Translated encryption/decryption consistency tests to catch2

This commit is contained in:
Leonetienne 2022-05-16 23:26:29 +02:00
parent 14e1fbe32c
commit f75a41d8dc
No known key found for this signature in database
GPG Key ID: C33879CD92E9708C

View File

@ -1,22 +1,14 @@
/* #include <GCrypt/Cipher.h>
#include "CppUnitTest.h" #include <GCrypt/Util.h>
#include "../GhettoCrypt/Cipher.h" #include "Catch2.h"
#include "../GhettoCrypt/Util.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Leonetienne::GCrypt;
using namespace GhettoCipher;
// THESE TESTS ASSUME BLOCK_SIZE == 512 // THESE TESTS ASSUME BLOCK_SIZE == 512
namespace SimpleTests
{
TEST_CLASS(EncryptEqualsDecrypt)
{
public:
// Tests that encrypting a message of exactly BLOCK_SIZE yields the exact message back // Tests that encrypting a message of exactly BLOCK_SIZE yields the exact message back
TEST_METHOD(SingleBlock_NoPadding) TEST_CASE(__FILE__"/SingleBlock_NoPadding", "[Encryption/Decryption consistency]") {
{
// Instanciate our cipher and supply a key // Instanciate our cipher and supply a key
const Block key = PasswordToKey("1234"); const Block key = PasswordToKey("1234");
const Cipher cipher(key); const Cipher cipher(key);
@ -39,15 +31,15 @@ namespace SimpleTests
const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits); const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits);
// Assert that the decrypted text equals the plaintext // Assert that the decrypted text equals the plaintext
Assert::AreEqual( REQUIRE(
cleartext_bits, cleartext_bits ==
decryptedBits decryptedBits
); );
} }
// Tests that encrypting a message of less than BLOCK_SIZE yields the exact message plus zero-padding back // Tests that encrypting a message of less than BLOCK_SIZE yields the exact message plus zero-padding back
TEST_METHOD(SingleBlock_Padding) TEST_CASE(__FILE__"/SingleBlock_Padding", "[Encryption/Decryption consistency]") {
{
// Instanciate our cipher and supply a key // Instanciate our cipher and supply a key
const Block key = PasswordToKey("1234"); const Block key = PasswordToKey("1234");
const Cipher cipher(key); const Cipher cipher(key);
@ -79,15 +71,15 @@ namespace SimpleTests
const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits); const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits);
// Assert that the decrypted text equals the plaintext // Assert that the decrypted text equals the plaintext
Assert::AreEqual( REQUIRE(
cleartext_bits_EXPECTED_RESULT, cleartext_bits_EXPECTED_RESULT ==
decryptedBits decryptedBits
); );
} }
// Tests that a decrypted ciphertext equals its plaintrext version, using a cleartext that requires A LOT of blocks // Tests that a decrypted ciphertext equals its plaintrext version, using a cleartext that requires A LOT of blocks
TEST_METHOD(MultiBlock_NoPadding) TEST_CASE(__FILE__"MultiBlock_NoPadding/", "[Encryption/Decryption consistency]") {
{
// Instanciate our cipher and supply a key // Instanciate our cipher and supply a key
const Block key = PasswordToKey("1234"); const Block key = PasswordToKey("1234");
const Cipher cipher(key); const Cipher cipher(key);
@ -134,15 +126,15 @@ namespace SimpleTests
const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits); const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits);
// Assert that the decrypted text equals the plaintext // Assert that the decrypted text equals the plaintext
Assert::AreEqual( REQUIRE(
cleartext_bits, cleartext_bits ==
decryptedBits decryptedBits
); );
} }
// Tests that a decrypted ciphertext equals its plaintrext version, using a cleartext that requires A LOT of blocks // Tests that a decrypted ciphertext equals its plaintrext version, using a cleartext that requires A LOT of blocks
TEST_METHOD(MultiBlock_Padding) TEST_CASE(__FILE__"MultiBlock_Padding/", "[Encryption/Decryption consistency]") {
{
// Instanciate our cipher and supply a key // Instanciate our cipher and supply a key
const Block key = PasswordToKey("1234"); const Block key = PasswordToKey("1234");
const Cipher cipher(key); const Cipher cipher(key);
@ -222,11 +214,9 @@ namespace SimpleTests
const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits); const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits);
// Assert that the decrypted text equals the plaintext // Assert that the decrypted text equals the plaintext
Assert::AreEqual( REQUIRE(
cleartext_bits_EXPECTED_RESULT, cleartext_bits_EXPECTED_RESULT ==
decryptedBits decryptedBits
); );
} }
};
}
*/