spacemonkeygo / openssl

OpenSSL bindings for Go
http://godoc.org/github.com/spacemonkeygo/openssl
Apache License 2.0
472 stars 237 forks source link

Bug in applyKeyAndIV function while using aes-256-cbc cipher #24

Closed ishbir closed 9 years ago

ishbir commented 9 years ago

I'm working on implementing elliptic curve cryptography using OpenSSL and I borrowed a lot of code from ciphers.go. While testing my own project, I noticed that while initializing the decryption context using the NewDecryptionCipherCtx function and "aes-256-cbc" as the cipher, it wouldn't do the decryption properly even though the IV, key and the ciphertext were as expected. Further investigation revealed that this was because of EVP_EncryptInit_ex function on line 156 of ciphers.go.

My solution to the problem was adding a new variable called do to the function which would determine whether the intended operation is encryption or decryption and do everything accordingly. More here: https://github.com/ishbir/elliptic/blob/master/ciphers.go#L123

I think that the same fix should be made in this package.

thepaul commented 9 years ago

Thanks ishbir! Good call.