Add support for CAST5 using mcrypt
This commit is contained in:
parent
e1181bd25e
commit
d2913ccb8a
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
require_once dirname(__FILE__).'/openpgp.php';
|
require_once dirname(__FILE__).'/openpgp.php';
|
||||||
@include_once dirname(__FILE__).'/openpgp_crypt_rsa.php';
|
@include_once dirname(__FILE__).'/openpgp_crypt_rsa.php';
|
||||||
|
@include_once dirname(__FILE__).'/openpgp_mcrypt_wrapper.php';
|
||||||
@include_once 'Crypt/AES.php';
|
@include_once 'Crypt/AES.php';
|
||||||
@include_once 'Crypt/TripleDES.php';
|
@include_once 'Crypt/TripleDES.php';
|
||||||
require_once 'Crypt/Random.php'; // part of phpseclib is absolutely required
|
require_once 'Crypt/Random.php'; // part of phpseclib is absolutely required
|
||||||
@ -148,6 +149,11 @@ class OpenPGP_Crypt_Symmetric {
|
|||||||
$key_block_bytes = 8;
|
$key_block_bytes = 8;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 3:
|
||||||
|
if(defined('MCRYPT_CAST_128')) {
|
||||||
|
$cipher = new MCryptWrapper(MCRYPT_CAST_128);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
if(class_exists('Crypt_AES')) {
|
if(class_exists('Crypt_AES')) {
|
||||||
$cipher = new Crypt_AES(CRYPT_AES_MODE_CFB);
|
$cipher = new Crypt_AES(CRYPT_AES_MODE_CFB);
|
||||||
|
31
lib/openpgp_mcrypt_wrapper.php
Normal file
31
lib/openpgp_mcrypt_wrapper.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if(function_exists('mcrypt_encrypt') && defined('MCRYPT_MODE_CFB')) {
|
||||||
|
class MCryptWrapper {
|
||||||
|
public $cipher, $key, $iv, $key_size, $block_size;
|
||||||
|
|
||||||
|
|
||||||
|
function __construct($cipher) {
|
||||||
|
$this->cipher = $cipher;
|
||||||
|
$this->key_size = mcrypt_module_get_algo_key_size($cipher);
|
||||||
|
$this->block_size = mcrypt_module_get_algo_block_size($cipher);
|
||||||
|
$this->iv = str_repeat("\0", mcrypt_get_iv_size($cipher, 'ncfb'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function setKey($key) {
|
||||||
|
$this->key = $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setIV($iv) {
|
||||||
|
$this->iv = $iv;
|
||||||
|
}
|
||||||
|
|
||||||
|
function encrypt($data) {
|
||||||
|
return mcrypt_encrypt($this->cipher, $this->key, $data, 'ncfb', $this->iv);
|
||||||
|
}
|
||||||
|
|
||||||
|
function decrypt($data) {
|
||||||
|
return mcrypt_decrypt($this->cipher, $this->key, $data, 'ncfb', $this->iv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
tests/data/symmetric-cast5.gpg
Normal file
1
tests/data/symmetric-cast5.gpg
Normal file
@ -0,0 +1 @@
|
|||||||
|
Ś
“9ĆÖF‡-`Ň2ľč<C4BE>—w¦¨DżĘş0q<30>,Čů‚zřý}Zϲ֣‡#Öľźí aŮ›!ţ!Í
|
@ -84,6 +84,10 @@ class Decryption extends PHPUnit_Framework_TestCase {
|
|||||||
$this->oneSymmetric("hello", "PGP\n", "symmetric-3des.gpg");
|
$this->oneSymmetric("hello", "PGP\n", "symmetric-3des.gpg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDecryptCAST5() { // Requires mcrypt
|
||||||
|
$this->oneSymmetric("hello", "PGP\n", "symmetric-cast5.gpg");
|
||||||
|
}
|
||||||
|
|
||||||
public function testDecryptSessionKey() {
|
public function testDecryptSessionKey() {
|
||||||
$this->oneSymmetric("hello", "PGP\n", "symmetric-with-session-key.gpg");
|
$this->oneSymmetric("hello", "PGP\n", "symmetric-with-session-key.gpg");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user