X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/4fa9c3d0a87911ef71653cb99aa1c70f633a9473..696a03b79ed936131f6e76a73aef69a46a704582:/OneRoundIoT/openssl/openssl_evp.c diff --git a/OneRoundIoT/openssl/openssl_evp.c b/OneRoundIoT/openssl/openssl_evp.c index 3c1416f..4e99565 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,16 +57,23 @@ 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 - if(ctr) + if(ctr) { if(1 != EVP_EncryptInit_ex(ctx, EVP_aes_128_ctr(), NULL, key, iv)) handleErrors(); - else + } + else if(1 != EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, key, iv)) handleErrors(); + time+=TimeStop(t); + printf("Time init %f\n",time); + + // int cipherBlockSize = EVP_CIPHER_CTX_block_size(ctx); // printf("INFO(evp_encrypt): block size: %d\n", cipherBlockSize); @@ -75,14 +82,24 @@ int encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key, * EVP_EncryptUpdate can be called multiple times if necessary */ - if(1 != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len)) - handleErrors(); - ciphertext_len = len; - +/* + static double time=0; + double t=0; + t=TimeStart(); +*/ + for(int i=0;i ecb - if(ctr) + if(ctr) { if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_128_ctr(), NULL, key, iv)) handleErrors(); - else + } + else if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, key, iv)) handleErrors(); @@ -129,17 +147,31 @@ 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(); +*/ + for(int i=0;i