Tests: small unit test updates

This commit is contained in:
terrafrost 2014-12-20 11:14:08 -06:00
parent 5d0cb1cee9
commit baf65d3fef
2 changed files with 10 additions and 7 deletions

View File

@ -135,10 +135,10 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
); );
$combos = array( $combos = array(
array(16), array(16),
array(17), array(17),
array(1, 16), array(1, 16),
array(3, 6, 7), // (3 to test the openssl_encrypt call and the buffer creation, 6 to test the exclusive use of the buffer and 7 to test the buffer's exhaustion and recreation) array(3, 6, 7), // (3 to test the openssl_encrypt call and the buffer creation, 6 to test the exclusive use of the buffer and 7 to test the buffer's exhaustion and recreation)
array(15, 4), // (15 to test openssl_encrypt call and buffer creation and 4 to test something that spans multpile bloc array(15, 4), // (15 to test openssl_encrypt call and buffer creation and 4 to test something that spans multpile bloc
array(3, 6, 10, 16), // this is why the strlen check in the buffer-only code was needed array(3, 6, 10, 16), // this is why the strlen check in the buffer-only code was needed
array(16, 16), // two full size blocks array(16, 16), // two full size blocks

View File

@ -33,7 +33,7 @@ class Unit_Crypt_RC2_TestCase extends PhpseclibTestCase
// in contrast, to my knowledge, there is no technique for expanding a key less than 128 bits to 128 bits, via RC2 key expansion. the only // in contrast, to my knowledge, there is no technique for expanding a key less than 128 bits to 128 bits, via RC2 key expansion. the only
// scenario in that regard is null padding. // scenario in that regard is null padding.
// simple truncation is insufficient, since, quoting RFC2268, "the purpose of th key-expansion algorithm [in RC2] is to modify the key buffer // simple truncation is insufficient, since, quoting RFC2268, "the purpose of the key-expansion algorithm [in RC2] is to modify the key buffer
// so that each bit of the expanded key depends in a complicated way on every bit of the supplied input key". // so that each bit of the expanded key depends in a complicated way on every bit of the supplied input key".
// now, to OpenSSL's credit, null padding is internally consistent with OpenSSL. OpenSSL only supports fixed length keys. For rc2, rc4 and // now, to OpenSSL's credit, null padding is internally consistent with OpenSSL. OpenSSL only supports fixed length keys. For rc2, rc4 and
@ -52,10 +52,13 @@ class Unit_Crypt_RC2_TestCase extends PhpseclibTestCase
$rc2->setPreferredEngine(CRYPT_ENGINE_INTERNAL); $rc2->setPreferredEngine(CRYPT_ENGINE_INTERNAL);
$internal = $rc2->encrypt('d'); $internal = $rc2->encrypt('d');
$result = pack('H*', 'e3b36057f4821346');
$this->assertEquals($result, $internal, 'Failed asserting that the internal engine produced the correct result');
$rc2->setPreferredEngine(CRYPT_ENGINE_MCRYPT); $rc2->setPreferredEngine(CRYPT_ENGINE_MCRYPT);
if ($rc2->getEngine() == CRYPT_ENGINE_MCRYPT) { if ($rc2->getEngine() == CRYPT_ENGINE_MCRYPT) {
$mcrypt = $rc2->encrypt('d'); $mcrypt = $rc2->encrypt('d');
$this->assertEquals($internal, $mcrypt, 'Failed asserting that the internal and mcrypt engines produce identical results'); $this->assertEquals($result, $mcrypt, 'Failed asserting that the mcrypt engine produced the correct result');
} else { } else {
self::markTestSkipped('Unable to initialize mcrypt engine'); self::markTestSkipped('Unable to initialize mcrypt engine');
} }
@ -63,7 +66,7 @@ class Unit_Crypt_RC2_TestCase extends PhpseclibTestCase
$rc2->setPreferredEngine(CRYPT_ENGINE_OPENSSL); $rc2->setPreferredEngine(CRYPT_ENGINE_OPENSSL);
if ($rc2->getEngine() == CRYPT_ENGINE_OPENSSL) { if ($rc2->getEngine() == CRYPT_ENGINE_OPENSSL) {
$openssl = $rc2->encrypt('d'); $openssl = $rc2->encrypt('d');
$this->assertEquals($internal, $openssl, 'Failed asserting that the internal and OpenSSL engines produce identical results'); $this->assertEquals($result, $openssl, 'Failed asserting that the OpenSSL engine produced the correct result');
} else { } else {
self::markTestSkipped('Unable to initialize OpenSSL engine'); self::markTestSkipped('Unable to initialize OpenSSL engine');
} }