From 5a6b60571067d1ac690c0aaf9c69a96d80966267 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 25 Jul 2018 11:06:49 -0500 Subject: [PATCH] Support Twofish and Blowfish --- lib/openpgp_crypt_symmetric.php | 42 ++++++++++++++++++++----------- tests/data/symmetric-blowfish.gpg | 1 + tests/data/symmetric-twofish.gpg | 3 +++ tests/phpseclib_suite.php | 18 ++++++++++--- 4 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 tests/data/symmetric-blowfish.gpg create mode 100644 tests/data/symmetric-twofish.gpg diff --git a/lib/openpgp_crypt_symmetric.php b/lib/openpgp_crypt_symmetric.php index c853379..ab7804e 100644 --- a/lib/openpgp_crypt_symmetric.php +++ b/lib/openpgp_crypt_symmetric.php @@ -1,12 +1,11 @@ setKeyLength(128); + $cipher = new Crypt_AES(Crypt_AES::MODE_CFB); + $cipher->setKeyLength(128); break; case 8: - $cipher = new Crypt_AES(CRYPT_AES_MODE_CFB); - $cipher->setKeyLength(192); + $cipher = new Crypt_AES(Crypt_AES::MODE_CFB); + $cipher->setKeyLength(192); break; case 9: - $cipher = new Crypt_AES(CRYPT_AES_MODE_CFB); + $cipher = new Crypt_AES(Crypt_AES::MODE_CFB); + $cipher->setKeyLength(256); + break; + case 10: + $cipher = new Crypt_Twofish(Crypt_Twofish::MODE_CFB); + if(method_exists($cipher, 'setKeyLength')) { $cipher->setKeyLength(256); + } else { + $cipher = NULL; + } break; } if(!$cipher) return array(NULL, NULL, NULL); // Unsupported cipher diff --git a/tests/data/symmetric-blowfish.gpg b/tests/data/symmetric-blowfish.gpg new file mode 100644 index 0000000..0dda30c --- /dev/null +++ b/tests/data/symmetric-blowfish.gpg @@ -0,0 +1 @@ + hϳfuhs_VF4 \ No newline at end of file diff --git a/tests/data/symmetric-twofish.gpg b/tests/data/symmetric-twofish.gpg new file mode 100644 index 0000000..14255d8 --- /dev/null +++ b/tests/data/symmetric-twofish.gpg @@ -0,0 +1,3 @@ +  +cІ 9=]TfA cvekʲn}%.lu?\I +[bl \ No newline at end of file diff --git a/tests/phpseclib_suite.php b/tests/phpseclib_suite.php index d592db5..2517e6e 100644 --- a/tests/phpseclib_suite.php +++ b/tests/phpseclib_suite.php @@ -76,10 +76,6 @@ class Decryption extends PHPUnit_Framework_TestCase { } } - public function testDecryptAES() { - $this->oneSymmetric("hello", "PGP\n", "symmetric-aes.gpg"); - } - public function testDecrypt3DES() { $this->oneSymmetric("hello", "PGP\n", "symmetric-3des.gpg"); } @@ -88,6 +84,20 @@ class Decryption extends PHPUnit_Framework_TestCase { $this->oneSymmetric("hello", "PGP\n", "symmetric-cast5.gpg"); } + public function testDecryptBlowfish() { + $this->oneSymmetric("hello", "PGP\n", "symmetric-blowfish.gpg"); + } + + public function testDecryptAES() { + $this->oneSymmetric("hello", "PGP\n", "symmetric-aes.gpg"); + } + + public function testDecryptTwofish() { + if(OpenPGP_Crypt_Symmetric::getCipher(10)[0]) { + $this->oneSymmetric("hello", "PGP\n", "symmetric-twofish.gpg"); + } + } + public function testDecryptSessionKey() { $this->oneSymmetric("hello", "PGP\n", "symmetric-with-session-key.gpg"); }