Bug #73812 [NEW]: openssl_error_string() dubious when decrypting aes-128-ccm
| From: | anthon dot pang at gmail dot com | Date: | Sun, 25 Dec 2016 19:04:19 +0000 |
| Subject: | Bug #73812 [NEW]: openssl_error_string() dubious when decrypting aes-128-ccm | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-206201@lists.php.net to get a copy of this message | ||
From: anthon dot pang at gmail dot com
Operating system:
PHP version: 7.1.0
Package: OpenSSL related
Bug Type: Bug
Bug description:openssl_error_string() dubious when decrypting aes-128-ccm
Description:
------------
openssl_error_string() returns a dubious message,
"error:0607A082:digital envelope
routines:EVP_CIPHER_CTX_set_key_length:invalid key length" when
decrypting even though the payload was successfully decrypted
(In the test script, the payload was produced using sjcl.)
Test script:
---------------
<?php
$password = 'password';
$input =
json_decode('{"iv":"A0DOQPxWAlJ5LHjoyg==","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Kk+ws1Xj0Xo=","ct":"NCPpLCHLLO5mBOGpSUpHdXPgKZA="}',
true);
$digest = hash_pbkdf2('sha256', $password,
base64_decode($input['salt']), $input['iter'], 0, true);
$cipher = $input['cipher'] . '-' . $input['ks'] . '-' .
$input['mode'];
$ct = substr(base64_decode($input['ct']), 0, - $input['ts'] / 8);
$tag = substr(base64_decode($input['ct']), - $input['ts'] / 8);
$iv = base64_decode($input['iv']);
$adata = $input['adata'];
$dt = openssl_decrypt($ct, $cipher, $digest, OPENSSL_RAW_DATA, $iv,
$tag, $adata);
var_dump($dt);
while ($msg = openssl_error_string()) {
echo $msg . "\n";
}
Expected result:
----------------
string(12) "Hello World!"
Actual result:
--------------
string(12) "Hello World!"
error:0607A082:digital envelope
routines:EVP_CIPHER_CTX_set_key_length:invalid key length
--
Edit bug report at https://bugs.php.net/bug.php?id=73812&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73812&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73812&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73812&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73812&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73812&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73812&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73812&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73812&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73812&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73812&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73812&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73812&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73812&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73812&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73812&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73812&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73812&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73812&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73812&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73812&r=mysqlcfg