From 5fb452e9045cf8179faca5c76e7fa8c0fcd815cc Mon Sep 17 00:00:00 2001 From: René Korthaus Date: Thu, 7 Jul 2016 15:14:28 +0200 Subject: Add test vectors for block cipher padding modes Exports get_bc_pad() to be used from tests. Adds separate handcrafted tests for block cipher padding modes. They were previously only tested implicitly during the block cipher modes of operation tests, though not all padding modes were covered. And in case a mode of operation is not part of the enabled modules, the previously tested padding modes are not covered at all. Fixes an off-by-one bug in the previously untested ANSI X9.23 padding mode, where the number of zero bytes in the pad was one more than allowed by the standard. --- src/lib/modes/mode_pad/mode_pad.cpp | 4 +++- src/lib/modes/mode_pad/mode_pad.h | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/lib/modes/mode_pad') diff --git a/src/lib/modes/mode_pad/mode_pad.cpp b/src/lib/modes/mode_pad/mode_pad.cpp index 0f1df9e8a..7b4546c86 100644 --- a/src/lib/modes/mode_pad/mode_pad.cpp +++ b/src/lib/modes/mode_pad/mode_pad.cpp @@ -69,8 +69,10 @@ void ANSI_X923_Padding::add_padding(secure_vector& buffer, { const byte pad_value = static_cast(block_size - last_byte_pos); - for(size_t i = last_byte_pos; i < block_size; ++i) + for(size_t i = last_byte_pos; i < block_size-1; ++i) + { buffer.push_back(0); + } buffer.push_back(pad_value); } diff --git a/src/lib/modes/mode_pad/mode_pad.h b/src/lib/modes/mode_pad/mode_pad.h index 0a775b1ea..bc2b7c132 100644 --- a/src/lib/modes/mode_pad/mode_pad.h +++ b/src/lib/modes/mode_pad/mode_pad.h @@ -32,6 +32,7 @@ class BOTAN_DLL BlockCipherModePaddingMethod /** * @param block the last block * @param size the of the block + * @return number of padding bytes */ virtual size_t unpad(const byte block[], size_t size) const = 0; @@ -119,7 +120,7 @@ class BOTAN_DLL Null_Padding final : public BlockCipherModePaddingMethod std::string name() const override { return "NoPadding"; } }; -BlockCipherModePaddingMethod* get_bc_pad(const std::string& algo_spec); +BOTAN_DLL BlockCipherModePaddingMethod* get_bc_pad(const std::string& algo_spec); } -- cgit v1.2.3