-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add an option for no zero padding of the key in openssl_encrypt and openssl_decrypt #2498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
To clarify, what is the current behavior when a too-short key is passed to fixed-length primitive like AES? I assume it is rejected and not padded, right? |
Nope such key is padded with This is meant just for variable length cipher to allow providing shorter keys where it is possible. |
In that case I'd prefer leaving 7.1 alone and just fix this completely in next minor, without introducing an option. If people want to pad, they can go pad themselves. Btw, we started rejecting incorrectly sized keys in mcrypt in PHP 5.6. |
I think that it doesn't make sense for variable length cipher as the result just changes without any warning. Please consider following:
Then it will be different between two PHP versions and without searching changelog you won't know why. That's a big problem if you have got some old code that hasn't been changed for ages and then you just don't know why it doesn't work. So what most people probably do is that they won't update. That's just not right IMHO. |
@nikic so are you ok with this or do we need RFC? I don't agree that this should be changed in the next minor without any migration path (e.g. first emitting notice or something like that). Especially for ciphers with variable length where would be BC break really ugly as noted above. |
I'll trust your judgement here, no need to RFC. |
It would be nice to have a nicer name for this option. |
Well it's not even completely correct for variable length cipher that the key won't be zero padded. It will be still padded if the key len is 0 (empty string). The only thing it does is trying to set key len first. Thinking about that, it's still kind of weird. So how about something a little bit different. We could introduce the flag that you suggest - |
@bukka I like that, sounds like a cleaner and more comprehensive solution. |
@bukka fine for 7.1, sorry about the delay there ... |
Merged via 0c707fc |
This fixes a problem with filling key with
\0
if it's shorter than default length of the cipher and instead prioritise setting a variable key length. That applies only on ciphers with variable key length (Blowfish, RC4 and some others). Please note that this has no influence on ciphers with defined fixed key length like AES. It fixes bug 72362 and bug 71917The reason for a new flag is to prevent BC issues that would happen if it was done by default because the used key would be different (it means that the key would no longer filled with
\0
).I targeted 7.1 which I think should be fine. It's a new option (constant) which fixes 2 bugs. @krakjoe Are you ok with such addition to 7.1?