X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/8e7ce26ffa675a1249751a2a2e5d3b5c1cdc0553..fd03c6c18761aedcf1616b4dadc316fbb07ebde3:/OneRoundIoT/openssl/openssl_evp.c?ds=sidebyside diff --git a/OneRoundIoT/openssl/openssl_evp.c b/OneRoundIoT/openssl/openssl_evp.c index bd4243a..0a4b949 100644 --- a/OneRoundIoT/openssl/openssl_evp.c +++ b/OneRoundIoT/openssl/openssl_evp.c @@ -16,6 +16,9 @@ typedef unsigned char uchar; int nb_test=1; int ctr=0; +double time_encrypt=0; +double time_decrypt=0; + double TimeStart() { struct timeval tstart; @@ -41,7 +44,7 @@ void handleErrors(void) int encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key, - unsigned char *iv, unsigned char *ciphertext, int ctr) + unsigned char *iv, unsigned char *ciphertext, int ctr, int index) { EVP_CIPHER_CTX *ctx; @@ -49,6 +52,9 @@ int encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key, int ciphertext_len; + + + /* Create and initialise the context */ if(!(ctx = EVP_CIPHER_CTX_new())) handleErrors(); @@ -58,40 +64,46 @@ int encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key, * IV size for *most* modes is the same as the block size. For AES this * is 128 bits */ + double t=TimeStart(); + //256 //avant ecb - if(ctr) { - if(1 != EVP_EncryptInit_ex(ctx, EVP_aes_128_ctr(), NULL, key, iv)) - handleErrors(); - } - else + for(int i=0;i ecb if(ctr) { if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_128_ctr(), NULL, key, iv)) @@ -131,17 +148,32 @@ int decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, * EVP_DecryptUpdate can be called multiple times if necessary */ - - if(1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len)) - handleErrors(); - plaintext_len = len; +/* static double time=0; + double t=0; + t=TimeStart(); +*/ + + plaintext_len = 0; + if(1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len)) + handleErrors(); + plaintext_len = len; +/* time+=TimeStop(t); +// if(index==nb_test-1) + printf("Time decrypt %f\n",time); +*/ + + /* Finalise the decryption. Further plaintext bytes may be written at * this stage. */ if(1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len)) handleErrors(); plaintext_len += len; + } + + time_decrypt+=TimeStop(t); + /* Clean up */ EVP_CIPHER_CTX_free(ctx); @@ -166,11 +198,11 @@ int main (int argc, char** argv) if(strncmp(argv[i],"lena",4)==0) lena = atoi(&(argv[i][4])); //Use Lena or buffer } - printf("nb times %d\n",nb_test); +/* printf("nb times %d\n",nb_test); printf("ctr %d\n",ctr); printf("lena %d\n",lena); printf("size_buf %d\n",size_buf); - +*/ @@ -202,7 +234,8 @@ int main (int argc, char** argv) // load_RGB_pixmap("No_ecb_mode_picture.ppm", &width, &height, &data_R, &data_G, &data_B); } else { - width=height=size_buf; + width=size_buf; + height=size_buf; imsize=width*height; buffer=malloc(imsize*sizeof(uchar)); for(int i=0;i