Support Twofish and Blowfish
This commit is contained in:
parent
d756110821
commit
5a6b605710
@ -1,12 +1,11 @@
|
||||
<?php
|
||||
|
||||
use phpseclib\Crypt\TripleDES as Crypt_TripleDES;
|
||||
use phpseclib\Crypt\AES as Crypt_AES;
|
||||
use phpseclib\Crypt\Blowfish as Crypt_Blowfish;
|
||||
use phpseclib\Crypt\TripleDES as Crypt_TripleDES;
|
||||
use phpseclib\Crypt\Twofish as Crypt_Twofish;
|
||||
use phpseclib\Crypt\Random;
|
||||
|
||||
define('CRYPT_DES_MODE_CFB', Crypt_TripleDES::MODE_CFB);
|
||||
define('CRYPT_AES_MODE_CFB', Crypt_AES::MODE_CFB);
|
||||
|
||||
require_once dirname(__FILE__).'/openpgp.php';
|
||||
@include_once dirname(__FILE__).'/openpgp_crypt_rsa.php';
|
||||
@include_once dirname(__FILE__).'/openpgp_mcrypt_wrapper.php';
|
||||
@ -146,13 +145,13 @@ class OpenPGP_Crypt_Symmetric {
|
||||
public static function getCipher($algo) {
|
||||
$cipher = NULL;
|
||||
switch($algo) {
|
||||
case NULL:
|
||||
case 0:
|
||||
throw new Exception("Data is already unencrypted");
|
||||
case NULL:
|
||||
case 0:
|
||||
throw new Exception("Data is already unencrypted");
|
||||
case 2:
|
||||
$cipher = new Crypt_TripleDES(CRYPT_DES_MODE_CFB);
|
||||
$key_bytes = 24;
|
||||
$key_block_bytes = 8;
|
||||
$cipher = new Crypt_TripleDES(Crypt_TripleDES::MODE_CFB);
|
||||
$key_bytes = 24;
|
||||
$key_block_bytes = 8;
|
||||
break;
|
||||
case 3:
|
||||
if(defined('MCRYPT_CAST_128')) {
|
||||
@ -161,17 +160,30 @@ class OpenPGP_Crypt_Symmetric {
|
||||
throw new Exception("Unsupported cipher: you must have mcrypt installed to use CAST5");
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
$cipher = new Crypt_Blowfish(Crypt_Blowfish::MODE_CFB);
|
||||
$key_bytes = 16;
|
||||
$key_block_bytes = 8;
|
||||
break;
|
||||
case 7:
|
||||
$cipher = new Crypt_AES(CRYPT_AES_MODE_CFB);
|
||||
$cipher->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
|
||||
|
1
tests/data/symmetric-blowfish.gpg
Normal file
1
tests/data/symmetric-blowfish.gpg
Normal file
@ -0,0 +1 @@
|
||||
<EFBFBD>
σθΆh<CE86>±Ο³ΦΙfuάhθ‚ύ’sΕώ®Ωψ°Όώ_VF•4Σ
|
3
tests/data/symmetric-twofish.gpg
Normal file
3
tests/data/symmetric-twofish.gpg
Normal file
@ -0,0 +1,3 @@
|
||||
Œ
|
||||
cýІèÑÔÖÒ9=õÇâ]¼TföA¼c«vìåeøkº€Èʲõ¡©n}%.<16>lòëuÛ?\êåI
|
||||
ð[øõblÊ
|
@ -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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user