-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OPENSSL_DONT_ZERO_PAD_KEY constant to prevent key padding
It fixes bug #71917 (openssl_open() returns junk on envelope < 16 bytes) and bug #72362 (OpenSSL Blowfish encryption is incorrect for short keys).
- Loading branch information
Showing
7 changed files
with
77 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--TEST-- | ||
Bug #71917: openssl_open() returns junk on envelope < 16 bytes | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("openssl")) die("skip openssl not loaded"); | ||
?> | ||
--FILE-- | ||
<?php | ||
function test($envkey) { | ||
$publicKey = "file://" . dirname(__FILE__) . "/public.key"; | ||
$privateKey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; | ||
openssl_public_encrypt($envkey, $envelope, $publicKey); | ||
$sealed = openssl_encrypt('plaintext', 'rc4', $envkey, OPENSSL_RAW_DATA | OPENSSL_DONT_ZERO_PAD_KEY); | ||
openssl_open($sealed, $output, $envelope, $privateKey, 'rc4'); | ||
var_dump($output === 'plaintext'); | ||
} | ||
|
||
// works - key of 16 bytes | ||
test('1234567890123456i'); | ||
// fails - key of 15 bytes | ||
test('123456789012345'); | ||
?> | ||
--EXPECT-- | ||
bool(true) | ||
bool(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Bug #72362: OpenSSL Blowfish encryption is incorrect for short keys | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("openssl")) die("skip openssl not loaded"); | ||
?> | ||
--FILE-- | ||
<?php | ||
var_dump(bin2hex(openssl_encrypt("this is a test string","bf-ecb","12345678", OPENSSL_RAW_DATA | OPENSSL_DONT_ZERO_PAD_KEY))); | ||
var_dump(bin2hex(openssl_encrypt("this is a test string","bf-ecb","1234567812345678" , OPENSSL_RAW_DATA))); | ||
?> | ||
--EXPECT-- | ||
string(48) "e3214d1b16e574828c8a3e222202dde81afd1ad2cb165ab3" | ||
string(48) "e3214d1b16e574828c8a3e222202dde81afd1ad2cb165ab3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters