[Svn] r3931 - trunk/roundcubemail/program/include

trac at roundcube.net trac at roundcube.net
Tue Aug 31 20:39:32 CEST 2010


Author: alec
Date: 2010-08-31 13:39:32 -0500 (Tue, 31 Aug 2010)
New Revision: 3931

Modified:
   trunk/roundcubemail/program/include/rcmail.php
Log:
- performance: use custom function for IV vector generation instead of mcrypt_create_iv()


Modified: trunk/roundcubemail/program/include/rcmail.php
===================================================================
--- trunk/roundcubemail/program/include/rcmail.php	2010-08-31 07:22:44 UTC (rev 3930)
+++ trunk/roundcubemail/program/include/rcmail.php	2010-08-31 18:39:32 UTC (rev 3931)
@@ -1071,7 +1071,7 @@
     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 @@
 
       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 @@
   }
 
   /**
+   * 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

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list