From baf65d3fefa2a0ab6d7c78e80a1b9a3d10bae480 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 20 Dec 2014 11:14:08 -0600 Subject: [PATCH] Tests: small unit test updates --- tests/Unit/Crypt/AES/TestCase.php | 8 ++++---- tests/Unit/Crypt/RC2.php | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/Unit/Crypt/AES/TestCase.php b/tests/Unit/Crypt/AES/TestCase.php index a990eb1b..e885ae5c 100644 --- a/tests/Unit/Crypt/AES/TestCase.php +++ b/tests/Unit/Crypt/AES/TestCase.php @@ -135,10 +135,10 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase ); $combos = array( - array(16), - array(17), - 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(16), + array(17), + 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(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(16, 16), // two full size blocks diff --git a/tests/Unit/Crypt/RC2.php b/tests/Unit/Crypt/RC2.php index 6803aca3..533239e3 100644 --- a/tests/Unit/Crypt/RC2.php +++ b/tests/Unit/Crypt/RC2.php @@ -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 // 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". // 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); $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); if ($rc2->getEngine() == CRYPT_ENGINE_MCRYPT) { $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 { self::markTestSkipped('Unable to initialize mcrypt engine'); } @@ -63,7 +66,7 @@ class Unit_Crypt_RC2_TestCase extends PhpseclibTestCase $rc2->setPreferredEngine(CRYPT_ENGINE_OPENSSL); if ($rc2->getEngine() == CRYPT_ENGINE_OPENSSL) { $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 { self::markTestSkipped('Unable to initialize OpenSSL engine'); }