aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/modes
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-05-26 11:53:31 +0000
committerlloyd <[email protected]>2014-05-26 11:53:31 +0000
commit91c8a2cbae4486f4988eda6ae5b7cb2497285346 (patch)
tree82276370964f2fc55253f0572e7f383612ffe74c /src/lib/modes
parentb9cd85a383b5a522a25d4d798e66d2921e2e1398 (diff)
Erroring on strict-overflow is a little too strict, GCC 4.9 is smart
Diffstat (limited to 'src/lib/modes')
-rw-r--r--src/lib/modes/cbc/cbc.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/lib/modes/cbc/cbc.cpp b/src/lib/modes/cbc/cbc.cpp
index 3095875f5..5fe5c8b17 100644
--- a/src/lib/modes/cbc/cbc.cpp
+++ b/src/lib/modes/cbc/cbc.cpp
@@ -99,15 +99,15 @@ void CBC_Encryption::update(secure_vector<byte>& buffer, size_t offset)
BOTAN_ASSERT(sz % BS == 0, "CBC input is full blocks");
const size_t blocks = sz / BS;
+ const byte* prev_block = state_ptr();
+
if(blocks)
{
- xor_buf(&buf[0], state_ptr(), BS);
- cipher().encrypt(&buf[0]);
-
- for(size_t i = 1; i != blocks; ++i)
+ for(size_t i = 0; i != blocks; ++i)
{
- xor_buf(&buf[BS*i], &buf[BS*(i-1)], BS);
+ xor_buf(&buf[BS*i], prev_block, BS);
cipher().encrypt(&buf[BS*i]);
+ prev_block = &buf[BS*i];
}
state().assign(&buf[BS*(blocks-1)], &buf[BS*blocks]);
@@ -267,6 +267,7 @@ void CTS_Decryption::finish(secure_vector<byte>& buffer, size_t offset)
if(sz % BS == 0)
{
// swap last two blocks
+
for(size_t i = 0; i != BS; ++i)
std::swap(buffer[buffer.size()-BS+i], buffer[buffer.size()-2*BS+i]);
@@ -283,21 +284,17 @@ void CTS_Decryption::finish(secure_vector<byte>& buffer, size_t offset)
update(buffer, offset);
cipher().decrypt(&last[0]);
+
xor_buf(&last[0], &last[BS], final_bytes - BS);
for(size_t i = 0; i != final_bytes - BS; ++i)
- {
- last[i] ^= last[i + BS];
- last[i + BS] ^= last[i];
- last[i] ^= last[i + BS];
- }
+ std::swap(last[i], last[i + BS]);
cipher().decrypt(&last[0]);
xor_buf(&last[0], state_ptr(), BS);
buffer += last;
}
-
}
}