note 88229 added to ref.mcrypt

From: Date: Fri, 16 Jan 2009 10:33:33 +0000
Subject: note 88229 added to ref.mcrypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-149309@lists.php.net to get a copy of this message
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 ---- Server IP: 92.48.74.199 Probable Submitter: 213.246.73.172 ---- Manual Page -- http://www.php.net/manual/en/ref.mcrypt.php Edit -- https://master.php.net/note/edit/88229 Del: integrated -- https://master.php.net/note/delete/88229/integrated Del: useless -- https://master.php.net/note/delete/88229/useless Del: bad code -- https://master.php.net/note/delete/88229/bad+code Del: spam -- https://master.php.net/note/delete/88229/spam Del: non-english -- https://master.php.net/note/delete/88229/non-english Del: in docs -- https://master.php.net/note/delete/88229/in+docs Del: other reasons-- https://master.php.net/note/delete/88229 Reject -- https://master.php.net/note/reject/88229 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149309) next »