AES faster than RSA Encryption?

aes, compare, encryption, performance, rsa

Solution

Besides @jbtule's correct point about the different purposes for RSA and AES encryption, there's something fundamentally flawed in the design of your benchmark.

What you're measuring here isn't just an RSA or AES encryption routine, but the whole execution of these `openssl` commands.

While it can make sense to use timers outside your external program to measure how one of its functions is performing, doing so requires the time spend doing other things (like parsing the command line parameters, finding the right OpenSSL sub-module, opening the file, reading the file) to be negligible compared with the time required to perform the timed function.

Here, this is clearly not the case, especially with such a short test message.

Problem

I am trying to test the speed of RSA and AES with openssl in ubuntu. i used the following code to test it. ``` echo -n "0123456789012345" > message.txt openssl genrsa -out private.pem 1024 openssl rsa -in private.pem -out public.pem -pubout for i in {1..1000} do openssl rsautl -encrypt -inkey public.pem -pubin -in message.txt -out message_enc.txt done for i in {1..1000} do openssl rsautl -decrypt -inkey private.pem -in message_enc.txt -out message_dec.txt done for i in {1..1000} do openssl enc -e -aes-128-cbc -in message.txt -out aes.bin -K ddf -iv 345 done ``` Results: ``` $ time ./rsa_enc real 0m3.697s user 0m1.308s sys 0m0.680s $ time ./rsa_dec real 0m14.273s user 0m3.172s sys 0m0.696s $ time ./aes real 0m3.790s user 0m1.408s sys 0m0.500s ``` It shows that RSA encrypt is faster then AES encrypt. Shouldn't AES be faster? Am I doing anything incorrectly? Thanks.

Original source