Skip to content

Instantly share code, notes, and snippets.

@kkung
Created August 14, 2014 02:52
Show Gist options
  • Save kkung/f7ec425afded454aed99 to your computer and use it in GitHub Desktop.
Save kkung/f7ec425afded454aed99 to your computer and use it in GitHub Desktop.
RSA library benchmark
  • RMBP 15" / Early 2013(2.4GHz i7, 16GB RAM), CPython 2.7.6
  • rsa==3.1.4
  • pycrypto==2.6.1
  • cryptography==0.5.3
Cryptography PyCrypto RSA
1.0222690105438232 1.453489065170288 4.905964136123657
1.0008471012115479 1.3903019428253174 4.860486030578613
0.9761111736297607 1.3885319232940674 5.226905107498169
0.9783790111541748 1.403367042541504 5.033346891403198
0.9941108226776123 1.3732759952545166 4.917948961257935
0.9868130683898926 1.372446060180664 4.915317058563232
0.993232011795044 1.381227970123291 4.905683994293213
0.9890398979187012 1.3831381797790527 4.940471887588501
0.9829819202423096 1.3643519878387451 4.9240992069244385
0.9794309139251709 1.3923370838165283 4.982703924179077
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import rsa, padding
from cryptography.hazmat.primitives.serialization import load_pem_pkcs8_private_key
with open('pk.pem') as f:
pk = load_pem_pkcs8_private_key(f.read(),
password=None,
backend=default_backend())
def test():
signer = pk.signer(padding.PKCS1v15(),
hashes.SHA1())
signer.update('A'*1024)
signer.finalize()
if __name__ == '__main__':
import timeit
print(timeit.repeat("test()",
setup="from __main__ import test",
repeat=10,
number=1000))
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
from Crypto.Hash import SHA
with open('pk.pem') as f:
pk = RSA.importKey(f.read())
def test():
signer = PKCS1_v1_5.new(pk)
digest = SHA.new()
digest.update('A'*1024)
signer.sign(digest)
if __name__ == '__main__':
import timeit
print(timeit.repeat("test()",
setup="from __main__ import test",
repeat=10,
number=1000))
import rsa
with open('pk.pem') as f:
pk = rsa.PrivateKey.load_pkcs1(f.read())
def test():
rsa.sign('A'*1024, pk, 'SHA-1')
if __name__ == '__main__':
import timeit
print(timeit.repeat("test()",
setup="from __main__ import test",
repeat=10,
number=1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment