aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenĂ© Korthaus <[email protected]>2016-11-14 21:00:33 +0100
committerRenĂ© Korthaus <[email protected]>2016-11-14 21:00:33 +0100
commit45355e4bb88185ac53ed5bdb5c72c160b907e7d5 (patch)
tree94a43c8ef398bff2dbd03389743fe7dca9423e35
parent7acbc219afdf72578bc158ac223f1147a6b43d6f (diff)
Check all ESP padding bytes during unpad
-rw-r--r--src/lib/modes/mode_pad/mode_pad.cpp23
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;
}