diff options
author | René Korthaus <[email protected]> | 2016-11-14 21:00:33 +0100 |
---|---|---|
committer | René Korthaus <[email protected]> | 2016-11-14 21:00:33 +0100 |
commit | 45355e4bb88185ac53ed5bdb5c72c160b907e7d5 (patch) | |
tree | 94a43c8ef398bff2dbd03389743fe7dca9423e35 /src/lib/modes | |
parent | 7acbc219afdf72578bc158ac223f1147a6b43d6f (diff) |
Check all ESP padding bytes during unpad
Diffstat (limited to 'src/lib/modes')
-rw-r--r-- | src/lib/modes/mode_pad/mode_pad.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/lib/modes/mode_pad/mode_pad.cpp b/src/lib/modes/mode_pad/mode_pad.cpp index 6550edef2..d4ab914cc 100644 --- a/src/lib/modes/mode_pad/mode_pad.cpp +++ b/src/lib/modes/mode_pad/mode_pad.cpp @@ -145,23 +145,22 @@ void ESP_Padding::add_padding(secure_vector<byte>& buffer, */ size_t ESP_Padding::unpad(const byte block[], size_t size) const { - while(size) + byte last_byte = block[size-1]; + if(last_byte > size) { - if(block[size-1] == 0x01) - { - break; - } - if(block[size-1] == 0x00) + throw Decoding_Error(name()); + } + + size_t i = size - 1; + while(i > size - last_byte) + { + if(block[i-1] != block[i]-1) { throw Decoding_Error(name()); } - size--; + --i; } - if(!size) - { - throw Decoding_Error(name()); - } - return (size-1); + return i; } |