aws/aws-sdk-ruby — pull request #259 by Ryman (2013-06-01 01:36:27+00:00)
Title: Should warn users if they're doing potentially unsafe encryption with EncryptionUtils

I think the API provided by EncryptionUtils.encrypt is slightly dangerous. If someone decides to use the nice simple looking encrypt() call with data larger than their key length then their encryption will be unsafe due to either being out of bounds with an RSA key or due to using ECB mode with an AES key.

I would advise renaming this method in future to something which highlights that it's only really suitable for single block chunks of data. (It seems fine in the usage of encoding the envelope encryption key by the master key, so perhaps it could be renamed to something describing that behaviour)

So, I think it's a good idea to provide warnings if these situations arise. This will also hopefully notify people who are using 128bit AES keys as their master key. There is an astronomically small chance that due to their 128bit key use, the internally enveloped 256bit key could be reduced in strength to only 128bit due to properties of ECB encryption.

e.g. If the random key chosen for CBC encryption turned out to have `key[0,16] == key[17,32]` then the encrypted key would have two equal blocks, which an attacker could use to their advantage to know they only need to search half the key space to decrypt the data.

Just to be clear, the 128bit key is likely still strong enough, but it is worth warning the user. My main concerns is the perceived safeness of the api and a user using it themselves for something that really requires CBC or similar.