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
yak
  • 3,770
  • 19
  • 60
  • 111

1 Answers1

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).

  • 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 :) – yak Dec 03 '14 at 21:11
  • 1
    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. –  Dec 03 '14 at 21:18
  • 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 – yak Dec 03 '14 at 21:38
  • That sentence doesn't make sense. Besides I think duskwuff correctly answered your question already. – Maarten Bodewes Dec 03 '14 at 22:11
  • 2
    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. –  Dec 03 '14 at 22:57