diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/mac/cmac/cmac.cpp | 21 | ||||
-rw-r--r-- | src/lib/modes/aead/siv/siv.cpp | 9 |
2 files changed, 17 insertions, 13 deletions
diff --git a/src/lib/mac/cmac/cmac.cpp b/src/lib/mac/cmac/cmac.cpp index 9e0a01853..18f7c151c 100644 --- a/src/lib/mac/cmac/cmac.cpp +++ b/src/lib/mac/cmac/cmac.cpp @@ -25,19 +25,21 @@ secure_vector<uint8_t> CMAC::poly_double(const secure_vector<uint8_t>& in) */ void CMAC::add_data(const uint8_t input[], size_t length) { + const size_t bs = output_length(); + buffer_insert(m_buffer, m_position, input, length); - if(m_position + length > output_length()) + if(m_position + length > bs) { - xor_buf(m_state, m_buffer, output_length()); + xor_buf(m_state, m_buffer, bs); m_cipher->encrypt(m_state); - input += (output_length() - m_position); - length -= (output_length() - m_position); - while(length > output_length()) + input += (bs - m_position); + length -= (bs - m_position); + while(length > bs) { - xor_buf(m_state, input, output_length()); + xor_buf(m_state, input, bs); m_cipher->encrypt(m_state); - input += output_length(); - length -= output_length(); + input += bs; + length -= bs; } copy_mem(m_buffer.data(), input, length); m_position = 0; @@ -64,8 +66,7 @@ void CMAC::final_result(uint8_t mac[]) m_cipher->encrypt(m_state); - for(size_t i = 0; i != output_length(); ++i) - mac[i] = m_state[i]; + copy_mem(mac, m_state.data(), output_length()); zeroise(m_state); zeroise(m_buffer); diff --git a/src/lib/modes/aead/siv/siv.cpp b/src/lib/modes/aead/siv/siv.cpp index df9a0ef37..3a960e0af 100644 --- a/src/lib/modes/aead/siv/siv.cpp +++ b/src/lib/modes/aead/siv/siv.cpp @@ -16,7 +16,7 @@ namespace Botan { SIV_Mode::SIV_Mode(BlockCipher* cipher) : m_name(cipher->name() + "/SIV"), - m_ctr(new CTR_BE(cipher->clone())), + m_ctr(new CTR_BE(cipher->clone(), 8)), m_mac(new CMAC(cipher)), m_bs(cipher->block_size()) { @@ -173,8 +173,11 @@ void SIV_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); - buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end()); - msg_buf().clear(); + if(msg_buf().size() > 0) + { + buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end()); + msg_buf().clear(); + } const size_t sz = buffer.size() - offset; |