# Execution Time - Rijandael encryption

• 09-20-2008
gamer4life687
Execution Time - Rijandael encryption
My professor posted this problem for us.

Quote:

The reading assignment in the last lecture covered how AES (Rjindael) works. This problem will give you an idea as to how much processing time AES requires to perform key generation, encryption and decryption.
First, familiarize yourself with the AES key generation, encryption and decryption functions in this source code. Choose a key and block size of 128 bits. Choose any plaintext M 128*5 bit long. Then, perform the following:
1) Execute the key generation function to get a key K
• Compute the execution time.
2) Execute the encryption function to encrypt M using K, and obtain the ciphertext
• Compute the execution time.
3) Execute the decryption function to decrypt C using K, and to obtain M back.
• Compute the execution time.

Repeat each of the above steps 100 times and give the average execution time for each of the three functions. List the type and speed of the processor, and the memory (RAM) of the machine you execute the code on.

I hope you know how to measure execution time! If not, please try to figure it out yourself before asking for help. Include a description of how you measured the timing, such as what functions you measured the execution time of.

I chose a plaintext of 5 blocks of(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
and a key of (bbbbbbbbbbbbbbbbbbbbbb)
I used this as my way of measuring execution time
In the rijandael.cpp file are the functions for makekey, enrcrypt, decrypt.
as a note i changed the the memset and buffers from 300 to 600 b/c it kept crashing

Code:

```void CRijndael::Encrypt(char const* in, char* result, size_t n) {         time_t begin = clock();         memset(result,0,600);         if(false==m_bKeyInit)                 throw exception(sm_szErrorMsg1);         //n should be > 0 and multiple of m_blockSize         if(0==n || n%m_blockSize!=0)                 throw exception(sm_szErrorMsg2);         int i;         char const* pin;         char* presult;         for(i=0,pin=in,presult=result; i<n/m_blockSize; i++)         {                 EncryptBlock(pin, presult);                 pin += m_blockSize;                 presult += m_blockSize;         }         result[n] = '\0';         time_t end = clock();         double dif = difftime(end,begin);         ofstream myfile;         myfile.open("Encrypt.txt", ios::app);         myfile << "Diffms: " << dif << endl;         myfile.close();         }```
I keep getting 0 or .1 ms for my times (encryption/decryption) and i know this is a fast algorithm but I just wanted to know if im doing this correctly or any1 else is getting the same values.
• 09-20-2008
tabstop
That's why you are supposed to encrypt/decrypt 100 times:
Code:

```start the clock for i from 0 to 99     encrypt/decrypt/generate (whichever you're measuring) stop the clock```
• 09-20-2008
matsp
What I have done many times is a "selfcalibrating" loop counter.
set n = 5 (or some other small number that will not take very long).
repeat
Store current clock() in T
Run n iterations
Get diff betwen clock() and T.
if (diff < 1.0) n *= 2
else if (diff < 3.0) n = (int) n * 3.1 * ((float) diff / n);
while (diff < 3.0);
display iterations per second by dividing (float) n / diff.

--
Mats
• 09-20-2008
gamer4life687
So I'm assuming I've read this wrong then. I read it as
"enter my text, enter my key, press encrypt" that would give me .001 thats 1 time
"enter my text, enter my key, press encrypt" that would give me .001 thats 2 times
and then take the average after 100?

From what your saying its measure the total time after 100 encrypts.
That seems to word to me considering that he was asking for an average. Can't have an average if your measuring one time for all 100. But that would make more sense to measure.
• 09-20-2008
tabstop
To get the average you do have to divide by 100 at the end.
• 09-20-2008
gamer4life687
ya i know how to do average lol... i was just reading the problem wrong.
it makes more sense now to clock all 100 iterations not 1 at a time. thx