From 444ef1f70687c340ba1b0b2a22d6e63c734d5f9e Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 20 May 2016 11:59:31 +0100 Subject: Prefix for internal symbols Give a load of internal symbols "_olm_" prefixes. This better delineates the public and private interfaces in the module, and helps avoid internal symbols leaking out and possibly being abused. --- src/cipher.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/cipher.cpp') diff --git a/src/cipher.cpp b/src/cipher.cpp index 8c56efa..73d6680 100644 --- a/src/cipher.cpp +++ b/src/cipher.cpp @@ -32,7 +32,7 @@ static void derive_keys( DerivedKeys & keys ) { std::uint8_t derived_secrets[2 * olm::KEY_LENGTH + olm::IV_LENGTH]; - crypto_hkdf_sha256( + _olm_crypto_hkdf_sha256( key, key_length, nullptr, 0, kdf_info, kdf_info_length, @@ -47,24 +47,24 @@ static void derive_keys( static const std::size_t MAC_LENGTH = 8; -size_t aes_sha_256_cipher_mac_length(const struct olm_cipher *cipher) { +size_t aes_sha_256_cipher_mac_length(const struct _olm_cipher *cipher) { return MAC_LENGTH; } size_t aes_sha_256_cipher_encrypt_ciphertext_length( - const struct olm_cipher *cipher, size_t plaintext_length + const struct _olm_cipher *cipher, size_t plaintext_length ) { return olm::aes_encrypt_cbc_length(plaintext_length); } size_t aes_sha_256_cipher_encrypt( - const struct olm_cipher *cipher, + const struct _olm_cipher *cipher, uint8_t const * key, size_t key_length, uint8_t const * plaintext, size_t plaintext_length, uint8_t * ciphertext, size_t ciphertext_length, uint8_t * output, size_t output_length ) { - auto *c = reinterpret_cast(cipher); + auto *c = reinterpret_cast(cipher); if (aes_sha_256_cipher_encrypt_ciphertext_length(cipher, plaintext_length) < ciphertext_length) { @@ -80,7 +80,7 @@ size_t aes_sha_256_cipher_encrypt( keys.aes_key, keys.aes_iv, plaintext, plaintext_length, ciphertext ); - crypto_hmac_sha256( + _olm_crypto_hmac_sha256( keys.mac_key, olm::KEY_LENGTH, output, output_length - MAC_LENGTH, mac ); @@ -92,27 +92,27 @@ size_t aes_sha_256_cipher_encrypt( size_t aes_sha_256_cipher_decrypt_max_plaintext_length( - const struct olm_cipher *cipher, + const struct _olm_cipher *cipher, size_t ciphertext_length ) { return ciphertext_length; } size_t aes_sha_256_cipher_decrypt( - const struct olm_cipher *cipher, + const struct _olm_cipher *cipher, uint8_t const * key, size_t key_length, uint8_t const * input, size_t input_length, uint8_t const * ciphertext, size_t ciphertext_length, uint8_t * plaintext, size_t max_plaintext_length ) { - auto *c = reinterpret_cast(cipher); + auto *c = reinterpret_cast(cipher); DerivedKeys keys; std::uint8_t mac[SHA256_OUTPUT_LENGTH]; derive_keys(c->kdf_info, c->kdf_info_length, key, key_length, keys); - crypto_hmac_sha256( + _olm_crypto_hmac_sha256( keys.mac_key, olm::KEY_LENGTH, input, input_length - MAC_LENGTH, mac ); @@ -131,11 +131,11 @@ size_t aes_sha_256_cipher_decrypt( } -void aes_sha_256_cipher_destruct(struct olm_cipher *cipher) { +void aes_sha_256_cipher_destruct(struct _olm_cipher *cipher) { } -const cipher_ops aes_sha_256_cipher_ops = { +const _olm_cipher_ops aes_sha_256_cipher_ops = { aes_sha_256_cipher_mac_length, aes_sha_256_cipher_encrypt_ciphertext_length, aes_sha_256_cipher_encrypt, @@ -147,10 +147,11 @@ const cipher_ops aes_sha_256_cipher_ops = { } // namespace -olm_cipher *olm_cipher_aes_sha_256_init(struct olm_cipher_aes_sha_256 *cipher, - uint8_t const * kdf_info, - size_t kdf_info_length) -{ +_olm_cipher *_olm_cipher_aes_sha_256_init( + struct _olm_cipher_aes_sha_256 *cipher, + uint8_t const * kdf_info, + size_t kdf_info_length +) { cipher->base_cipher.ops = &aes_sha_256_cipher_ops; cipher->kdf_info = kdf_info; cipher->kdf_info_length = kdf_info_length; -- cgit v1.2.3