I'm writing a web server in Common Lisp. Now it works OK but slow. According to the profiling the bottleneck is expt-mod
function which is used to do key exchange by RSA.
Here is the detail. I got c
from the client(browser). c
is a 2048 bits integer. I got n
and d
from the RSA private key file. n
and d
are also 2048 bits integers. Then calculate (expt-mod c d n)
to get the pre-master-key of TLS connection. The profiling shows as below:
(EXPT-MOD C D N) took 542,184 microseconds (0.542184 seconds) to run.
9,941 microseconds (0.009941 seconds, 1.83%) of which was spent in GC.
During that period, and with 4 available CPU cores
1,057,317 microseconds (1.057317 seconds) were spent in user mode
7,123 microseconds (0.007123 seconds) were spent in system mode
3,309,856 bytes of memory allocated.
10 minor page faults, 0 major page faults, 0 swaps.
I think it's super slow since OpenSSL just take 0.002 seconds to process a TLS handshake. I've tried my own version of expt-mod, cl-utilities:expt-mod
and ironclad:expt-mod
but no luck. The profiling result shows pretty much the same.
So where did I make mistakes? Thanks.