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.
This commit is contained in:
parent
c57b2b71c5
commit
444ef1f706
16 changed files with 93 additions and 90 deletions
|
@ -30,7 +30,7 @@ extern "C" {
|
||||||
/**
|
/**
|
||||||
* The number of bytes of unpadded base64 needed to encode a length of input.
|
* The number of bytes of unpadded base64 needed to encode a length of input.
|
||||||
*/
|
*/
|
||||||
size_t olm_encode_base64_length(
|
size_t _olm_encode_base64_length(
|
||||||
size_t input_length
|
size_t input_length
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ size_t olm_encode_base64_length(
|
||||||
*
|
*
|
||||||
* Returns number of bytes encoded
|
* Returns number of bytes encoded
|
||||||
*/
|
*/
|
||||||
size_t olm_encode_base64(
|
size_t _olm_encode_base64(
|
||||||
uint8_t const * input, size_t input_length,
|
uint8_t const * input, size_t input_length,
|
||||||
uint8_t * output
|
uint8_t * output
|
||||||
);
|
);
|
||||||
|
@ -51,7 +51,7 @@ size_t olm_encode_base64(
|
||||||
* The number of bytes of raw data a length of unpadded base64 will encode to.
|
* The number of bytes of raw data a length of unpadded base64 will encode to.
|
||||||
* Returns size_t(-1) if the length is not a valid length for base64.
|
* Returns size_t(-1) if the length is not a valid length for base64.
|
||||||
*/
|
*/
|
||||||
size_t olm_decode_base64_length(
|
size_t _olm_decode_base64_length(
|
||||||
size_t input_length
|
size_t input_length
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ size_t olm_decode_base64_length(
|
||||||
*
|
*
|
||||||
* Returns number of bytes decoded
|
* Returns number of bytes decoded
|
||||||
*/
|
*/
|
||||||
size_t olm_decode_base64(
|
size_t _olm_decode_base64(
|
||||||
uint8_t const * input, size_t input_length,
|
uint8_t const * input, size_t input_length,
|
||||||
uint8_t * output
|
uint8_t * output
|
||||||
);
|
);
|
||||||
|
|
|
@ -23,20 +23,22 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct olm_cipher;
|
struct _olm_cipher;
|
||||||
|
|
||||||
struct cipher_ops {
|
struct _olm_cipher_ops {
|
||||||
/**
|
/**
|
||||||
* Returns the length of the message authentication code that will be
|
* Returns the length of the message authentication code that will be
|
||||||
* appended to the output.
|
* appended to the output.
|
||||||
*/
|
*/
|
||||||
size_t (*mac_length)(const struct olm_cipher *cipher);
|
size_t (*mac_length)(const struct _olm_cipher *cipher);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the length of cipher-text for a given length of plain-text.
|
* Returns the length of cipher-text for a given length of plain-text.
|
||||||
*/
|
*/
|
||||||
size_t (*encrypt_ciphertext_length)(const struct olm_cipher *cipher,
|
size_t (*encrypt_ciphertext_length)(
|
||||||
size_t plaintext_length);
|
const struct _olm_cipher *cipher,
|
||||||
|
size_t plaintext_length
|
||||||
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Encrypts the plain-text into the output buffer and authenticates the
|
* Encrypts the plain-text into the output buffer and authenticates the
|
||||||
|
@ -53,7 +55,7 @@ struct cipher_ops {
|
||||||
* buffer is too small. Otherwise returns the length of the output buffer.
|
* buffer is too small. Otherwise returns the length of the output buffer.
|
||||||
*/
|
*/
|
||||||
size_t (*encrypt)(
|
size_t (*encrypt)(
|
||||||
const struct olm_cipher *cipher,
|
const struct _olm_cipher *cipher,
|
||||||
uint8_t const * key, size_t key_length,
|
uint8_t const * key, size_t key_length,
|
||||||
uint8_t const * plaintext, size_t plaintext_length,
|
uint8_t const * plaintext, size_t plaintext_length,
|
||||||
uint8_t * ciphertext, size_t ciphertext_length,
|
uint8_t * ciphertext, size_t ciphertext_length,
|
||||||
|
@ -65,7 +67,7 @@ struct cipher_ops {
|
||||||
* cipher-text can contain.
|
* cipher-text can contain.
|
||||||
*/
|
*/
|
||||||
size_t (*decrypt_max_plaintext_length)(
|
size_t (*decrypt_max_plaintext_length)(
|
||||||
const struct olm_cipher *cipher,
|
const struct _olm_cipher *cipher,
|
||||||
size_t ciphertext_length
|
size_t ciphertext_length
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -84,7 +86,7 @@ struct cipher_ops {
|
||||||
* of the plain text.
|
* of the plain text.
|
||||||
*/
|
*/
|
||||||
size_t (*decrypt)(
|
size_t (*decrypt)(
|
||||||
const struct olm_cipher *cipher,
|
const struct _olm_cipher *cipher,
|
||||||
uint8_t const * key, size_t key_length,
|
uint8_t const * key, size_t key_length,
|
||||||
uint8_t const * input, size_t input_length,
|
uint8_t const * input, size_t input_length,
|
||||||
uint8_t const * ciphertext, size_t ciphertext_length,
|
uint8_t const * ciphertext, size_t ciphertext_length,
|
||||||
|
@ -92,16 +94,16 @@ struct cipher_ops {
|
||||||
);
|
);
|
||||||
|
|
||||||
/** destroy any private data associated with this cipher */
|
/** destroy any private data associated with this cipher */
|
||||||
void (*destruct)(struct olm_cipher *cipher);
|
void (*destruct)(struct _olm_cipher *cipher);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct olm_cipher {
|
struct _olm_cipher {
|
||||||
const struct cipher_ops *ops;
|
const struct _olm_cipher_ops *ops;
|
||||||
/* cipher-specific fields follow */
|
/* cipher-specific fields follow */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct olm_cipher_aes_sha_256 {
|
struct _olm_cipher_aes_sha_256 {
|
||||||
struct olm_cipher base_cipher;
|
struct _olm_cipher base_cipher;
|
||||||
|
|
||||||
uint8_t const * kdf_info;
|
uint8_t const * kdf_info;
|
||||||
size_t kdf_info_length;
|
size_t kdf_info_length;
|
||||||
|
@ -121,8 +123,8 @@ struct olm_cipher_aes_sha_256 {
|
||||||
*
|
*
|
||||||
* kdf_info_length: length of context string kdf_info
|
* kdf_info_length: length of context string kdf_info
|
||||||
*/
|
*/
|
||||||
struct olm_cipher *olm_cipher_aes_sha_256_init(
|
struct _olm_cipher *_olm_cipher_aes_sha_256_init(
|
||||||
struct olm_cipher_aes_sha_256 *cipher,
|
struct _olm_cipher_aes_sha_256 *cipher,
|
||||||
uint8_t const * kdf_info,
|
uint8_t const * kdf_info,
|
||||||
size_t kdf_info_length);
|
size_t kdf_info_length);
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ const size_t SHA256_OUTPUT_LENGTH = 32;
|
||||||
|
|
||||||
/** Computes SHA-256 of the input. The output buffer must be a least 32
|
/** Computes SHA-256 of the input. The output buffer must be a least 32
|
||||||
* bytes long. */
|
* bytes long. */
|
||||||
void crypto_sha256(
|
void _olm_crypto_sha256(
|
||||||
uint8_t const * input, size_t input_length,
|
uint8_t const * input, size_t input_length,
|
||||||
uint8_t * output
|
uint8_t * output
|
||||||
);
|
);
|
||||||
|
@ -40,7 +40,7 @@ void crypto_sha256(
|
||||||
* http://tools.ietf.org/html/rfc2104
|
* http://tools.ietf.org/html/rfc2104
|
||||||
* Computes HMAC-SHA-256 of the input for the key. The output buffer must
|
* Computes HMAC-SHA-256 of the input for the key. The output buffer must
|
||||||
* be at least 32 bytes long. */
|
* be at least 32 bytes long. */
|
||||||
void crypto_hmac_sha256(
|
void _olm_crypto_hmac_sha256(
|
||||||
uint8_t const * key, size_t key_length,
|
uint8_t const * key, size_t key_length,
|
||||||
uint8_t const * input, size_t input_length,
|
uint8_t const * input, size_t input_length,
|
||||||
uint8_t * output
|
uint8_t * output
|
||||||
|
@ -50,7 +50,7 @@ void crypto_hmac_sha256(
|
||||||
/** HMAC-based Key Derivation Function (HKDF)
|
/** HMAC-based Key Derivation Function (HKDF)
|
||||||
* https://tools.ietf.org/html/rfc5869
|
* https://tools.ietf.org/html/rfc5869
|
||||||
* Derives key material from the input bytes. */
|
* Derives key material from the input bytes. */
|
||||||
void crypto_hkdf_sha256(
|
void _olm_crypto_hkdf_sha256(
|
||||||
uint8_t const * input, size_t input_length,
|
uint8_t const * input, size_t input_length,
|
||||||
uint8_t const * info, size_t info_length,
|
uint8_t const * info, size_t info_length,
|
||||||
uint8_t const * salt, size_t salt_length,
|
uint8_t const * salt, size_t salt_length,
|
||||||
|
|
|
@ -21,25 +21,25 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define olm_pickle_uint32_length(value) 4
|
#define _olm_pickle_uint32_length(value) 4
|
||||||
uint8_t * olm_pickle_uint32(uint8_t * pos, uint32_t value);
|
uint8_t * _olm_pickle_uint32(uint8_t * pos, uint32_t value);
|
||||||
uint8_t const * olm_unpickle_uint32(
|
uint8_t const * _olm_unpickle_uint32(
|
||||||
uint8_t const * pos, uint8_t const * end,
|
uint8_t const * pos, uint8_t const * end,
|
||||||
uint32_t *value
|
uint32_t *value
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
#define olm_pickle_bool_length(value) 1
|
#define _olm_pickle_bool_length(value) 1
|
||||||
uint8_t * olm_pickle_bool(uint8_t * pos, int value);
|
uint8_t * _olm_pickle_bool(uint8_t * pos, int value);
|
||||||
uint8_t const * olm_unpickle_bool(
|
uint8_t const * _olm_unpickle_bool(
|
||||||
uint8_t const * pos, uint8_t const * end,
|
uint8_t const * pos, uint8_t const * end,
|
||||||
int *value
|
int *value
|
||||||
);
|
);
|
||||||
|
|
||||||
#define olm_pickle_bytes_length(bytes, bytes_length) (bytes_length)
|
#define _olm_pickle_bytes_length(bytes, bytes_length) (bytes_length)
|
||||||
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);
|
size_t 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);
|
uint8_t * bytes, size_t bytes_length);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "olm/list.hh"
|
#include "olm/list.hh"
|
||||||
#include "olm/error.h"
|
#include "olm/error.h"
|
||||||
|
|
||||||
struct olm_cipher;
|
struct _olm_cipher;
|
||||||
|
|
||||||
namespace olm {
|
namespace olm {
|
||||||
|
|
||||||
|
@ -69,14 +69,14 @@ struct Ratchet {
|
||||||
|
|
||||||
Ratchet(
|
Ratchet(
|
||||||
KdfInfo const & kdf_info,
|
KdfInfo const & kdf_info,
|
||||||
olm_cipher const *ratchet_cipher
|
_olm_cipher const *ratchet_cipher
|
||||||
);
|
);
|
||||||
|
|
||||||
/** A some strings identifying the application to feed into the KDF. */
|
/** A some strings identifying the application to feed into the KDF. */
|
||||||
KdfInfo const & kdf_info;
|
KdfInfo const & kdf_info;
|
||||||
|
|
||||||
/** The AEAD cipher to use for encrypting messages. */
|
/** The AEAD cipher to use for encrypting messages. */
|
||||||
olm_cipher const *ratchet_cipher;
|
_olm_cipher const *ratchet_cipher;
|
||||||
|
|
||||||
/** The last error that happened encrypting or decrypting a message. */
|
/** The last error that happened encrypting or decrypting a message. */
|
||||||
OlmErrorCode last_error;
|
OlmErrorCode last_error;
|
||||||
|
|
|
@ -138,13 +138,13 @@ std::uint8_t const * olm::decode_base64(
|
||||||
|
|
||||||
// implementations of base64.h
|
// implementations of base64.h
|
||||||
|
|
||||||
size_t olm_encode_base64_length(
|
size_t _olm_encode_base64_length(
|
||||||
size_t input_length
|
size_t input_length
|
||||||
) {
|
) {
|
||||||
return olm::encode_base64_length(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 const * input, size_t input_length,
|
||||||
uint8_t * output
|
uint8_t * output
|
||||||
) {
|
) {
|
||||||
|
@ -152,13 +152,13 @@ size_t olm_encode_base64(
|
||||||
return r - output;
|
return r - output;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t olm_decode_base64_length(
|
size_t _olm_decode_base64_length(
|
||||||
size_t input_length
|
size_t input_length
|
||||||
) {
|
) {
|
||||||
return olm::decode_base64_length(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 const * input, size_t input_length,
|
||||||
uint8_t * output
|
uint8_t * output
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ static void derive_keys(
|
||||||
DerivedKeys & keys
|
DerivedKeys & keys
|
||||||
) {
|
) {
|
||||||
std::uint8_t derived_secrets[2 * olm::KEY_LENGTH + olm::IV_LENGTH];
|
std::uint8_t derived_secrets[2 * olm::KEY_LENGTH + olm::IV_LENGTH];
|
||||||
crypto_hkdf_sha256(
|
_olm_crypto_hkdf_sha256(
|
||||||
key, key_length,
|
key, key_length,
|
||||||
nullptr, 0,
|
nullptr, 0,
|
||||||
kdf_info, kdf_info_length,
|
kdf_info, kdf_info_length,
|
||||||
|
@ -47,24 +47,24 @@ static void derive_keys(
|
||||||
|
|
||||||
static const std::size_t MAC_LENGTH = 8;
|
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;
|
return MAC_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t aes_sha_256_cipher_encrypt_ciphertext_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);
|
return olm::aes_encrypt_cbc_length(plaintext_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t aes_sha_256_cipher_encrypt(
|
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 * key, size_t key_length,
|
||||||
uint8_t const * plaintext, size_t plaintext_length,
|
uint8_t const * plaintext, size_t plaintext_length,
|
||||||
uint8_t * ciphertext, size_t ciphertext_length,
|
uint8_t * ciphertext, size_t ciphertext_length,
|
||||||
uint8_t * output, size_t output_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)
|
if (aes_sha_256_cipher_encrypt_ciphertext_length(cipher, plaintext_length)
|
||||||
< ciphertext_length) {
|
< ciphertext_length) {
|
||||||
|
@ -80,7 +80,7 @@ size_t aes_sha_256_cipher_encrypt(
|
||||||
keys.aes_key, keys.aes_iv, plaintext, plaintext_length, ciphertext
|
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
|
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(
|
size_t aes_sha_256_cipher_decrypt_max_plaintext_length(
|
||||||
const struct olm_cipher *cipher,
|
const struct _olm_cipher *cipher,
|
||||||
size_t ciphertext_length
|
size_t ciphertext_length
|
||||||
) {
|
) {
|
||||||
return ciphertext_length;
|
return ciphertext_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t aes_sha_256_cipher_decrypt(
|
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 * key, size_t key_length,
|
||||||
uint8_t const * input, size_t input_length,
|
uint8_t const * input, size_t input_length,
|
||||||
uint8_t const * ciphertext, size_t ciphertext_length,
|
uint8_t const * ciphertext, size_t ciphertext_length,
|
||||||
uint8_t * plaintext, size_t max_plaintext_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;
|
DerivedKeys keys;
|
||||||
std::uint8_t mac[SHA256_OUTPUT_LENGTH];
|
std::uint8_t mac[SHA256_OUTPUT_LENGTH];
|
||||||
|
|
||||||
derive_keys(c->kdf_info, c->kdf_info_length, key, key_length, keys);
|
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
|
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_mac_length,
|
||||||
aes_sha_256_cipher_encrypt_ciphertext_length,
|
aes_sha_256_cipher_encrypt_ciphertext_length,
|
||||||
aes_sha_256_cipher_encrypt,
|
aes_sha_256_cipher_encrypt,
|
||||||
|
@ -147,10 +147,11 @@ const cipher_ops aes_sha_256_cipher_ops = {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
olm_cipher *olm_cipher_aes_sha_256_init(struct olm_cipher_aes_sha_256 *cipher,
|
_olm_cipher *_olm_cipher_aes_sha_256_init(
|
||||||
uint8_t const * kdf_info,
|
struct _olm_cipher_aes_sha_256 *cipher,
|
||||||
size_t kdf_info_length)
|
uint8_t const * kdf_info,
|
||||||
{
|
size_t kdf_info_length
|
||||||
|
) {
|
||||||
cipher->base_cipher.ops = &aes_sha_256_cipher_ops;
|
cipher->base_cipher.ops = &aes_sha_256_cipher_ops;
|
||||||
cipher->kdf_info = kdf_info;
|
cipher->kdf_info = kdf_info;
|
||||||
cipher->kdf_info_length = kdf_info_length;
|
cipher->kdf_info_length = kdf_info_length;
|
||||||
|
|
|
@ -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 const * input, std::size_t input_length,
|
||||||
std::uint8_t * output
|
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 * key, std::size_t key_length,
|
||||||
std::uint8_t const * input, std::size_t input_length,
|
std::uint8_t const * input, std::size_t input_length,
|
||||||
std::uint8_t * output
|
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 * input, std::size_t input_length,
|
||||||
std::uint8_t const * salt, std::size_t salt_length,
|
std::uint8_t const * salt, std::size_t salt_length,
|
||||||
std::uint8_t const * info, std::size_t info_length,
|
std::uint8_t const * info, std::size_t info_length,
|
||||||
|
|
|
@ -59,11 +59,11 @@ static std::uint8_t const * from_c(void const * bytes) {
|
||||||
|
|
||||||
static const std::uint8_t CIPHER_KDF_INFO[] = "Pickle";
|
static const std::uint8_t CIPHER_KDF_INFO[] = "Pickle";
|
||||||
|
|
||||||
const olm_cipher *get_pickle_cipher() {
|
const _olm_cipher *get_pickle_cipher() {
|
||||||
static olm_cipher *cipher = NULL;
|
static _olm_cipher *cipher = NULL;
|
||||||
static olm_cipher_aes_sha_256 PICKLE_CIPHER;
|
static _olm_cipher_aes_sha_256 PICKLE_CIPHER;
|
||||||
if (!cipher) {
|
if (!cipher) {
|
||||||
cipher = olm_cipher_aes_sha_256_init(
|
cipher = _olm_cipher_aes_sha_256_init(
|
||||||
&PICKLE_CIPHER,
|
&PICKLE_CIPHER,
|
||||||
CIPHER_KDF_INFO, sizeof(CIPHER_KDF_INFO) - 1
|
CIPHER_KDF_INFO, sizeof(CIPHER_KDF_INFO) - 1
|
||||||
);
|
);
|
||||||
|
|
|
@ -200,34 +200,34 @@ std::uint8_t const * olm::unpickle(
|
||||||
|
|
||||||
////// pickle.h implementations
|
////// 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);
|
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,
|
uint8_t const * pos, uint8_t const * end,
|
||||||
uint32_t *value
|
uint32_t *value
|
||||||
) {
|
) {
|
||||||
return olm::unpickle(pos, end, *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);
|
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,
|
uint8_t const * pos, uint8_t const * end,
|
||||||
int *value
|
int *value
|
||||||
) {
|
) {
|
||||||
return olm::unpickle(pos, end, *reinterpret_cast<bool *>(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) {
|
size_t bytes_length) {
|
||||||
return olm::pickle_bytes(pos, bytes, 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) {
|
uint8_t * bytes, size_t bytes_length) {
|
||||||
return olm::unpickle_bytes(pos, end, bytes, bytes_length);
|
return olm::unpickle_bytes(pos, end, bytes, bytes_length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ static void create_chain_key(
|
||||||
olm::SharedKey secret;
|
olm::SharedKey secret;
|
||||||
olm::curve25519_shared_secret(our_key, their_key, secret);
|
olm::curve25519_shared_secret(our_key, their_key, secret);
|
||||||
std::uint8_t derived_secrets[2 * olm::KEY_LENGTH];
|
std::uint8_t derived_secrets[2 * olm::KEY_LENGTH];
|
||||||
crypto_hkdf_sha256(
|
_olm_crypto_hkdf_sha256(
|
||||||
secret, sizeof(secret),
|
secret, sizeof(secret),
|
||||||
root_key, sizeof(root_key),
|
root_key, sizeof(root_key),
|
||||||
info.ratchet_info, info.ratchet_info_length,
|
info.ratchet_info, info.ratchet_info_length,
|
||||||
|
@ -70,7 +70,7 @@ static void advance_chain_key(
|
||||||
olm::ChainKey const & chain_key,
|
olm::ChainKey const & chain_key,
|
||||||
olm::ChainKey & new_chain_key
|
olm::ChainKey & new_chain_key
|
||||||
) {
|
) {
|
||||||
crypto_hmac_sha256(
|
_olm_crypto_hmac_sha256(
|
||||||
chain_key.key, sizeof(chain_key.key),
|
chain_key.key, sizeof(chain_key.key),
|
||||||
CHAIN_KEY_SEED, sizeof(CHAIN_KEY_SEED),
|
CHAIN_KEY_SEED, sizeof(CHAIN_KEY_SEED),
|
||||||
new_chain_key.key
|
new_chain_key.key
|
||||||
|
@ -84,7 +84,7 @@ static void create_message_keys(
|
||||||
olm::ChainKey const & chain_key,
|
olm::ChainKey const & chain_key,
|
||||||
olm::KdfInfo const & info,
|
olm::KdfInfo const & info,
|
||||||
olm::MessageKey & message_key) {
|
olm::MessageKey & message_key) {
|
||||||
crypto_hmac_sha256(
|
_olm_crypto_hmac_sha256(
|
||||||
chain_key.key, sizeof(chain_key.key),
|
chain_key.key, sizeof(chain_key.key),
|
||||||
MESSAGE_KEY_SEED, sizeof(MESSAGE_KEY_SEED),
|
MESSAGE_KEY_SEED, sizeof(MESSAGE_KEY_SEED),
|
||||||
message_key.key
|
message_key.key
|
||||||
|
@ -94,7 +94,7 @@ static void create_message_keys(
|
||||||
|
|
||||||
|
|
||||||
static std::size_t verify_mac_and_decrypt(
|
static std::size_t verify_mac_and_decrypt(
|
||||||
olm_cipher const *cipher,
|
_olm_cipher const *cipher,
|
||||||
olm::MessageKey const & message_key,
|
olm::MessageKey const & message_key,
|
||||||
olm::MessageReader const & reader,
|
olm::MessageReader const & reader,
|
||||||
std::uint8_t * plaintext, std::size_t max_plaintext_length
|
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::Ratchet::Ratchet(
|
||||||
olm::KdfInfo const & kdf_info,
|
olm::KdfInfo const & kdf_info,
|
||||||
olm_cipher const * ratchet_cipher
|
_olm_cipher const * ratchet_cipher
|
||||||
) : kdf_info(kdf_info),
|
) : kdf_info(kdf_info),
|
||||||
ratchet_cipher(ratchet_cipher),
|
ratchet_cipher(ratchet_cipher),
|
||||||
last_error(OlmErrorCode::OLM_SUCCESS) {
|
last_error(OlmErrorCode::OLM_SUCCESS) {
|
||||||
|
@ -196,7 +196,7 @@ void olm::Ratchet::initialise_as_bob(
|
||||||
olm::Curve25519PublicKey const & their_ratchet_key
|
olm::Curve25519PublicKey const & their_ratchet_key
|
||||||
) {
|
) {
|
||||||
std::uint8_t derived_secrets[2 * olm::KEY_LENGTH];
|
std::uint8_t derived_secrets[2 * olm::KEY_LENGTH];
|
||||||
crypto_hkdf_sha256(
|
_olm_crypto_hkdf_sha256(
|
||||||
shared_secret, shared_secret_length,
|
shared_secret, shared_secret_length,
|
||||||
nullptr, 0,
|
nullptr, 0,
|
||||||
kdf_info.root_info, kdf_info.root_info_length,
|
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
|
olm::Curve25519KeyPair const & our_ratchet_key
|
||||||
) {
|
) {
|
||||||
std::uint8_t derived_secrets[2 * olm::KEY_LENGTH];
|
std::uint8_t derived_secrets[2 * olm::KEY_LENGTH];
|
||||||
crypto_hkdf_sha256(
|
_olm_crypto_hkdf_sha256(
|
||||||
shared_secret, shared_secret_length,
|
shared_secret, shared_secret_length,
|
||||||
nullptr, 0,
|
nullptr, 0,
|
||||||
kdf_info.root_info, kdf_info.root_info_length,
|
kdf_info.root_info, kdf_info.root_info_length,
|
||||||
|
|
|
@ -35,11 +35,11 @@ static const olm::KdfInfo OLM_KDF_INFO = {
|
||||||
RATCHET_KDF_INFO, sizeof(RATCHET_KDF_INFO) - 1
|
RATCHET_KDF_INFO, sizeof(RATCHET_KDF_INFO) - 1
|
||||||
};
|
};
|
||||||
|
|
||||||
const olm_cipher *get_cipher() {
|
const _olm_cipher *get_cipher() {
|
||||||
static olm_cipher *cipher;
|
static _olm_cipher *cipher;
|
||||||
static olm_cipher_aes_sha_256 OLM_CIPHER;
|
static _olm_cipher_aes_sha_256 OLM_CIPHER;
|
||||||
if (!cipher) {
|
if (!cipher) {
|
||||||
cipher = olm_cipher_aes_sha_256_init(
|
cipher = _olm_cipher_aes_sha_256_init(
|
||||||
&OLM_CIPHER,
|
&OLM_CIPHER,
|
||||||
CIPHER_KDF_INFO, sizeof(CIPHER_KDF_INFO) - 1
|
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_identity_key.public_key);
|
||||||
pos = olm::store_array(pos, alice_base_key.public_key);
|
pos = olm::store_array(pos, alice_base_key.public_key);
|
||||||
pos = olm::store_array(pos, bob_one_time_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();
|
return session_id_length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ size_t olm::Utility::sha256(
|
||||||
last_error = OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
|
last_error = OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
|
||||||
return std::size_t(-1);
|
return std::size_t(-1);
|
||||||
}
|
}
|
||||||
crypto_sha256(input, input_length, output);
|
_olm_crypto_sha256(input, input_length, output);
|
||||||
return SHA256_OUTPUT_LENGTH;
|
return SHA256_OUTPUT_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,11 @@ std::uint8_t input[] = "Hello World";
|
||||||
std::uint8_t expected_output[] = "SGVsbG8gV29ybGQ";
|
std::uint8_t expected_output[] = "SGVsbG8gV29ybGQ";
|
||||||
std::size_t input_length = sizeof(input) - 1;
|
std::size_t input_length = sizeof(input) - 1;
|
||||||
|
|
||||||
std::size_t output_length = ::olm_encode_base64_length(input_length);
|
std::size_t output_length = ::_olm_encode_base64_length(input_length);
|
||||||
assert_equals(std::size_t(15), output_length);
|
assert_equals(std::size_t(15), output_length);
|
||||||
|
|
||||||
std::uint8_t output[output_length];
|
std::uint8_t output[output_length];
|
||||||
output_length = ::olm_encode_base64(input, input_length, output);
|
output_length = ::_olm_encode_base64(input, input_length, output);
|
||||||
assert_equals(std::size_t(15), output_length);
|
assert_equals(std::size_t(15), output_length);
|
||||||
assert_equals(expected_output, output, output_length);
|
assert_equals(expected_output, output, output_length);
|
||||||
}
|
}
|
||||||
|
@ -57,11 +57,11 @@ std::uint8_t input[] = "SGVsbG8gV29ybGQ";
|
||||||
std::uint8_t expected_output[] = "Hello World";
|
std::uint8_t expected_output[] = "Hello World";
|
||||||
std::size_t input_length = sizeof(input) - 1;
|
std::size_t input_length = sizeof(input) - 1;
|
||||||
|
|
||||||
std::size_t output_length = ::olm_decode_base64_length(input_length);
|
std::size_t output_length = ::_olm_decode_base64_length(input_length);
|
||||||
assert_equals(std::size_t(11), output_length);
|
assert_equals(std::size_t(11), output_length);
|
||||||
|
|
||||||
std::uint8_t output[output_length];
|
std::uint8_t output[output_length];
|
||||||
output_length = ::olm_decode_base64(input, input_length, output);
|
output_length = ::_olm_decode_base64(input, input_length, output);
|
||||||
assert_equals(std::size_t(11), output_length);
|
assert_equals(std::size_t(11), output_length);
|
||||||
assert_equals(expected_output, output, output_length);
|
assert_equals(expected_output, output, output_length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,7 @@ std::uint8_t expected[32] = {
|
||||||
|
|
||||||
std::uint8_t actual[32];
|
std::uint8_t actual[32];
|
||||||
|
|
||||||
crypto_sha256(input, sizeof(input), actual);
|
_olm_crypto_sha256(input, sizeof(input), actual);
|
||||||
|
|
||||||
assert_equals(expected, actual, 32);
|
assert_equals(expected, actual, 32);
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ std::uint8_t expected[32] = {
|
||||||
|
|
||||||
std::uint8_t actual[32];
|
std::uint8_t actual[32];
|
||||||
|
|
||||||
crypto_hmac_sha256(input, sizeof(input), input, sizeof(input), actual);
|
_olm_crypto_hmac_sha256(input, sizeof(input), input, sizeof(input), actual);
|
||||||
|
|
||||||
assert_equals(expected, actual, 32);
|
assert_equals(expected, actual, 32);
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ std::uint8_t hmac_expected_output[32] = {
|
||||||
|
|
||||||
std::uint8_t hmac_actual_output[32] = {};
|
std::uint8_t hmac_actual_output[32] = {};
|
||||||
|
|
||||||
crypto_hmac_sha256(
|
_olm_crypto_hmac_sha256(
|
||||||
salt, sizeof(salt),
|
salt, sizeof(salt),
|
||||||
input, sizeof(input),
|
input, sizeof(input),
|
||||||
hmac_actual_output
|
hmac_actual_output
|
||||||
|
@ -261,7 +261,7 @@ std::uint8_t hkdf_expected_output[42] = {
|
||||||
|
|
||||||
std::uint8_t hkdf_actual_output[42] = {};
|
std::uint8_t hkdf_actual_output[42] = {};
|
||||||
|
|
||||||
crypto_hkdf_sha256(
|
_olm_crypto_hkdf_sha256(
|
||||||
input, sizeof(input),
|
input, sizeof(input),
|
||||||
salt, sizeof(salt),
|
salt, sizeof(salt),
|
||||||
info, sizeof(info),
|
info, sizeof(info),
|
||||||
|
|
|
@ -28,8 +28,8 @@ olm::KdfInfo kdf_info = {
|
||||||
ratchet_info, sizeof(ratchet_info) - 1
|
ratchet_info, sizeof(ratchet_info) - 1
|
||||||
};
|
};
|
||||||
|
|
||||||
olm_cipher_aes_sha_256 cipher0;
|
_olm_cipher_aes_sha_256 cipher0;
|
||||||
olm_cipher *cipher = olm_cipher_aes_sha_256_init(
|
_olm_cipher *cipher = _olm_cipher_aes_sha_256_init(
|
||||||
&cipher0, message_info, sizeof(message_info) - 1
|
&cipher0, message_info, sizeof(message_info) - 1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue