Skip to content

Conversation

nikic
Copy link
Member

@nikic nikic commented Mar 1, 2014

No longer allow invalid IV size, invalid key size or missing IV on modes that require an IV.

nikic added 4 commits March 1, 2014 15:29
Previously, if the size of the IV did not match the block size
mcrypt would throw a warning and fall back to a NUL IV. This
behavior is both dangerous and makes no practical sense.

mcrypt_encrypt etc. will now return false if the IV has an incorrect
size.
Previously the code fell back on using a NUL IV if no IV was
passed and the encryption mode required it. This is dangerous and
makes no sense from a practical point of view (as you could just
as well use ECB then).
Previously an incorrectly sized key was either silently padded
with NUL bytes or truncated. Especially the silent nature of this
behavior makes it extremely easy to use weak encryption. A common
mistake - which has also been extensively made in our tests - is
to use a password instead of a key.

Incorrectly sized keys will now be rejected.
Avoid unnecessary alloc/copy/free cycles and clean up structure in
general. Add a few extra checks for the key length.

{
int count, i;
int *key_sizes = mcrypt_enc_get_supported_key_sizes(td, &count);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit pointless to start a new scope here. Just put the definitions at the start?

@php-pulls
Copy link

Comment on behalf of nikic at php.net:

Merged.

@php-pulls php-pulls closed this Mar 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants