aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/modes/mode_pad
diff options
context:
space:
mode:
authorRenĂ© Korthaus <[email protected]>2016-07-07 15:14:28 +0200
committerRenĂ© Korthaus <[email protected]>2016-07-11 10:43:04 +0200
commit5fb452e9045cf8179faca5c76e7fa8c0fcd815cc (patch)
tree6b6d11defac283f88dea540edb89e91257c709a1 /src/lib/modes/mode_pad
parent2b3f4270371d376e1500b68f4955548b659d2011 (diff)
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.
Diffstat (limited to 'src/lib/modes/mode_pad')
-rw-r--r--src/lib/modes/mode_pad/mode_pad.cpp4
-rw-r--r--src/lib/modes/mode_pad/mode_pad.h3
2 files changed, 5 insertions, 2 deletions
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<byte>& buffer,
{
const byte pad_value = static_cast<byte>(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);
}