LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Opensll AES-129-ccm

do any body use Openssl Library in LabView?

I'm trying to use mostly to Encrypt Text strings on AES-128-ccm.

I been looking all the forum and I can't find anything.

 

I Install the latest version of Openssl Library in my Windows platform.

 

Y developed a .dll using the Openssl in Visual Studio 2017 and looks than works in LabView, but it is unstable, some time makes the LabView Crush, the code works fine if I run into VisualStudio (with modifications for command prompt), but not for LabView (50% of time works fine)

 

This is my c++ code for one function:

 

 

 

/****************************************************************************
   FUNCTION: encryptMessage(unsigned char *plaintext, int plaintext_len, unsigned char *key,
											   unsigned char *iv, unsigned char *ciphertext)

   ARGUMENTS: plaintext       	-  Message to Encrypt
			  plaintext_len		-  size of Message
			  key				-  Encryption key
			  iv            	-  initialization vector
			  ciphertext  		-  array where to put encrypted message

   RETURN: STATUS - OK if success; otherwise not OK

   DESCRIPTION: This method encrypts the message into plaintext
 *****************************************************************************/
int encryptMessage(uint8_t *plaintext, int plaintext_len, uint8_t *key, uint8_t *iv, uint8_t *ciphertext, uint8_t tag[TAG_LEN], char *comment)
{
	EVP_CIPHER_CTX *ctx;

	uint8_t texttoencrypt[27];
	int ciphertext_len, len;
	int ret;

	memset(texttoencrypt, 0, 27);
	memcpy(texttoencrypt, plaintext, plaintext_len);

	ctx = EVP_CIPHER_CTX_new();

	// Set cipher type and mode 
	ret = EVP_EncryptInit_ex(ctx, EVP_aes_128_ccm(), NULL, NULL, NULL);
	if (ret != 1)
	{
		comment = (char *) "Encrypt Message: Init AES CCM Error...";
		EVP_CIPHER_CTX_free(ctx);
		return -1;
	}

	// Set nonce length (13) 
	ret = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_IVLEN, IV_LEN, NULL);
	if (ret != 1)
	{
		comment = (char *) "Encrypt Message: Set IV LEN Error ...";
		EVP_CIPHER_CTX_free(ctx);
		return -2;
	}

	// Set tag length 
	ret = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_TAG, TAG_LEN, NULL);
	if (ret != 1)
	{
		comment = (char *) "Encrypt Message: TAG Error ...";
		EVP_CIPHER_CTX_free(ctx);
		return -3;
	}

	// Initialize key and IV 
	ret = EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv);
	if (ret != 1)
	{
		comment = (char *) "Encrypt Message: Set KEY and NONCE Error ...";
		EVP_CIPHER_CTX_free(ctx);
		return -4;
	}

	// set total plaintext length
	ret = EVP_EncryptUpdate(ctx, NULL, &len, NULL, sizeof(texttoencrypt));
	if (ret != 1)
	{
		comment = (char *) "Encrypt Message: set plaintext Error ...";
		EVP_CIPHER_CTX_free(ctx);
		return -5;
	}

	/* Encrypt plaintext: can only be called once */
	ret = EVP_EncryptUpdate(ctx, ciphertext, &len, texttoencrypt, sizeof(texttoencrypt));
	if (ret != 1)
	{
		comment = (char *) "Encrypt Message: Encrypt plaintext ...";
		EVP_CIPHER_CTX_free(ctx);
		return -6;
	}
	ciphertext_len = len;

	// Finalize: note get no output for CCM 
	ret = EVP_EncryptFinal_ex(ctx, ciphertext + len, &len);
	if (ret != 1)
	{
		comment = (char *) "Encrypt Message: Finalize Encrypt error ...";
		EVP_CIPHER_CTX_free(ctx);
		return -7;
	}
	ciphertext_len += len;
	comment = (char *) "Encrypt Message: Success ...";

	EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_GET_TAG, TAG_LEN, tag);

	EVP_CIPHER_CTX_free(ctx);

	return ciphertext_len;
	
}

 

Thank you for your Help

 

0 Kudos
Message 1 of 2
(2,477 Views)

Maybe this would save you some trouble:

 

https://lvs-tools.co.uk/files/6914/4279/3239/Encryption_Compendium_for_LabVIEW-Datasheet2.pdf

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 2
(2,473 Views)