diff options
author | Mark Haines <mark.haines@matrix.org> | 2015-06-16 15:15:40 +0100 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2015-06-16 15:15:40 +0100 |
commit | 76f49cf17780c155dd02d39ebc40e1f62c0c2503 (patch) | |
tree | e4194d0feca2ac165ee8335af9155c981c1bbb0b /src/crypto.cpp | |
parent | 11861404e444795a5437dcf193e71f68a96b5a59 (diff) |
Add a test for the axolotl API
Diffstat (limited to 'src/crypto.cpp')
-rw-r--r-- | src/crypto.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/crypto.cpp b/src/crypto.cpp index 24a8136..b287919 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -237,15 +237,18 @@ std::size_t axolotl::aes_decrypt_cbc( ) { std::uint32_t key_schedule[60]; ::aes_key_setup(key.key, key_schedule, 256); + std::uint8_t block1[AES_BLOCK_LENGTH]; + std::uint8_t block2[AES_BLOCK_LENGTH]; + std::memcpy(block1, iv.iv, AES_BLOCK_LENGTH); for (std::size_t i = 0; i < input_length; i += AES_BLOCK_LENGTH) { + std::memcpy(block2, &input[i], AES_BLOCK_LENGTH); ::aes_decrypt(&input[i], &output[i], key_schedule, 256); - if (i == 0) { - xor_block<AES_BLOCK_LENGTH>(&output[i], iv.iv); - } else { - xor_block<AES_BLOCK_LENGTH>(&output[i], &input[i - AES_BLOCK_LENGTH]); - } + xor_block<AES_BLOCK_LENGTH>(&output[i], block1); + std::memcpy(block1, block2, AES_BLOCK_LENGTH); } axolotl::unset(key_schedule); + axolotl::unset(block1); + axolotl::unset(block2); std::size_t padding = output[input_length - 1]; return (padding > input_length) ? std::size_t(-1) : (input_length - padding); } |