0

I wrote a simple code in pure C to benchmark AES-CBC-256 and RC2-CBC-128 from Openssl. My testing loops look like this:

for(i=0; i<tests; i++) { timer_start(); for(j=0; j<its; j++) { RC2_cbc_encrypt(input, enc_out, length, &key, iv_enc, RC2_ENCRYPT); } stop = timer_stop(); printf("%f\n",(stop / its) * 1000); } for(i=0; i<tests; i++) { timer_start(); for(j=0; j<its; j++) { AES_cbc_encrypt(input, enc_out, length, &enc_key, iv_enc, AES_ENCRYPT); } stop = timer_stop(); printf("%f\n",(stop / its) * 1000); } 

But something wrong is happening, on every machine I test my code I get strange results, that is, every time AES is faster than RC2. What could be the problem? I use getrusage to measure time (in my timers).

AES: 0.010898 0.010471 0.010531 RC2: 0.023261 0.023392 0.023224 
1
  • Also check this answer, the paragraph just before the last paragraph. Commented Dec 3, 2014 at 21:05

1 Answer 1

3

Nothing is wrong. AES is faster because:

  • RC2 is rather complex, from a computational perspective.

  • AES has been optimized heavily in software, because it is so frequently used.

  • Some CPUs have hardware acceleration for AES (e.g. AES-NI for x86).

Sign up to request clarification or add additional context in comments.

5 Comments

Hmm, and how about 3DES? Should it be faster than RC2 but slower than AES? It seemed strange to me because when I tested it with Openssl, I got 283758 for AES and 205444 for RC2 and was sure that it was me who did the mistake in my code, not the Openssl programmers. Could you be so kind and answer about 3DES and 2 others? Thank you :)
DES is also rather complex, is difficult to implement in software, and is not hardware-accelerated on most systems. That result sounds reasonable to me.
So why In Openssl AES in slower than RC2 and in my code is faster than RC2? I tested it with openssl speed on the same machine I tested my code
That sentence doesn't make sense. Besides I think duskwuff correctly answered your question already.
You're reading the results wrong. The numbers printed by openssl speed are the number of iterations it completed per second — higher numbers from this tool mean it's faster, not slower.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.