From c0386f3ddfa5db09f98686912e23aa884afc15c2 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Fri, 23 Feb 2018 17:16:38 -0500 Subject: Test block ciphers with mis-aligned inputs --- src/tests/test_block.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/tests/test_block.cpp b/src/tests/test_block.cpp index a274b260b..78e828e17 100644 --- a/src/tests/test_block.cpp +++ b/src/tests/test_block.cpp @@ -111,10 +111,36 @@ class Block_Cipher_Tests final : public Text_Based_Test cipher->decrypt(buf); } - cipher->clear(); - result.test_eq(provider, "decrypt", buf, input); + // Now test misaligned buffers + const size_t blocks = input.size() / cipher->block_size(); + buf.resize(input.size() + 1); + std::memcpy(buf.data() + 1, input.data(), input.size()); + + for(size_t i = 0; i != iterations; ++i) + { + cipher->encrypt_n(buf.data() + 1, buf.data() + 1, blocks); + } + + result.test_eq(provider.c_str(), "encrypt", + buf.data() + 1, buf.size() - 1, + expected.data(), expected.size()); + + // always decrypt expected ciphertext vs what we produced above + std::memcpy(buf.data() + 1, expected.data(), expected.size()); + + for(size_t i = 0; i != iterations; ++i) + { + cipher->decrypt_n(buf.data() + 1, buf.data() + 1, blocks); + } + + result.test_eq(provider.c_str(), "decrypt", + buf.data() + 1, buf.size() - 1, + input.data(), input.size()); + + cipher->clear(); + try { std::vector block(cipher->block_size()); -- cgit v1.2.3