diff --git a/lib/openpgp_crypt_symmetric.php b/lib/openpgp_crypt_symmetric.php index a8b52d6..9833a46 100644 --- a/lib/openpgp_crypt_symmetric.php +++ b/lib/openpgp_crypt_symmetric.php @@ -2,6 +2,7 @@ require_once dirname(__FILE__).'/openpgp.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/TripleDES.php'; require_once 'Crypt/Random.php'; // part of phpseclib is absolutely required @@ -148,6 +149,11 @@ class OpenPGP_Crypt_Symmetric { $key_block_bytes = 8; } break; + case 3: + if(defined('MCRYPT_CAST_128')) { + $cipher = new MCryptWrapper(MCRYPT_CAST_128); + } + break; case 7: if(class_exists('Crypt_AES')) { $cipher = new Crypt_AES(CRYPT_AES_MODE_CFB); diff --git a/lib/openpgp_mcrypt_wrapper.php b/lib/openpgp_mcrypt_wrapper.php new file mode 100644 index 0000000..1030700 --- /dev/null +++ b/lib/openpgp_mcrypt_wrapper.php @@ -0,0 +1,31 @@ +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); + } + } +} diff --git a/tests/data/symmetric-cast5.gpg b/tests/data/symmetric-cast5.gpg new file mode 100644 index 0000000..950b791 --- /dev/null +++ b/tests/data/symmetric-cast5.gpg @@ -0,0 +1 @@ + 9F-`2萗wD0q,z}Zϲ֣#־ aٛ!! \ No newline at end of file diff --git a/tests/phpseclib_suite.php b/tests/phpseclib_suite.php index 90e5f7d..0f6ae30 100644 --- a/tests/phpseclib_suite.php +++ b/tests/phpseclib_suite.php @@ -84,6 +84,10 @@ class Decryption extends PHPUnit_Framework_TestCase { $this->oneSymmetric("hello", "PGP\n", "symmetric-3des.gpg"); } + public function testDecryptCAST5() { // Requires mcrypt + $this->oneSymmetric("hello", "PGP\n", "symmetric-cast5.gpg"); + } + public function testDecryptSessionKey() { $this->oneSymmetric("hello", "PGP\n", "symmetric-with-session-key.gpg"); }