diff options
author | Jack Lloyd <[email protected]> | 2015-08-04 22:06:44 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2015-08-04 22:06:44 -0400 |
commit | eddf0d75e60740017de20301bcf5dffef9dfbb95 (patch) | |
tree | d2e7bda33077e0433b3d1e97b7563056b0f8c3f5 /src | |
parent | 1c6c1bdf2a59af37c287c972b4f133ddecff4656 (diff) |
For CBC, ECB, and XTS the output length of a zero length input is well
defined, so don't fail. Fix XTS, as XTS always uses ciphertext
stealing the value of output_length had been incorrect in rounding up
to the block size.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/modes/cbc/cbc.cpp | 6 | ||||
-rw-r--r-- | src/lib/modes/ecb/ecb.cpp | 6 | ||||
-rw-r--r-- | src/lib/modes/xts/xts.cpp | 4 |
3 files changed, 9 insertions, 7 deletions
diff --git a/src/lib/modes/cbc/cbc.cpp b/src/lib/modes/cbc/cbc.cpp index dd6550fce..85241cf53 100644 --- a/src/lib/modes/cbc/cbc.cpp +++ b/src/lib/modes/cbc/cbc.cpp @@ -105,8 +105,10 @@ size_t CBC_Encryption::minimum_final_size() const size_t CBC_Encryption::output_length(size_t input_length) const { - BOTAN_ASSERT(input_length != 0, "CBC_Encryption::output_length() call"); - return round_up(input_length, cipher().block_size()); + if(input_length == 0) + return cipher().block_size(); + else + return round_up(input_length, cipher().block_size()); } void CBC_Encryption::update(secure_vector<byte>& buffer, size_t offset) diff --git a/src/lib/modes/ecb/ecb.cpp b/src/lib/modes/ecb/ecb.cpp index 6de00f18a..e5794d8e1 100644 --- a/src/lib/modes/ecb/ecb.cpp +++ b/src/lib/modes/ecb/ecb.cpp @@ -83,8 +83,10 @@ size_t ECB_Encryption::minimum_final_size() const size_t ECB_Encryption::output_length(size_t input_length) const { - BOTAN_ASSERT(input_length != 0, "ECB_Encryption::output_length() call"); - return round_up(input_length, cipher().block_size()); + if(input_length == 0) + return cipher().block_size(); + else + return round_up(input_length, cipher().block_size()); } void ECB_Encryption::update(secure_vector<byte>& buffer, size_t offset) diff --git a/src/lib/modes/xts/xts.cpp b/src/lib/modes/xts/xts.cpp index 4eaf03fe5..046de216f 100644 --- a/src/lib/modes/xts/xts.cpp +++ b/src/lib/modes/xts/xts.cpp @@ -135,8 +135,7 @@ void XTS_Mode::update_tweak(size_t which) size_t XTS_Encryption::output_length(size_t input_length) const { - BOTAN_ASSERT(input_length != 0, "XTS_Encryption::output_length() call"); - return round_up(input_length, cipher().block_size()); + return input_length; } void XTS_Encryption::update(secure_vector<byte>& buffer, size_t offset) @@ -214,7 +213,6 @@ void XTS_Encryption::finish(secure_vector<byte>& buffer, size_t offset) size_t XTS_Decryption::output_length(size_t input_length) const { - // might be less return input_length; } |