<div dir="ltr"><div><div><div><div><div>dear all<br></div>i am using Authenticated Encryption AES-GCM. i am trying to calculate the processing time for encrypting a data message of size 500 byte <br><br> clock_t startEncryption, endEncryption;<br> double msecs1;<br><br> startEncryption = clock();<br><br> unsigned char plaintext[500] = {'f','a','3','1','3','2','2','5','f','8','8','4','0','6','e','5','a','5','5','9','0','9','c','5','a','f','f','5','2','6','9','a','8','6','a','7','a','9','5','3','1','5','3','4','f','7','d','a','2','e','4','c','3','0','3','d','8','a','3','1','8','a','7','2','1','c','3','c','0','c','9','5','9','5','6','8','0','9','5','3','2','f','c','f','0','e','2','4','4','9','a','6','b','5','2','5','b','1','6','a','e','d','f','5','a','a','0','d','e','6','5','7','b','a','6','3','7','b','3','9','f','a','3','1','3','2','2','5','f','8','8','4','0','6','e','5','a','5','5','9','0','9','c','5','a','f','f','5','2','6','9','a','8','6','a','7','a','9','5','3','1','5','3','4','f','7','d','a','2','e','4','c','3','0','3','d','8','a','3','1','8','a','7','2','1','c','3','c','0','c','9','5','9','5','6','8','0','9','5','3','2','f','c','f','0','e','2','4','4','9','a','6','b','5','2','5','b','1','6','a','e','d','f','5','a','a','0','d','e','6','5','7','b','a','6','3','7','b','3','9',<br> 'f','a','3','1','3','2','2','5','f','8','8','4','0','6','e','5','a','5','5','9','0','9','c','5','a','f','f','5','2','6','9','a','8','6','a','7','a','9','5','3','1','5','3','4','f','7','d','a','2','e','4','c','3','0','3','d','8','a','3','1','8','a','7','2','1','c','3','c','0','c','9','5','9','5','6','8','0','9','5','3','2','f','c','f','0','e','2','4','4','9','a','6','b','5','2','5','b','1','6','a','e','d','f','5','a','a','0','d','e','6','5','7','b','a','6','3','7','b','3','9'<br> ,'f','a','3','1','3','2','2','5','f','8','8','4','0','6','e','5','a','5','5','9','0','9','c','5','a','f','f','5','2','6','9','a','8','6','a','7','a','9','5','3','1','5','3','4','f','7','d','a','2','e','4','c','3','0','3','d','8','a','3','1','8','a','7','2','1','c','3','c','0','c','9','5','9','5','6','8','0','9','5','3','2','f','c','f','0','e','2','4','4','9','a','6','b','5','2','5','b','1','6','a','e','d','f','5','a','a','0','d','e','6','5','7','b','a','6','3','7','b','3','9'<br> ,'f','a','3','1','3','2','2','5','f','8','8','4','0','6','e','5','a','5','5','9'};<br> unsigned char key [32] = {'f','e','f','f','e',9,9,2,8,6,6,5,7,3,1,'c',6,'d',6,'a',8,'f',9,4,6,7,3,0,8,3,0,8};<br> //unsigned char key [48] = "000000000000000000000000";<br><br> unsigned char aad[8] = {'f','e','e','d','f','a','c','e'};<br> //unsigned char iv[24] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};<br> unsigned char iv[16] = {9,3,1,3,2,2,5,'d','f',8,8,4,0,6,'e',5};<br> unsigned char cipher[500];<br> unsigned char tag[16];<br><br> unsigned char extractedpalintext[500];<br><br> int encryptionsize = 0;<br> encryptionsize = servertest.AuthenticationEncryption(plaintext,500,aad,8,key,32,iv,16,cipher,tag);<br>servertest.AuthenticationDecryption(cipher,500,aad,8,tag,key,32,iv,16,extractedpalintext);<br> servertest.AuthenticationDecryption(cipher,120,fakeaad,40,tag,key,32,iv,120,extractedpalintext);<br><br> endEncryption = clock();<br> msecs1 = ((double) (endEncryption - startEncryption)) * 1000000.0 / CLOCKS_PER_SEC;<br> cout<<"time for encryption "<< " start "<<startEncryption<<" msec "<<" end time "<<endEncryption<<" msec"<<endl;<br> cout<<" encryption start time "<<msecs1<<"msec"<<endl;<br><br><br></div>the time at start and end time<br><br>time for encryption start 4870000 msec end time 4870000 msec<br><br></div>this made the processing time is 0 msec <br><br><br></div>functions for encryption and decryption<br><br>int<br>Server::AuthenticationEncryption(unsigned char plaintext[], int ptextsize,<br> unsigned char aad[], int aadlen, unsigned char key[],int keysize,<br> unsigned char iv[],int ivsize, unsigned char ciphertext[], unsigned char tag[])<br>{<br> int len;<br> int ciphertext_len;<br> EVP_CIPHER_CTX *ctx;<br> ctx = EVP_CIPHER_CTX_new();<br><br> //Initialize the encryption operation<br> if (1 == EVP_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, NULL, NULL))<br> {<br> cout<<"success inttialize"<<endl;<br> }<br> else<br> {<br> cout<<"something wrong"<<endl;<br> }<br> //Set IV length should be more than 12 byte or 96 bit normally 16<br> if (1 == EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, ivsize, NULL))<br> {<br> cout<<"success adding iv"<<endl;<br> }<br> else<br> {<br> cout<<"something wrong"<<endl;<br> }<br> //Initialize key and IV<br> if (1 == EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv))<br> {<br> cout<<"success initialize key and iv "<<endl;<br> }<br> else<br> {<br> cout<<"something wrong"<<endl;<br> }<br> //add AAD data<br> if (1 == EVP_EncryptUpdate(ctx, NULL, &len, aad, aadlen))<br> {<br> cout<<"success adding AAD"<<endl;<br> }<br> else<br> {<br> cout<<"something wrong"<<endl;<br> }<br> //encrypt the message<br> if (1 == EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, ptextsize))<br> {<br> cout<<"success encryption"<<endl;<br> ciphertext_len = len;<br> }<br> else<br> {<br> cout<<"something wrong"<<endl;<br> }<br> //finalize the encryption<br> if (1 == EVP_EncryptFinal_ex(ctx, ciphertext + len, &len))<br> {<br> cout<<"success final encryption"<<endl;<br> ciphertext_len += len;<br> cout<<"cipher length is "<<ciphertext_len<<endl;<br> }<br> else<br> {<br> cout<<"something wrong"<<endl;<br> }<br> //get the tag<br> if (1 == EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, 16, tag))<br> {<br> cout<<"success creating tag"<<endl;<br> }<br> else<br> {<br> cout<<"something wrong "<<endl;<br> }<br> EVP_CIPHER_CTX_free(ctx);<br> return ciphertext_len;<br>}<br><br>int<br>Server::AuthenticationDecryption(unsigned char ciphertext[], int ctextsize,<br> unsigned char aad[], int aadlen, unsigned char tag[],<br> unsigned char key[], int keysize, unsigned char iv[], int ivsize,<br> unsigned char plaintext[])<br>{<br> int len;<br> int plaintext_len;<br><br> EVP_CIPHER_CTX *ctx;<br> ctx = EVP_CIPHER_CTX_new();<br><br> //Initialize the encryption operation<br> if (1 == EVP_DecryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, NULL, NULL))<br> {<br> cout<<"success initialize"<<endl;<br> }<br> else<br> {<br> cout<<"something wrong"<<endl;<br> }<br> //Set IV length should be more than 12 byte or 96 bit normally 16<br> if (1 == EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, ivsize, NULL))<br> {<br> cout<<"success adding iv"<<endl;<br> }<br> else<br> {<br> cout<<"something wrong"<<endl;<br> }<br> //Initialize key and IV<br> if (1 == EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv))<br> {<br> cout<<"success adding key and iv"<<endl;<br> }<br> else<br> {<br> cout<<"something wrong"<<endl;<br> }<br> //add AAD data<br> if (1 == EVP_DecryptUpdate(ctx, NULL, &len, aad, aadlen))<br> {<br> cout<<"success adding AAD"<<endl;<br> }<br> else<br> {<br> cout<<"something wrong"<<endl;<br> }<br> //Decrypt the message<br> if (1 == EVP_DecryptUpdate(ctx, plaintext, &len , ciphertext, ctextsize))<br> {<br> cout<<"success decryption"<<endl;<br> plaintext_len = len;<br> }<br> else<br> {<br> cout<<"something wrong"<<endl;<br> }<br> //add the tag<br> if (1 == EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, 16, tag))<br> {<br> cout<<"success adding tag"<<endl;<br> }<br> else<br> {<br> cout<<"something wrong"<<endl;<br> }<br> //finalize the Decryption<br> int ret = -1;<br> ret = EVP_DecryptFinal_ex(ctx, plaintext + len, &len);<br><br> cout<<" ret value is "<<ret<<endl;<br> EVP_CIPHER_CTX_free(ctx);<br><br> if (ret > 0)<br> {<br> cout<<"success final decryption"<<endl;<br> plaintext_len += len;<br> cout<<"palin text is "<<plaintext_len<<endl;<br> return plaintext_len;<br><br> }<br> else<br> {<br> cout<<"decrypt fail"<<endl;<br> return -1;<br> }<br> return ret;<br><br>}<br><br></div><b>the processing time is 0 and this is not reasonable </b>thanks for help<br clear="all"><div><div><div><div><div><div><br>-- <br><div><div dir="ltr"><div><font face="Times New Roman, Times, Serif"><font color="#ff8040"><span style="font-family:Garamond;color:blue;font-size:12pt"><font face="Arial Black, Geneva, Arial, Sans-serif"><font color="#ff8040">Warmest regards and best wishes for a good health</font></font><font face="Arial Black, Geneva, Arial, Sans-serif">,</font></span><font face="Arial Black, Geneva, Arial, Sans-serif" size="3"><b>urs sincerely </b></font></font></font><br><b><font color="#ff8040" face="Arial Black, Geneva, Arial, Sans-serif" size="3">mero</font></b><br></div></div></div>
</div></div></div></div></div></div></div>