|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2014-03-04 19:49 UTC] narf at devilix dot net
[2014-10-16 04:26 UTC] gm dot outside+php at gmail dot com
[2016-12-14 17:55 UTC] leigh@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: leigh
[2016-12-14 17:55 UTC] leigh@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 22:00:01 2025 UTC |
Description: ------------ Please verify that the 80-bit and 40-bit test vectors in RFC2144 Section B.1 do not agree with the output from mcrypt when using CAST 128 encryption. I provided a test program with functions that print and parse the hexadecimal. I am using mcrypt 2.5.8 on php 5.3.13. The 128-bit test vector does work though. The problem is probably related to the fact that CAST-128 changes the number of rounds from 16 to 12 when a key is 80 bits or smaller. I have verified that the test vectors in RFC2144 work with a different piece of code written in C. Please let me know if there is a work around. Test script: --------------- function str2hex($string) { $hex=''; for ($i=0; $i < strlen($string); $i++) { $hex .= sprintf("%02x",ord($string[$i])) . ' '; } return $hex; } function hex2str($x) { $s=''; foreach(explode("\n",trim(chunk_split($x,2))) as $h) $s.=chr(hexdec($h)); return($s); } //RFC-2144 $text = hex2str("0123456789ABCDEF"); //Section B.1 128-bit example $key = hex2str("0123456712345678234567893456789A"); echo "RFC-2144 Section B.1 128-bit<BR>"; $enc = mcrypt_encrypt(MCRYPT_CAST_128,$key,$text,MCRYPT_MODE_ECB); echo "ciphertext: " . str2hex($enc); echo "<BR>"; //RFC-2144 //Section B.1 80-bit example $key = hex2str("01234567123456782345"); echo "RFC-2144 Section B.1 80-bit<BR>"; $enc = mcrypt_encrypt(MCRYPT_CAST_128,$key,$text,MCRYPT_MODE_ECB); echo "ciphertext: " . str2hex($enc); echo "<BR>"; //RFC-2144 //Section B.1 40-bit example $key = hex2str("0123456712"); echo "RFC-2144 Section B.1 40-bit<BR>"; $enc = mcrypt_encrypt(MCRYPT_CAST_128,$key,$text,MCRYPT_MODE_ECB); echo "ciphertext: " . str2hex($enc); echo "<BR>"; Expected result: ---------------- see RFC2144 Section B.1 Actual result: -------------- see result of provided code.