diff options
author | René Korthaus <[email protected]> | 2016-11-15 11:12:28 +0100 |
---|---|---|
committer | René Korthaus <[email protected]> | 2016-11-15 11:12:28 +0100 |
commit | 5d811c9d88f1be9caa384d85d5c56c1d90021864 (patch) | |
tree | b0f0f883bd08d1c58fa3804d856442263a8493d5 /src/lib/modes | |
parent | 45355e4bb88185ac53ed5bdb5c72c160b907e7d5 (diff) |
Check all padding bytes in ESP_Padding::unpad()
Diffstat (limited to 'src/lib/modes')
-rw-r--r-- | src/lib/modes/mode_pad/mode_pad.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/lib/modes/mode_pad/mode_pad.cpp b/src/lib/modes/mode_pad/mode_pad.cpp index d4ab914cc..eb4ae42be 100644 --- a/src/lib/modes/mode_pad/mode_pad.cpp +++ b/src/lib/modes/mode_pad/mode_pad.cpp @@ -145,22 +145,27 @@ void ESP_Padding::add_padding(secure_vector<byte>& buffer, */ size_t ESP_Padding::unpad(const byte block[], size_t size) const { - byte last_byte = block[size-1]; + const byte last_byte = block[size-1]; if(last_byte > size) { throw Decoding_Error(name()); } + // try to do this in const time by looping over the entire block + const size_t pad_pos = size - last_byte; size_t i = size - 1; - while(i > size - last_byte) + while(i) { if(block[i-1] != block[i]-1) { - throw Decoding_Error(name()); + if(i > pad_pos) + { + throw Decoding_Error(name()); + } } --i; } - return i; + return pad_pos; } |