Thread: Execution Time - Rijandael encryption

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    230

    Execution Time - Rijandael encryption

    My professor posted this problem for us.

    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.
    Download the AES implementation source code from: http://islab.oregonstate.edu/koc/ece...Sha/sprash.zip
    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.
    Last edited by Salem; 09-21-2008 at 12:13 AM. Reason: quote tags for the prose
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    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.
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    To get the average you do have to divide by 100 at the end.

  6. #6
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    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
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mac OS X Users/C programmers?
    By petermichaux in forum C Programming
    Replies: 16
    Last Post: 04-18-2011, 06:36 AM
  2. How to get program execution time
    By pobri19 in forum C++ Programming
    Replies: 8
    Last Post: 01-20-2009, 07:45 AM
  3. Representing floats with color?
    By DrSnuggles in forum C++ Programming
    Replies: 113
    Last Post: 12-30-2008, 09:11 AM
  4. execution time
    By shuo in forum C++ Programming
    Replies: 3
    Last Post: 10-17-2007, 02:58 AM
  5. relating date....
    By Prakash in forum C Programming
    Replies: 3
    Last Post: 09-19-2001, 09:08 AM