Bug #66949 [NEW]: Serpent produces result which can not be decrypted from other languages
| From: | pkorsukov at gmail dot com | Date: | Mon, 24 Mar 2014 20:06:20 +0000 |
| Subject: | Bug #66949 [NEW]: Serpent produces result which can not be decrypted from other languages | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-184869@lists.php.net to get a copy of this message | ||
From: pkorsukov at gmail dot com
Operating system: Windows 7
PHP version: 5.5.10
Package: mcrypt related
Bug Type: Bug
Bug description:Serpent produces result which can not be decrypted from other languages
Description:
------------
The implementation of Serpent in PHP not passes test from Serpent AES
submission. As a result, the sting encrypted by PHP MCrypt can not be
decrypted in other programming languages (I tried C# and Bouncy Castle
support tried Java). If we use same key and iv, then PHP results for
decrypt or encrypt differs from other programming languages.
More details:
https://github.com/bcgit/bc-csharp/issues/13#issuecomment-38490830
Test script:
---------------
<?php
function crypt_test($algo, $mode, $key, $iv, $name, $plaintext,
$expected) {
$cipher = mcrypt_module_open($algo,'',$mode,'');
mcrypt_generic_init($cipher, $key, $iv);
$encrypted = mcrypt_generic($cipher, hex2bin($plaintext));
printf("%s/%s %s:\n expected: %s\n actual: %s\n", $algo, $mode,
$name, bin2hex($encrypted), $expected);
mcrypt_generic_deinit($cipher);
mcrypt_module_close($cipher);
}
$key = hex2bin('00000000000000000000000000000000');
$iv = hex2bin('00000000000000000000000000000000');
crypt_test('serpent', 'ecb', $key, $iv, 'zeros',
'00000000000000000000000000000000',
'e9ba668276b81896d093a9e67ab12036');
crypt_test('serpent', 'ecb', $key, $iv, 'I1',
'80000000000000000000000000000000',
'10b5ffb720b8cb9002a1142b0ba2e94a');
crypt_test('serpent', 'ecb', $key, $iv, 'I2',
'40000000000000000000000000000000',
'91a7847ef1cd87551b5b4bf6f8e96e2c');
crypt_test('serpent', 'ecb', $key, $iv, 'I3',
'20000000000000000000000000000000',
'5d32aece8383fb2ee22cb4a6061d1429');
?>
Expected result:
----------------
serpent/ecb zeros:
expected: 3620b17ae6a993d09618b8768266bae9
actual: 3620b17ae6a993d09618b8768266bae9
serpent/ecb I1:
expected: a3b35de7c358ddd82644678c64b8bcbb
actual: a3b35de7c358ddd82644678c64b8bcbb
serpent/ecb I2:
expected: 04abcfe4e0af27ff92a2bb10949d7dd2
actual: 04abcfe4e0af27ff92a2bb10949d7dd2
serpent/ecb I3:
expected: 8f773194b78ef2b2740237ef12d08608
actual: 8f773194b78ef2b2740237ef12d08608
Actual result:
--------------
serpent/ecb zeros:
expected: 3620b17ae6a993d09618b8768266bae9
actual: e9ba668276b81896d093a9e67ab12036
serpent/ecb I1:
expected: a3b35de7c358ddd82644678c64b8bcbb
actual: 10b5ffb720b8cb9002a1142b0ba2e94a
serpent/ecb I2:
expected: 04abcfe4e0af27ff92a2bb10949d7dd2
actual: 91a7847ef1cd87551b5b4bf6f8e96e2c
serpent/ecb I3:
expected: 8f773194b78ef2b2740237ef12d08608
actual: 5d32aece8383fb2ee22cb4a6061d1429
--
Edit bug report at https://bugs.php.net/bug.php?id=66949&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66949&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66949&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66949&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66949&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66949&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66949&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66949&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66949&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66949&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66949&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66949&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66949&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66949&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66949&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66949&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66949&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66949&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66949&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66949&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66949&r=mysqlcfg