X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/8e7ce26ffa675a1249751a2a2e5d3b5c1cdc0553..26cfeb68c1da44bc454806933dde5459455e113b:/OneRoundIoT/openssl/openssl_evp.c diff --git a/OneRoundIoT/openssl/openssl_evp.c b/OneRoundIoT/openssl/openssl_evp.c index bd4243a..6860932 100644 --- a/OneRoundIoT/openssl/openssl_evp.c +++ b/OneRoundIoT/openssl/openssl_evp.c @@ -41,7 +41,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; @@ -57,9 +57,14 @@ int encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key, * In this example we are using 256 bit AES (i.e. a 256 bit key). The * IV size for *most* modes is the same as the block size. For AES this * is 128 bits */ - + //static double time=0; + //double t=0; + //t=TimeStart(); //256 //avant ecb + for(int i=0;i ecb if(ctr) { if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_128_ctr(), NULL, key, iv)) @@ -131,17 +151,30 @@ 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; - + } + + /* Clean up */ EVP_CIPHER_CTX_free(ctx); @@ -166,11 +199,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 +235,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