aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2016-05-20 11:59:31 +0100
committerRichard van der Hoff <richard@matrix.org>2016-05-23 18:55:06 +0100
commit444ef1f70687c340ba1b0b2a22d6e63c734d5f9e (patch)
tree08e39a888a262acab58d2c0616a966a5e1034ca1 /src
parentc57b2b71c5a1314e79a0ee110ed9e1168a70b921 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/base64.cpp8
-rw-r--r--src/cipher.cpp33
-rw-r--r--src/crypto.cpp6
-rw-r--r--src/olm.cpp8
-rw-r--r--src/pickle.cpp12
-rw-r--r--src/ratchet.cpp14
-rw-r--r--src/session.cpp10
-rw-r--r--src/utility.cpp2
8 files changed, 47 insertions, 46 deletions
diff --git a/src/base64.cpp b/src/base64.cpp
index 920119e..bbfb210 100644
--- a/src/base64.cpp
+++ b/src/base64.cpp
@@ -138,13 +138,13 @@ std::uint8_t const * olm::decode_base64(
// implementations of base64.h
-size_t olm_encode_base64_length(
+size_t _olm_encode_base64_length(
size_t input_length
) {
return olm::encode_base64_length(input_length);
}
-size_t olm_encode_base64(
+size_t _olm_encode_base64(
uint8_t const * input, size_t input_length,
uint8_t * output
) {
@@ -152,13 +152,13 @@ size_t olm_encode_base64(
return r - output;
}
-size_t olm_decode_base64_length(
+size_t _olm_decode_base64_length(
size_t input_length
) {
return olm::decode_base64_length(input_length);
}
-size_t olm_decode_base64(
+size_t _olm_decode_base64(
uint8_t const * input, size_t input_length,
uint8_t * output
) {
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<const olm_cipher_aes_sha_256 *>(cipher);
+ auto *c = reinterpret_cast<const _olm_cipher_aes_sha_256 *>(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<const olm_cipher_aes_sha_256 *>(cipher);
+ auto *c = reinterpret_cast<const _olm_cipher_aes_sha_256 *>(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;
diff --git a/src/crypto.cpp b/src/crypto.cpp
index 175b323..4fa92f1 100644
--- a/src/crypto.cpp
+++ b/src/crypto.cpp
@@ -255,7 +255,7 @@ std::size_t olm::aes_decrypt_cbc(
}
-void crypto_sha256(
+void _olm_crypto_sha256(
std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output
) {
@@ -267,7 +267,7 @@ void crypto_sha256(
}
-void crypto_hmac_sha256(
+void _olm_crypto_hmac_sha256(
std::uint8_t const * key, std::size_t key_length,
std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output
@@ -283,7 +283,7 @@ void crypto_hmac_sha256(
}
-void crypto_hkdf_sha256(
+void _olm_crypto_hkdf_sha256(
std::uint8_t const * input, std::size_t input_length,
std::uint8_t const * salt, std::size_t salt_length,
std::uint8_t const * info, std::size_t info_length,
diff --git a/src/olm.cpp b/src/olm.cpp
index 9d84758..b34a1dc 100644
--- a/src/olm.cpp
+++ b/src/olm.cpp
@@ -59,11 +59,11 @@ static std::uint8_t const * from_c(void const * bytes) {
static const std::uint8_t CIPHER_KDF_INFO[] = "Pickle";
-const olm_cipher *get_pickle_cipher() {
- static olm_cipher *cipher = NULL;
- static olm_cipher_aes_sha_256 PICKLE_CIPHER;
+const _olm_cipher *get_pickle_cipher() {
+ static _olm_cipher *cipher = NULL;
+ static _olm_cipher_aes_sha_256 PICKLE_CIPHER;
if (!cipher) {
- cipher = olm_cipher_aes_sha_256_init(
+ cipher = _olm_cipher_aes_sha_256_init(
&PICKLE_CIPHER,
CIPHER_KDF_INFO, sizeof(CIPHER_KDF_INFO) - 1
);
diff --git a/src/pickle.cpp b/src/pickle.cpp
index 1158306..fc3e2b4 100644
--- a/src/pickle.cpp
+++ b/src/pickle.cpp
@@ -200,34 +200,34 @@ std::uint8_t const * olm::unpickle(
////// pickle.h implementations
-uint8_t * olm_pickle_uint32(uint8_t * pos, uint32_t value) {
+uint8_t * _olm_pickle_uint32(uint8_t * pos, uint32_t value) {
return olm::pickle(pos, value);
}
-uint8_t const * olm_unpickle_uint32(
+uint8_t const * _olm_unpickle_uint32(
uint8_t const * pos, uint8_t const * end,
uint32_t *value
) {
return olm::unpickle(pos, end, *value);
}
-uint8_t * olm_pickle_bool(uint8_t * pos, int value) {
+uint8_t * _olm_pickle_bool(uint8_t * pos, int value) {
return olm::pickle(pos, (bool)value);
}
-uint8_t const * olm_unpickle_bool(
+uint8_t const * _olm_unpickle_bool(
uint8_t const * pos, uint8_t const * end,
int *value
) {
return olm::unpickle(pos, end, *reinterpret_cast<bool *>(value));
}
-uint8_t * olm_pickle_bytes(uint8_t * pos, uint8_t const * bytes,
+uint8_t * _olm_pickle_bytes(uint8_t * pos, uint8_t const * bytes,
size_t bytes_length) {
return olm::pickle_bytes(pos, bytes, bytes_length);
}
-uint8_t const * olm_unpickle_bytes(uint8_t const * pos, uint8_t const * end,
+uint8_t const * _olm_unpickle_bytes(uint8_t const * pos, uint8_t const * end,
uint8_t * bytes, size_t bytes_length) {
return olm::unpickle_bytes(pos, end, bytes, bytes_length);
}
diff --git a/src/ratchet.cpp b/src/ratchet.cpp
index de46be4..abcc8a1 100644
--- a/src/ratchet.cpp
+++ b/src/ratchet.cpp
@@ -50,7 +50,7 @@ static void create_chain_key(
olm::SharedKey secret;
olm::curve25519_shared_secret(our_key, their_key, secret);
std::uint8_t derived_secrets[2 * olm::KEY_LENGTH];
- crypto_hkdf_sha256(
+ _olm_crypto_hkdf_sha256(
secret, sizeof(secret),
root_key, sizeof(root_key),
info.ratchet_info, info.ratchet_info_length,
@@ -70,7 +70,7 @@ static void advance_chain_key(
olm::ChainKey const & chain_key,
olm::ChainKey & new_chain_key
) {
- crypto_hmac_sha256(
+ _olm_crypto_hmac_sha256(
chain_key.key, sizeof(chain_key.key),
CHAIN_KEY_SEED, sizeof(CHAIN_KEY_SEED),
new_chain_key.key
@@ -84,7 +84,7 @@ static void create_message_keys(
olm::ChainKey const & chain_key,
olm::KdfInfo const & info,
olm::MessageKey & message_key) {
- crypto_hmac_sha256(
+ _olm_crypto_hmac_sha256(
chain_key.key, sizeof(chain_key.key),
MESSAGE_KEY_SEED, sizeof(MESSAGE_KEY_SEED),
message_key.key
@@ -94,7 +94,7 @@ static void create_message_keys(
static std::size_t verify_mac_and_decrypt(
- olm_cipher const *cipher,
+ _olm_cipher const *cipher,
olm::MessageKey const & message_key,
olm::MessageReader const & reader,
std::uint8_t * plaintext, std::size_t max_plaintext_length
@@ -184,7 +184,7 @@ static std::size_t verify_mac_and_decrypt_for_new_chain(
olm::Ratchet::Ratchet(
olm::KdfInfo const & kdf_info,
- olm_cipher const * ratchet_cipher
+ _olm_cipher const * ratchet_cipher
) : kdf_info(kdf_info),
ratchet_cipher(ratchet_cipher),
last_error(OlmErrorCode::OLM_SUCCESS) {
@@ -196,7 +196,7 @@ void olm::Ratchet::initialise_as_bob(
olm::Curve25519PublicKey const & their_ratchet_key
) {
std::uint8_t derived_secrets[2 * olm::KEY_LENGTH];
- crypto_hkdf_sha256(
+ _olm_crypto_hkdf_sha256(
shared_secret, shared_secret_length,
nullptr, 0,
kdf_info.root_info, kdf_info.root_info_length,
@@ -218,7 +218,7 @@ void olm::Ratchet::initialise_as_alice(
olm::Curve25519KeyPair const & our_ratchet_key
) {
std::uint8_t derived_secrets[2 * olm::KEY_LENGTH];
- crypto_hkdf_sha256(
+ _olm_crypto_hkdf_sha256(
shared_secret, shared_secret_length,
nullptr, 0,
kdf_info.root_info, kdf_info.root_info_length,
diff --git a/src/session.cpp b/src/session.cpp
index 0d9b58a..19b9f21 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -35,11 +35,11 @@ static const olm::KdfInfo OLM_KDF_INFO = {
RATCHET_KDF_INFO, sizeof(RATCHET_KDF_INFO) - 1
};
-const olm_cipher *get_cipher() {
- static olm_cipher *cipher;
- static olm_cipher_aes_sha_256 OLM_CIPHER;
+const _olm_cipher *get_cipher() {
+ static _olm_cipher *cipher;
+ static _olm_cipher_aes_sha_256 OLM_CIPHER;
if (!cipher) {
- cipher = olm_cipher_aes_sha_256_init(
+ cipher = _olm_cipher_aes_sha_256_init(
&OLM_CIPHER,
CIPHER_KDF_INFO, sizeof(CIPHER_KDF_INFO) - 1
);
@@ -216,7 +216,7 @@ std::size_t olm::Session::session_id(
pos = olm::store_array(pos, alice_identity_key.public_key);
pos = olm::store_array(pos, alice_base_key.public_key);
pos = olm::store_array(pos, bob_one_time_key.public_key);
- crypto_sha256(tmp, sizeof(tmp), id);
+ _olm_crypto_sha256(tmp, sizeof(tmp), id);
return session_id_length();
}
diff --git a/src/utility.cpp b/src/utility.cpp
index 2169e60..67029c9 100644
--- a/src/utility.cpp
+++ b/src/utility.cpp
@@ -35,7 +35,7 @@ size_t olm::Utility::sha256(
last_error = OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
return std::size_t(-1);
}
- crypto_sha256(input, input_length, output);
+ _olm_crypto_sha256(input, input_length, output);
return SHA256_OUTPUT_LENGTH;
}