includes/rijndael.php
changeset 286 b2f985e4cef3
parent 54 84b56303cab5
child 345 4ccdfeee9a11
child 440 105457df35e5
--- a/includes/rijndael.php	Fri Nov 23 17:59:24 2007 -0500
+++ b/includes/rijndael.php	Sat Nov 24 00:53:23 2007 -0500
@@ -16,10 +16,13 @@
 define ('ENC_BASE64', 202);
 define ('ENC_BINARY', 203);
 
+$_aes_objcache = array();
+
 class AESCrypt {
   
   var $debug = false;
   var $mcrypt = false;
+  var $decrypt_cache = array();
 
   // Rijndael parameters --  Valid values are 128, 192, or 256
   
@@ -128,6 +131,18 @@
     $this->debug = $debug;
   }
   
+  function singleton($key_size, $block_size)
+  {
+    global $_aes_objcache;
+    if ( isset($_aes_objcache["$key_size,$block_size"]) )
+    {
+      return $_aes_objcache["$key_size,$block_size"];
+    }
+    
+    $_aes_objcache["$key_size,$block_size"] = new AESCrypt($key_size, $block_size);
+    return $_aes_objcache["$key_size,$block_size"];
+  }
+  
   // Error handler
   
   function trigger_error($text, $level = E_USER_NOTICE)
@@ -804,6 +819,14 @@
   {
     if ( $text == '' )
       return '';
+    $text_orig = $text;
+    if ( isset($this->decrypt_cache[$key]) && is_array($this->decrypt_cache[$key]) )
+    {
+      if ( isset($this->decrypt_cache[$key][$text]) )
+      {
+        return $this->decrypt_cache[$key][$text];
+      }
+    }
     switch($input_encoding)
     {
       case ENC_BINARY:
@@ -838,6 +861,11 @@
       }
       $dypt = $this->byteArrayToString($dypt);
     }
+    if ( !isset($this->decrypt_cache[$key]) )
+      $this->decrypt_cache[$key] = array();
+    
+    $this->decrypt_cache[$key][$text_orig] = $dypt;
+    
     return $dypt;
   }