0

I am trying to implement the RSA algorithm using the C language, for learning purpose.

I was wondering how much time should we expect it to take for encrypting a message of size 1024/2048/4096bits on an average consumer computer, assuming a reasonably efficient implementation ?

For now, I am trying to generate pseudo-random numbers using the Miller-Rabin primality test, but even for 320-bits wide numbers it seems to become unfeasible in a reasonable amount of time. For sure my implementation is not efficient, but I would like to know how much more efficient I could make it.

Thanks !

2 Answers2

1

This table from a 2006 paper suggest times of 310ms/2924ms/24332ms for 1024/2048/4096-bit RSA key generation on commodity hardware.

Daniel S
  • 29,316
  • 1
  • 33
  • 73
0

OpenSSL's speed command is the base helper to compare your implementation on your platform. You don't need an old article or arbitrary internet library.

Run

openssl speed rsa

on your system get results then compare. I get the below on my system.

Doing 512 bits private rsa's for 10s: 365354 512 bits private RSA's in 9.99s
Doing 512 bits public rsa's for 10s: 6632923 512 bits public RSA's in 10.00s
Doing 1024 bits private rsa's for 10s: 145277 1024 bits private RSA's in 10.00s
Doing 1024 bits public rsa's for 10s: 2467123 1024 bits public RSA's in 10.00s
Doing 2048 bits private rsa's for 10s: 21029 2048 bits private RSA's in 10.00s
Doing 2048 bits public rsa's for 10s: 748543 2048 bits public RSA's in 10.00s
Doing 3072 bits private rsa's for 10s: 6886 3072 bits private RSA's in 10.00s
Doing 3072 bits public rsa's for 10s: 349552 3072 bits public RSA's in 9.99s
Doing 4096 bits private rsa's for 10s: 3038 4096 bits private RSA's in 10.00s
Doing 4096 bits public rsa's for 10s: 201612 4096 bits public RSA's in 10.00s
Doing 7680 bits private rsa's for 10s: 343 7680 bits private RSA's in 10.01s
Doing 7680 bits public rsa's for 10s: 58627 7680 bits public RSA's in 10.00s
Doing 15360 bits private rsa's for 10s: 65 15360 bits private RSA's in 10.12s
Doing 15360 bits public rsa's for 10s: 14943 15360 bits public RSA's in 10.00s

Later, it turns into a better table as;

                  sign    verify    sign/s verify/s
rsa  512 bits 0.000027s 0.000002s  36572.0 663292.3
rsa 1024 bits 0.000069s 0.000004s  14527.7 246712.3
rsa 2048 bits 0.000476s 0.000013s   2102.9  74854.3
rsa 3072 bits 0.001452s 0.000029s    688.6  34990.2
rsa 4096 bits 0.003292s 0.000050s    303.8  20161.2
rsa 7680 bits 0.029184s 0.000171s     34.3   5862.7
rsa 15360 bits 0.155692s 0.000669s      6.4   1494.3

Note that, OpenSSL uses BIGNUM as its arbitrary precision library, you may use GNU GMP or it's ports for other languages like gmpy2 in python.

kelalaka
  • 49,797
  • 12
  • 123
  • 211