* 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<nb_test;i++)
+ {
+
if(ctr) {
if(1 != EVP_EncryptInit_ex(ctx, EVP_aes_128_ctr(), NULL, key, iv))
handleErrors();
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);
* EVP_EncryptUpdate can be called multiple times if necessary
*/
-
+/*
static double time=0;
double t=0;
t=TimeStart();
-
-// for(int i=0;i<nb_test;i++)
- {
+*/
-
- if(1 != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len))
+ if(1 != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len))
handleErrors();
ciphertext_len = len;
- }
- time+=TimeStop(t);
- if(index==nb_test-1)
- printf("Time encrypt %f\n",time);
-
+/* time+=TimeStop(t);
+ // if(index==nb_test-1)
+ printf("Time encrypt %f\n",time);
+
+*/
/* Finalise the encryption. Further ciphertext bytes may be written at
*/
if(1 != EVP_EncryptFinal_ex(ctx, ciphertext + len, &len)) handleErrors();
ciphertext_len += len;
-
+ }
/* Clean up */
EVP_CIPHER_CTX_free(ctx);
* EVP_DecryptUpdate can be called multiple times if necessary
*/
- static double time=0;
+/* static double time=0;
double t=0;
t=TimeStart();
-
-// for(int i=0;i<nb_test;i++)
+*/
+ for(int i=0;i<nb_test;i++)
{
+ 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)
+/* 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);
// 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<imsize;i++) {
int oneD=width*height;
- uchar *plaintext = malloc(imsize);
+ uchar *plaintext = malloc(imsize+1000); //add that for cbc
if(lena) {
for(int i=0;i<oneD;i++) {
plaintext[i]=data_R[i];
- uchar *ciphertext = malloc(imsize);
+ uchar *ciphertext = malloc(imsize+1000); //add that for cbc
/* Buffer for the decrypted text */
- uchar *decryptedtext = malloc(imsize);
+ uchar *decryptedtext = malloc(imsize+1000); //add that for cbc
int decryptedtext_len, ciphertext_len;
*/
- double time=0;
+ double time_encrypt=0;
+ double time_decrypt=0;
double t=TimeStart();
int i;
- for(i=0;i<nb_test;i++)
+// for(i=0;i<nb_test;i++)
{
ciphertext_len = encrypt (plaintext, imsize, key, iv,
ciphertext, ctr, i );
}
- time+=TimeStop(t);
+ time_encrypt+=TimeStop(t);
- printf("Time encrypt %f\n",time);
+// printf("Time encrypt %f\n",time);
+ printf("%f\t",(double)imsize*nb_test/time_encrypt);
if(lena) {
for(int i=0;i<oneD;i++) {
}
- time=0;
t=0;
t=TimeStart();
- for(int i=0;i<nb_test;i++)
+ //for(int i=0;i<nb_test;i++)
{
/* Decrypt the ciphertext */
decryptedtext_len = decrypt(ciphertext, ciphertext_len, key, iv,
decryptedtext,ctr, i);
}
- time+=TimeStop(t);
+ time_decrypt+=TimeStop(t);
- printf("Time decrypt %f\n",time);
+ //printf("Time decrypt %f\n",time);
+ printf("%f\t",(double)imsize*nb_test/time_decrypt);
if(lena) {
for(int i=0;i<oneD;i++) {
equal=0;
}
}
- printf("RESULT CORRECT: %d\n",equal);
+// printf("RESULT CORRECT: %d\n",equal);
}