|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-06-08 12:35 UTC] sachavav at tut dot by
Description: ------------ According to description of Blowfish algorithm it can use variable key starting from 32bits. If the key is shorter than block, it should be cycled over. https://www.schneier.com/academic/archives/1994/09/description_of_a_new.html Keys A - AA - AAA should be equivalent. This is true in openssl extension for keys, longer than 128 bits, but for shorter keys extension works incorrectly. It padds short keys with zeros up to 128 bits instead of cycling them. Please check sample code for explanation. If you can compare behavior of mcrypt extension - it works correctly there. Test script: --------------- > php -r 'echo bin2hex(openssl_encrypt("this is a test string","bf-ecb","12345678" , OPENSSL_RAW_DATA));' 0b30345b335e2ca5ba4d12c0077768c99680ca260b07d693 > php -r 'echo bin2hex(openssl_encrypt("this is a test string","bf-ecb","12345678\0\0\0\0\0\0\0\0" , OPENSSL_RAW_DATA));' 0b30345b335e2ca5ba4d12c0077768c99680ca260b07d693 > php -r 'echo bin2hex(openssl_encrypt("this is a test string","bf-ecb","1234567812345678" , OPENSSL_RAW_DATA));' e3214d1b16e574828c8a3e222202dde81afd1ad2cb165ab3 Expected result: ---------------- Short keys are cycled over. Actual result: -------------- Short keys are padded with zeros PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
A new constant OPENSSL_DONT_ZERO_PAD_KEY has been introduced to address that and it will be part of 7.1.8. For example it can be used like: openssl_encrypt("this is a test string","bf-ecb","12345678", OPENSSL_RAW_DATA | OPENSSL_DONT_ZERO_PAD_KEY));Use this function for OpenSSL to get the same key of mcrypt's blowfish: function make_openssl_blowfish_key($key) { if("$key" === '') return $key; $len = (16+2) * 4; while(strlen($key) < $len) { $key .= $key; } $key = substr($key, 0, $len); return $key; }