diff options
author | Jack Lloyd <[email protected]> | 2018-02-23 17:16:38 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-02-23 17:16:38 -0500 |
commit | c0386f3ddfa5db09f98686912e23aa884afc15c2 (patch) | |
tree | 5d00dc6abdbef56539c27bce8b37e32c498599bf /src | |
parent | f0d6de271de6cdb482c504b756f9b2208ba424d5 (diff) |
Test block ciphers with mis-aligned inputs
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/test_block.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
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<uint8_t> block(cipher->block_size()); |