summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2010-08-31 18:39:32 +0000
committeralecpl <alec@alec.pl>2010-08-31 18:39:32 +0000
commit564741f77b5203d3d54ec14e32d25c87028ecd7f (patch)
treee2440d4e90f05196c5e5c0176336b40377ad0ee2 /program
parentb0fd4cfd69a51455b657e16fbd09a2bf11740904 (diff)
- performance: use custom function for IV vector generation instead of mcrypt_create_iv()
Diffstat (limited to 'program')
-rw-r--r--program/include/rcmail.php22
1 files changed, 18 insertions, 4 deletions
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 980379075..808f0db06 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -1071,7 +1071,7 @@ class rcmail
if (function_exists('mcrypt_module_open') &&
($td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_CBC, "")))
{
- $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
+ $iv = $this->create_iv(mcrypt_enc_get_iv_size($td));
mcrypt_generic_init($td, $this->config->get_crypto_key($key), $iv);
$cipher = $iv . mcrypt_generic($td, $clear);
mcrypt_generic_deinit($td);
@@ -1082,9 +1082,7 @@ class rcmail
if (function_exists('des')) {
$des_iv_size = 8;
- $iv = '';
- for ($i = 0; $i < $des_iv_size; $i++)
- $iv .= sprintf("%c", mt_rand(0, 255));
+ $iv = $this->create_iv($des_iv_size);
$cipher = $iv . des($this->config->get_crypto_key($key), $clear, 1, 1, $iv);
}
else {
@@ -1153,6 +1151,22 @@ class rcmail
}
/**
+ * Generates encryption initialization vector (IV)
+ *
+ * @param int Vector size
+ * @return string Vector string
+ */
+ private function create_iv($size)
+ {
+ // mcrypt_create_iv() can be slow when system lacks entrophy
+ // we'll generate IV vector manually
+ $iv = '';
+ for ($i = 0; $i < $size; $i++)
+ $iv .= chr(mt_rand(0, 255));
+ return $iv;
+ }
+
+ /**
* Build a valid URL to this instance of RoundCube
*
* @param mixed Either a string with the action or url parameters as key-value pairs