mcrypt_create_iv - why so slow?
| From: | Nathan Nobbe | Date: | Fri, 31 May 2013 06:40:45 +0000 |
| Subject: | mcrypt_create_iv - why so slow? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-321288@lists.php.net to get a copy of this message | ||
Hi folks,
This code:
<?php
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_CBC), MCRYPT_DEV_RANDOM);
var_dump($iv);
Takes just over a minute to run on my laptop and roughly 45 seconds on a
capable server, any idea why?
time php test-iv.php
string(32) "????'???H??y?PJ?U?1O;6???ѧ"
real 0m44.917s
user 0m0.024s
sys 0m0.036s
Also, I've noticed the mcrypt_encypt & mcrypt_decrypt complain with
The IV parameter must be as long as the blocksize
when not using mcrypt_create_iv, however, if the value of the IV parameter
is consistent in both calls, the decryption seems to succeed despite the
warning.
So wondering:
* can the call to mcrypt_create_iv be sped up
* is there an alternative (faster) way to create a proper iv
* how big a risk is it to 'ride dirty' here and not use mcrypt_create_iv
thanks,
-nathan