Commit Graph

7 Commits

Author SHA1 Message Date
Thomas Waldmann 1f4077d870 crypto.pyx: adapt to strange requirements found in the openssl docs
https://www.openssl.org/docs/crypto/EVP_aes_256_cbc.html

EVP_DecryptInit_ex(), EVP_DecryptUpdate() and EVP_DecryptFinal_ex() are the corresponding decryption operations. EVP_DecryptFinal() will return an error code if padding is enabled and the final block is not correctly formatted. The parameters and restrictions are identical to the encryption operations except that if padding is enabled the decrypted data buffer out passed to EVP_DecryptUpdate() should have sufficient room for (inl + cipher_block_size) bytes unless the cipher block size is 1 in which case inl bytes is sufficient.

I doubt this is correct, but let's rather be defensive here.
2015-03-03 20:18:28 +01:00
Thomas Waldmann 550320535c crypto.pyx: cosmetic changes, added comments 2015-03-03 20:11:28 +01:00
Thomas Waldmann 6c7c2e2e40 cleanup crypto.pyx, make it easier to adapt to other modes
There were some small issues:

 a) it never called EVP_EncryptFinal_ex.
For CTR mode, this had no visible consequences as EVP_EncryptUpdate already yielded all ciphertext.
For cleanliness and to have correctness even in other modes, the missing call was added.

b) decrypt = encrypt hack
This is a nice hack to abbreviate, but it only works for modes without padding and without authentication.
For cleanliness and to have correctness even in other modes, the missing usage of the decrypt api was added.

c) outl == inl assumption
Again, True for CTR mode, but not for padding or authenticating modes.
Fixed so it computes the ciphertext / plaintext length based on api return values.

Other changes:
As encrypt and decrypt API calls are different even for initialization/reset, added a is_encrypt flag.

Defensive output buffer allocation. Added the length of one extra AES block (16bytes) so it would
work even with padding modes. 16bytes are needed because a full block of padding might get
added when the plaintext was a multiple of aes block size.

These changes are based on some experimental code I did for aes-cbc and aes-gcm.
While we likely won't ever want aes-cbc in attic (maybe gcm though?), I think it is cleaner
to not make too many mode specific assumptions and hacks, but just use the API as it
was meant to be used.
2015-03-03 19:19:28 +01:00
Jonas Borgström 11687fbec1 crypto: store EVP_CIPHER_CTX on the stack 2014-05-13 23:18:32 +02:00
Jonas Borgström 7e258c8401 crypto: Improved AES performance
attic.crypto now uses the OpenSSL EVP API for AES encryption.
This API uses AES-NI instructions when available resulting in
a significant AES encryption performance improvement:

Before: 80MiB/s
After: 1931MiB/s

Message size: 64kiB
CPU: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz
2014-05-13 22:33:58 +02:00
Jonas Borgström 92c333c071 Add a method to detect out of date binary extension modules 2014-03-18 22:04:08 +01:00
Jonas Borgström 0e39acffd3 crypto: convert attic.crypto into a cython module
This will give a slight performance boost and make the openssl
detection/linking more robust.
2014-03-10 22:50:38 +01:00