Esempio n. 1
0
 /**
  * Opens the module of the algorithm and the mode to be used
  *
  * This function opens the module of the algorithm and the mode to be used. The name of the algorithm
  * is specified in algorithm, e.g. "twofish" or is one of the MCRYPT_ciphername constants. The module
  * is closed by calling mcrypt_module_close().
  *
  * @param string $algorithm
  * @param string $algorithm_directory
  * @param string $mode
  * @param string $mode_directory
  * @return object
  * @access public
  */
 function phpseclib_mcrypt_module_open($algorithm, $algorithm_directory, $mode, $mode_directory)
 {
     $modeMap = array('ctr' => Base::MODE_CTR, 'ecb' => Base::MODE_ECB, 'cbc' => Base::MODE_CBC, 'ncfb' => Base::MODE_CFB, 'nofb' => Base::MODE_OFB, 'stream' => Base::MODE_STREAM);
     switch (true) {
         case !isset($modeMap[$mode]):
         case $mode == 'stream' && $algorithm != 'arcfour':
         case $algorithm == 'arcfour' && $mode != 'stream':
             trigger_error('mcrypt_module_open(): Could not open encryption module', E_USER_WARNING);
             return false;
     }
     switch ($algorithm) {
         case 'rijndael-128':
             $cipher = new phpseclib_mcrypt_rijndael($modeMap[$mode]);
             $cipher->setBlockLength(128);
             break;
         case 'twofish':
             $cipher = new Twofish($modeMap[$mode]);
             break;
         case 'rijndael-192':
             $cipher = new phpseclib_mcrypt_rijndael($modeMap[$mode]);
             $cipher->setBlockLength(192);
             break;
         case 'des':
             $cipher = new DES($modeMap[$mode]);
             break;
         case 'rijndael-256':
             $cipher = new phpseclib_mcrypt_rijndael($modeMap[$mode]);
             $cipher->setBlockLength(256);
             break;
         case 'blowfish':
             $cipher = new Blowfish($modeMap[$mode]);
             break;
         case 'rc2':
             $cipher = new RC2($modeMap[$mode]);
             break;
         case 'tripledes':
             $cipher = new TripleDES($modeMap[$mode]);
             break;
         case 'arcfour':
             $cipher = new RC4();
             break;
         default:
             trigger_error('mcrypt_module_open(): Could not open encryption module', E_USER_WARNING);
             return false;
     }
     $cipher->disablePadding();
     return $cipher;
 }