diff options
author | Richard van der Hoff <github@rvanderhoff.org.uk> | 2016-09-05 10:36:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-05 10:36:43 +0100 |
commit | 9d16d820890e7b301baa8b69694aaea19f9bfc7f (patch) | |
tree | 659be65eb1b131073bf9580292214b3fc24aa982 /src/cipher.cpp | |
parent | 0c3f527dfd46d3056d5b3690836c102f0e0adfb4 (diff) | |
parent | 39212987bdef8e16794e756e3c78b531be25b70a (diff) |
Merge pull request #13 from matrix-org/rav/split_out_key_lengths
Create new constants for key lengths, etc
Diffstat (limited to 'src/cipher.cpp')
-rw-r--r-- | src/cipher.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/cipher.cpp b/src/cipher.cpp index 8c3de92..8e3d7a5 100644 --- a/src/cipher.cpp +++ b/src/cipher.cpp @@ -17,11 +17,13 @@ #include "olm/memory.hh" #include <cstring> +const std::size_t HMAC_KEY_LENGTH = 32; + namespace { struct DerivedKeys { olm::Aes256Key aes_key; - std::uint8_t mac_key[olm::KEY_LENGTH]; + std::uint8_t mac_key[HMAC_KEY_LENGTH]; olm::Aes256Iv aes_iv; }; @@ -31,7 +33,9 @@ static void derive_keys( std::uint8_t const * key, std::size_t key_length, DerivedKeys & keys ) { - std::uint8_t derived_secrets[2 * olm::KEY_LENGTH + olm::IV_LENGTH]; + std::uint8_t derived_secrets[ + AES256_KEY_LENGTH + HMAC_KEY_LENGTH + AES256_IV_LENGTH + ]; _olm_crypto_hkdf_sha256( key, key_length, nullptr, 0, @@ -81,7 +85,7 @@ size_t aes_sha_256_cipher_encrypt( ); _olm_crypto_hmac_sha256( - keys.mac_key, olm::KEY_LENGTH, output, output_length - MAC_LENGTH, mac + keys.mac_key, HMAC_KEY_LENGTH, output, output_length - MAC_LENGTH, mac ); std::memcpy(output + output_length - MAC_LENGTH, mac, MAC_LENGTH); @@ -113,7 +117,7 @@ size_t aes_sha_256_cipher_decrypt( derive_keys(c->kdf_info, c->kdf_info_length, key, key_length, keys); _olm_crypto_hmac_sha256( - keys.mac_key, olm::KEY_LENGTH, input, input_length - MAC_LENGTH, mac + keys.mac_key, HMAC_KEY_LENGTH, input, input_length - MAC_LENGTH, mac ); std::uint8_t const * input_mac = input + input_length - MAC_LENGTH; |