note 88229 rejected from ref.mcrypt by thiago

From: Date: Fri, 16 Jan 2009 12:08:12 +0000
Subject: note 88229 rejected from ref.mcrypt by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149310@lists.php.net to get a copy of this message
Note Submitter: j dot andersch at foofox dot de ---- I tried to validate a JavaScript-AES according to the standard [1] and test the encryption values with PHP's MCRYPT_RIJNDAEL_128 in ECB-mode <?php # test if JavaScript AES works correctly and is compatible with PHP #================================================== $key = 'E8E9EAEBEDEEEFF0F2F3F4F5F7F8F9FA'; $plaintext = '014BAF2278A69D331D5180103643E99A'; # expected cipher: 6743C3D1519AB4F2CD9A78AB09A511BD # convert input $key = pack('H*', $key); $plaintext = pack('H*', $plaintext); # encrypt $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, $key, $iv); $encrypted_data = mcrypt_generic($td, $plaintext); mcrypt_generic_deinit($td); mcrypt_module_close($td); # display encryption value: should be 6743c3d1519ab4f2cd9a78ab09a511bd echo bin2hex($encrypted_data); ?> Please note that modifying the script for the 192 and 256 bit encryption does not give the expected values of [1], because there seems to be a deviation from the AES standard in PHP. PHP seems to expand the blocksizes to be encrypted to 192 and 256 bit instead of using 128 bit. ________________ [1] Federal Information Processing Standards Publication 197, November 26, 2001, Announcing the ADVANCED ENCRYPTION STANDARD (AES) http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf

« previous php.notes (#149310) next »