Pycrypto aes 256 Initialization Vector Size

In this case, I have a PHP script that uses aes256, CBC key size and IV is 32 bytes

data= '123456789abcdef' from Crypto.Cipher import AES a = AES.new('oqufXQ(?bc=6_hR2I3sMZChDpb6dDlw4',2,'fOaiIOkD8*9Xeu_s4_bb87Ox_UG+D9GA') print a.encrypt(data) 

and the error I received

 <type 'exceptions.ValueError'>: IV must be 16 bytes long Traceback (most recent call last): File "/base/data/home/apps/s~xxxxxxx/1.155074369696961822/main.py", line 4, in <module> 

php code that works

  echo base64_encode(encrypt('0123456789abcdef')) ; function encrypt($data) { return mcrypt_encrypt(MCRYPT_RIJNDAEL_256 ,'oqufXQ(?bc=6_hR2I3sMZChDpb6dDlw4', $data , MCRYPT_MODE_CBC, utf8_encode('fOaiIOkD8*9Xeu_s4_bb87Ox_UG+D9GA') ); } 

I can not resize IV

Please note that I'm not very familiar with Python, I just need a way to encrypt data, as this will be a single application.

+4
source share
1 answer

Yeah!

There is a difference of opinion, which means "256".

AES has a fixed block size of 128 bits, so "AES 256" means 128-bit blocks, 256-bit key, 14 rounds.

However, Rijndael allows you to change the key size and block size. MCRYPT_RIJNDAEL_256 refers to Rijndael with a block size set to 256 (and I don't know how many rounds). So it really takes 32 bytes IV. Your PHP script does not use AES 256.

This is confirmed in https://bugs.php.net/bug.php?id=47125 - the reporter considers this an error in PHP mcrypt, PHP considers this an error in libmcrypt, but this is not an error, since libmcrypt makes the document which means MCRYPT_RIJNDAEL_256 (at least for the linux man page for mcrypt, my google-fu could not find any real documentation for libmcrypt). This is not the same as AES 256.

So, you encrypt and decrypt ciphers, which, although related, can also be completely different.

The bad news is that Crypto.Cipher.RIJNDAEL does not exist in Crypto.Cipher.RIJNDAEL . If you can pass the 256-bit key to MCRYPT_RIJNDAEL_128 in a PHP script, then this will be AES 256 (thanks to Paŭlo).

+11
source

Source: https://habr.com/ru/post/1384164/


All Articles