SecurityInnovation / PGPy

Pretty Good Privacy for Python
BSD 3-Clause "New" or "Revised" License
313 stars 98 forks source link

Any way to improve performance? #465

Open alexandervlpl opened 2 months ago

alexandervlpl commented 2 months ago

This library is excellent, but some quick benchmarking with a small message on my machine shows decryption taking ~200ms, encryption ~100ms (using Uncompressed). Is this to be expected with PGP, which was created for email back in the day? Or is it the Python implementation? Can anything be done to optimize, maybe on my side?

Using 2048 bit RSA keys created like this:

key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 2048)
key.add_uid(uid, usage={KeyFlags.Sign, KeyFlags.EncryptCommunications, KeyFlags.EncryptStorage},
                    hashes=[HashAlgorithm.SHA256, HashAlgorithm.SHA384, HashAlgorithm.SHA512, HashAlgorithm.SHA224],
                    ciphers=[SymmetricKeyAlgorithm.AES256, SymmetricKeyAlgorithm.AES192, SymmetricKeyAlgorithm.AES128],
                    compression=[CompressionAlgorithm.ZLIB, CompressionAlgorithm.BZ2, CompressionAlgorithm.ZIP, CompressionAlgorithm.Uncompressed])

Edit: by comparison, the GnuPG wrapper around gpg encrypts and decrypts 10x faster with the same key and message.