diff --git a/include/olm/account.hh b/include/olm/account.hh index 826b26d..99754ea 100644 --- a/include/olm/account.hh +++ b/include/olm/account.hh @@ -49,7 +49,7 @@ struct Account { OlmErrorCode last_error; /** Number of random bytes needed to create a new account */ - std::size_t new_account_random_length(); + std::size_t new_account_random_length() const; /** Create a new account. Returns std::size_t(-1) on error. If the number of * random bytes is too small then last_error will be NOT_ENOUGH_RANDOM */ @@ -58,7 +58,7 @@ struct Account { ); /** Number of bytes needed to output the identity keys for this account */ - std::size_t get_identity_json_length(); + std::size_t get_identity_json_length() const; /** Output the identity keys for this account as JSON in the following * format: @@ -77,7 +77,7 @@ struct Account { /** * The length of an ed25519 signature in bytes. */ - std::size_t signature_length(); + std::size_t signature_length() const; /** * Signs a message with the ed25519 key for this account. @@ -88,7 +88,7 @@ struct Account { ); /** Number of bytes needed to output the one time keys for this account */ - std::size_t get_one_time_keys_json_length(); + std::size_t get_one_time_keys_json_length() const; /** Output the one time keys that haven't been published yet as JSON: * @@ -111,13 +111,13 @@ struct Account { std::size_t mark_keys_as_published(); /** The largest number of one time keys this account can store. */ - std::size_t max_number_of_one_time_keys(); + std::size_t max_number_of_one_time_keys() const; /** The number of random bytes needed to generate a given number of new one * time keys. */ std::size_t generate_one_time_keys_random_length( std::size_t number_of_keys - ); + ) const; /** Generates a number of new one time keys. If the total number of keys * stored by this account exceeds max_number_of_one_time_keys() then the @@ -129,7 +129,7 @@ struct Account { ); /** The number of random bytes needed to generate a fallback key. */ - std::size_t generate_fallback_key_random_length(); + std::size_t generate_fallback_key_random_length() const; /** Generates a new fallback key. Returns std::size_t(-1) on error. If the * number of random bytes is too small then last_error will be @@ -139,7 +139,7 @@ struct Account { ); /** Number of bytes needed to output the one time keys for this account */ - std::size_t get_fallback_key_json_length(); + std::size_t get_fallback_key_json_length() const; /** Output the fallback key as JSON: * diff --git a/include/olm/olm.h b/include/olm/olm.h index 0d3ea94..e5aff67 100644 --- a/include/olm/olm.h +++ b/include/olm/olm.h @@ -119,12 +119,12 @@ size_t olm_clear_utility( /** Returns the number of bytes needed to store an account */ size_t olm_pickle_account_length( - OlmAccount * account + const OlmAccount * account ); /** Returns the number of bytes needed to store a session */ size_t olm_pickle_session_length( - OlmSession * session + const OlmSession * session ); /** Stores an account as a base64 string. Encrypts the account using the @@ -175,7 +175,7 @@ size_t olm_unpickle_session( /** The number of random bytes needed to create an account.*/ size_t olm_create_account_random_length( - OlmAccount * account + const OlmAccount * account ); /** Creates a new account. Returns olm_error() on failure. If there weren't @@ -188,7 +188,7 @@ size_t olm_create_account( /** The size of the output buffer needed to hold the identity keys */ size_t olm_account_identity_keys_length( - OlmAccount * account + const OlmAccount * account ); /** Writes the public parts of the identity keys for the account into the @@ -203,7 +203,7 @@ size_t olm_account_identity_keys( /** The length of an ed25519 signature encoded as base64. */ size_t olm_account_signature_length( - OlmAccount * account + const OlmAccount * account ); /** Signs a message with the ed25519 key for this account. Returns olm_error() @@ -217,7 +217,7 @@ size_t olm_account_sign( /** The size of the output buffer needed to hold the one time keys */ size_t olm_account_one_time_keys_length( - OlmAccount * account + const OlmAccount * account ); /** Writes the public parts of the unpublished one time keys for the account @@ -250,13 +250,13 @@ size_t olm_account_mark_keys_as_published( /** The largest number of one time keys this account can store. */ size_t olm_account_max_number_of_one_time_keys( - OlmAccount * account + const OlmAccount * account ); /** The number of random bytes needed to generate a given number of new one * time keys. */ size_t olm_account_generate_one_time_keys_random_length( - OlmAccount * account, + const OlmAccount * account, size_t number_of_keys ); @@ -272,7 +272,7 @@ size_t olm_account_generate_one_time_keys( /** The number of random bytes needed to generate a fallback key. */ size_t olm_account_generate_fallback_key_random_length( - OlmAccount * account + const OlmAccount * account ); /** Generates a new fallback key. Only one previous fallback key is @@ -286,7 +286,7 @@ size_t olm_account_generate_fallback_key( /** The number of bytes needed to hold the fallback key as returned by * olm_account_fallback_key. */ size_t olm_account_fallback_key_length( - OlmAccount * account + const OlmAccount * account ); size_t olm_account_fallback_key( @@ -297,7 +297,7 @@ size_t olm_account_fallback_key( /** The number of random bytes needed to create an outbound session */ size_t olm_create_outbound_session_random_length( - OlmSession * session + const OlmSession * session ); /** Creates a new out-bound session for sending messages to a given identity_key @@ -339,7 +339,7 @@ size_t olm_create_inbound_session_from( /** The length of the buffer needed to return the id for this session. */ size_t olm_session_id_length( - OlmSession * session + const OlmSession * session ); /** An identifier for this session. Will be the same for both ends of the @@ -351,7 +351,7 @@ size_t olm_session_id( ); int olm_session_has_received_message( - OlmSession *session + const OlmSession *session ); /** @@ -402,18 +402,18 @@ size_t olm_remove_one_time_keys( * Returns OLM_MESSAGE_TYPE_MESSAGE if the message will be a normal message. * Returns olm_error on failure. */ size_t olm_encrypt_message_type( - OlmSession * session + const OlmSession * session ); /** The number of random bytes needed to encrypt the next message. */ size_t olm_encrypt_random_length( - OlmSession * session + const OlmSession * session ); /** The size of the next message in bytes for the given number of plain-text * bytes. */ size_t olm_encrypt_message_length( - OlmSession * session, + const OlmSession * session, size_t plaintext_length ); @@ -464,7 +464,7 @@ size_t olm_decrypt( /** The length of the buffer needed to hold the SHA-256 hash. */ size_t olm_sha256_length( - OlmUtility * utility + const OlmUtility * utility ); /** Calculates the SHA-256 hash of the input and encodes it as base64. If the diff --git a/include/olm/pk.h b/include/olm/pk.h index ddeedca..a3157a4 100644 --- a/include/olm/pk.h +++ b/include/olm/pk.h @@ -62,13 +62,13 @@ size_t olm_pk_encryption_set_recipient_key( /** Get the length of the ciphertext that will correspond to a plaintext of the * given length. */ size_t olm_pk_ciphertext_length( - OlmPkEncryption *encryption, + const OlmPkEncryption *encryption, size_t plaintext_length ); /** Get the length of the message authentication code. */ size_t olm_pk_mac_length( - OlmPkEncryption *encryption + const OlmPkEncryption *encryption ); /** Get the length of a public or ephemeral key */ @@ -76,7 +76,7 @@ size_t olm_pk_key_length(void); /** The number of random bytes needed to encrypt a message. */ size_t olm_pk_encrypt_random_length( - OlmPkEncryption *encryption + const OlmPkEncryption *encryption ); /** Encrypt a plaintext for the recipient set using @@ -160,7 +160,7 @@ size_t olm_pk_generate_key( /** Returns the number of bytes needed to store a decryption object. */ size_t olm_pickle_pk_decryption_length( - OlmPkDecryption * decryption + const OlmPkDecryption * decryption ); /** Stores decryption object as a base64 string. Encrypts the object using the @@ -191,7 +191,7 @@ size_t olm_unpickle_pk_decryption( /** Get the length of the plaintext that will correspond to a ciphertext of the * given length. */ size_t olm_pk_max_plaintext_length( - OlmPkDecryption * decryption, + const OlmPkDecryption * decryption, size_t ciphertext_length ); diff --git a/include/olm/ratchet.hh b/include/olm/ratchet.hh index 4925e37..050ddd8 100644 --- a/include/olm/ratchet.hh +++ b/include/olm/ratchet.hh @@ -124,12 +124,12 @@ struct Ratchet { * a given message length. */ std::size_t encrypt_output_length( std::size_t plaintext_length - ); + ) const; /** The number of bytes of random data the encrypt method will need to * encrypt a message. This will be 32 bytes if the session needs to * generate a new ephemeral key, or will be 0 bytes otherwise.*/ - std::size_t encrypt_random_length(); + std::size_t encrypt_random_length() const; /** Encrypt some plain-text. Returns the length of the encrypted message * or std::size_t(-1) on failure. On failure last_error will be set with diff --git a/include/olm/sas.h b/include/olm/sas.h index c455435..e9acd62 100644 --- a/include/olm/sas.h +++ b/include/olm/sas.h @@ -61,7 +61,7 @@ size_t olm_clear_sas( /** The number of random bytes needed to create an SAS object. */ size_t olm_create_sas_random_length( - OlmSAS * sas + const OlmSAS * sas ); /** Creates a new SAS object. @@ -81,7 +81,7 @@ size_t olm_create_sas( ); /** The size of a public key in bytes. */ -size_t olm_sas_pubkey_length(OlmSAS * sas); +size_t olm_sas_pubkey_length(const OlmSAS * sas); /** Get the public key for the SAS object. * @@ -119,7 +119,7 @@ size_t olm_sas_set_their_key( * */ int olm_sas_is_their_key_set( - OlmSAS *sas + const OlmSAS *sas ); /** Generate bytes to use for the short authentication string. @@ -144,7 +144,7 @@ size_t olm_sas_generate_bytes( /** The size of the message authentication code generated by * olm_sas_calculate_mac()`. */ size_t olm_sas_mac_length( - OlmSAS *sas + const OlmSAS *sas ); /** Generate a message authentication code (MAC) based on the shared secret. diff --git a/include/olm/session.hh b/include/olm/session.hh index ce05fc8..5859632 100644 --- a/include/olm/session.hh +++ b/include/olm/session.hh @@ -41,7 +41,7 @@ struct Session { /** The number of random bytes that are needed to create a new outbound * session. This will be 64 bytes since two ephemeral keys are needed. */ - std::size_t new_outbound_session_random_length(); + std::size_t new_outbound_session_random_length() const; /** Start a new outbound session. Returns std::size_t(-1) on failure. On * failure last_error will be set with an error code. The last_error will be @@ -64,7 +64,7 @@ struct Session { ); /** The number of bytes written by session_id() */ - std::size_t session_id_length(); + std::size_t session_id_length() const; /** An identifier for this session. Generated by hashing the public keys * used to create the session. Returns the length of the session id on @@ -84,21 +84,21 @@ struct Session { bool matches_inbound_session( _olm_curve25519_public_key const * their_identity_key, std::uint8_t const * pre_key_message, std::size_t message_length - ); + ) const; /** Whether the next message will be a pre-key message or a normal message. * An outbound session will send pre-key messages until it receives a * message with a ratchet key. */ - MessageType encrypt_message_type(); + MessageType encrypt_message_type() const; std::size_t encrypt_message_length( std::size_t plaintext_length - ); + ) const; /** The number of bytes of random data the encrypt method will need to * encrypt a message. This will be 32 bytes if the session needs to * generate a new ephemeral key, or will be 0 bytes otherwise. */ - std::size_t encrypt_random_length(); + std::size_t encrypt_random_length() const; /** Encrypt some plain-text. Returns the length of the encrypted message * or std::size_t(-1) on failure. On failure last_error will be set with diff --git a/include/olm/utility.hh b/include/olm/utility.hh index d650abc..3e5f5b7 100644 --- a/include/olm/utility.hh +++ b/include/olm/utility.hh @@ -32,7 +32,7 @@ struct Utility { OlmErrorCode last_error; /** The length of a SHA-256 hash in bytes. */ - std::size_t sha256_length(); + std::size_t sha256_length() const; /** Compute a SHA-256 hash. Returns the length of the SHA-256 hash in bytes * on success. Returns std::size_t(-1) on failure. On failure last_error diff --git a/libolm.version b/libolm.version index f93b6f2..343b0cf 100644 --- a/libolm.version +++ b/libolm.version @@ -1,4 +1,4 @@ { - global: olm*; _olm*; megolm*; _ZN3olm*; + global: olm*; _olm*; megolm*; _ZN3olm*; _ZNK3olm*; local: *; }; diff --git a/src/account.cpp b/src/account.cpp index d7a3e4c..7b81dc7 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -84,7 +84,7 @@ std::size_t olm::Account::remove_key( return std::size_t(-1); } -std::size_t olm::Account::new_account_random_length() { +std::size_t olm::Account::new_account_random_length() const { return ED25519_RANDOM_LENGTH + CURVE25519_RANDOM_LENGTH; } @@ -120,7 +120,7 @@ static std::uint8_t * write_string( } -std::size_t olm::Account::get_identity_json_length() { +std::size_t olm::Account::get_identity_json_length() const { std::size_t length = 0; length += 1; /* { */ length += sizeof(KEY_JSON_CURVE25519) - 1; @@ -172,7 +172,7 @@ std::size_t olm::Account::get_identity_json( std::size_t olm::Account::signature_length( -) { +) const { return ED25519_SIGNATURE_LENGTH; } @@ -193,7 +193,7 @@ std::size_t olm::Account::sign( std::size_t olm::Account::get_one_time_keys_json_length( -) { +) const { std::size_t length = 0; bool is_empty = true; for (auto const & key : one_time_keys) { @@ -267,13 +267,13 @@ std::size_t olm::Account::mark_keys_as_published( std::size_t olm::Account::max_number_of_one_time_keys( -) { +) const { return olm::MAX_ONE_TIME_KEYS; } std::size_t olm::Account::generate_one_time_keys_random_length( std::size_t number_of_keys -) { +) const { return CURVE25519_RANDOM_LENGTH * number_of_keys; } @@ -295,7 +295,7 @@ std::size_t olm::Account::generate_one_time_keys( return number_of_keys; } -std::size_t olm::Account::generate_fallback_key_random_length() { +std::size_t olm::Account::generate_fallback_key_random_length() const { return CURVE25519_RANDOM_LENGTH; } @@ -315,9 +315,9 @@ std::size_t olm::Account::generate_fallback_key( std::size_t olm::Account::get_fallback_key_json_length( -) { +) const { std::size_t length = 4 + sizeof(KEY_JSON_CURVE25519) - 1; /* {"curve25519":{}} */ - OneTimeKey & key = current_fallback_key; + const OneTimeKey & key = current_fallback_key; if (key.published) { length += 1; /* " */ length += olm::encode_base64_length(_olm_pickle_uint32_length(key.id)); diff --git a/src/olm.cpp b/src/olm.cpp index b8896c7..5024874 100644 --- a/src/olm.cpp +++ b/src/olm.cpp @@ -231,14 +231,14 @@ size_t olm_clear_utility( size_t olm_pickle_account_length( - OlmAccount * account + const OlmAccount * account ) { return _olm_enc_output_length(pickle_length(*from_c(account))); } size_t olm_pickle_session_length( - OlmSession * session + const OlmSession * session ) { return _olm_enc_output_length(pickle_length(*from_c(session))); } @@ -334,7 +334,7 @@ size_t olm_unpickle_session( size_t olm_create_account_random_length( - OlmAccount * account + const OlmAccount * account ) { return from_c(account)->new_account_random_length(); } @@ -351,7 +351,7 @@ size_t olm_create_account( size_t olm_account_identity_keys_length( - OlmAccount * account + const OlmAccount * account ) { return from_c(account)->get_identity_json_length(); } @@ -368,7 +368,7 @@ size_t olm_account_identity_keys( size_t olm_account_signature_length( - OlmAccount * account + const OlmAccount * account ) { return b64_output_length(from_c(account)->signature_length()); } @@ -394,7 +394,7 @@ size_t olm_account_sign( size_t olm_account_one_time_keys_length( - OlmAccount * account + const OlmAccount * account ) { return from_c(account)->get_one_time_keys_json_length(); } @@ -418,14 +418,14 @@ size_t olm_account_mark_keys_as_published( size_t olm_account_max_number_of_one_time_keys( - OlmAccount * account + const OlmAccount * account ) { return from_c(account)->max_number_of_one_time_keys(); } size_t olm_account_generate_one_time_keys_random_length( - OlmAccount * account, + const OlmAccount * account, size_t number_of_keys ) { return from_c(account)->generate_one_time_keys_random_length(number_of_keys); @@ -447,7 +447,7 @@ size_t olm_account_generate_one_time_keys( size_t olm_account_generate_fallback_key_random_length( - OlmAccount * account + const OlmAccount * account ) { return from_c(account)->generate_fallback_key_random_length(); } @@ -466,7 +466,7 @@ size_t olm_account_generate_fallback_key( size_t olm_account_fallback_key_length( - OlmAccount * account + const OlmAccount * account ) { return from_c(account)->get_fallback_key_json_length(); } @@ -483,7 +483,7 @@ size_t olm_account_fallback_key( size_t olm_create_outbound_session_random_length( - OlmSession * session + const OlmSession * session ) { return from_c(session)->new_outbound_session_random_length(); } @@ -569,7 +569,7 @@ size_t olm_create_inbound_session_from( size_t olm_session_id_length( - OlmSession * session + const OlmSession * session ) { return b64_output_length(from_c(session)->session_id_length()); } @@ -595,7 +595,7 @@ size_t olm_session_id( int olm_session_has_received_message( - OlmSession * session + const OlmSession * session ) { return from_c(session)->received_message; } @@ -666,21 +666,21 @@ size_t olm_remove_one_time_keys( size_t olm_encrypt_message_type( - OlmSession * session + const OlmSession * session ) { return size_t(from_c(session)->encrypt_message_type()); } size_t olm_encrypt_random_length( - OlmSession * session + const OlmSession * session ) { return from_c(session)->encrypt_random_length(); } size_t olm_encrypt_message_length( - OlmSession * session, + const OlmSession * session, size_t plaintext_length ) { return b64_output_length( @@ -753,7 +753,7 @@ size_t olm_decrypt( size_t olm_sha256_length( - OlmUtility * utility + const OlmUtility * utility ) { return b64_output_length(from_c(utility)->sha256_length()); } diff --git a/src/pk.cpp b/src/pk.cpp index 99882db..70d64a5 100644 --- a/src/pk.cpp +++ b/src/pk.cpp @@ -90,7 +90,7 @@ size_t olm_pk_encryption_set_recipient_key ( } size_t olm_pk_ciphertext_length( - OlmPkEncryption *encryption, + const OlmPkEncryption *encryption, size_t plaintext_length ) { return olm::encode_base64_length( @@ -99,13 +99,13 @@ size_t olm_pk_ciphertext_length( } size_t olm_pk_mac_length( - OlmPkEncryption *encryption + const OlmPkEncryption *encryption ) { return olm::encode_base64_length(_olm_cipher_aes_sha_256_ops.mac_length(olm_pk_cipher)); } size_t olm_pk_encrypt_random_length( - OlmPkEncryption *encryption + const OlmPkEncryption *encryption ) { return CURVE25519_KEY_LENGTH; } @@ -291,7 +291,7 @@ namespace { } size_t olm_pickle_pk_decryption_length( - OlmPkDecryption * decryption + const OlmPkDecryption * decryption ) { return _olm_enc_output_length(pickle_length(*decryption)); } @@ -355,7 +355,7 @@ size_t olm_unpickle_pk_decryption( } size_t olm_pk_max_plaintext_length( - OlmPkDecryption * decryption, + const OlmPkDecryption * decryption, size_t ciphertext_length ) { return _olm_cipher_aes_sha_256_ops.decrypt_max_plaintext_length( diff --git a/src/ratchet.cpp b/src/ratchet.cpp index 026a105..360a20b 100644 --- a/src/ratchet.cpp +++ b/src/ratchet.cpp @@ -399,7 +399,7 @@ std::uint8_t const * olm::unpickle( std::size_t olm::Ratchet::encrypt_output_length( std::size_t plaintext_length -) { +) const { std::size_t counter = 0; if (!sender_chain.empty()) { counter = sender_chain[0].chain_key.index; @@ -414,7 +414,7 @@ std::size_t olm::Ratchet::encrypt_output_length( } -std::size_t olm::Ratchet::encrypt_random_length() { +std::size_t olm::Ratchet::encrypt_random_length() const { return sender_chain.empty() ? CURVE25519_RANDOM_LENGTH : 0; } diff --git a/src/sas.c b/src/sas.c index 765a4a6..d9cec7e 100644 --- a/src/sas.c +++ b/src/sas.c @@ -56,7 +56,7 @@ size_t olm_clear_sas( return sizeof(OlmSAS); } -size_t olm_create_sas_random_length(OlmSAS * sas) { +size_t olm_create_sas_random_length(const OlmSAS * sas) { return CURVE25519_KEY_LENGTH; } @@ -73,7 +73,7 @@ size_t olm_create_sas( return 0; } -size_t olm_sas_pubkey_length(OlmSAS * sas) { +size_t olm_sas_pubkey_length(const OlmSAS * sas) { return _olm_encode_base64_length(CURVE25519_KEY_LENGTH); } @@ -114,7 +114,7 @@ size_t olm_sas_set_their_key( } int olm_sas_is_their_key_set( - OlmSAS *sas + const OlmSAS *sas ) { return sas->their_key_set; } @@ -138,7 +138,7 @@ size_t olm_sas_generate_bytes( } size_t olm_sas_mac_length( - OlmSAS *sas + const OlmSAS *sas ) { return _olm_encode_base64_length(SHA256_OUTPUT_LENGTH); } diff --git a/src/session.cpp b/src/session.cpp index b619e56..bd622fc 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -49,7 +49,7 @@ olm::Session::Session( } -std::size_t olm::Session::new_outbound_session_random_length() { +std::size_t olm::Session::new_outbound_session_random_length() const { return CURVE25519_RANDOM_LENGTH * 2; } @@ -193,7 +193,7 @@ std::size_t olm::Session::new_inbound_session( } -std::size_t olm::Session::session_id_length() { +std::size_t olm::Session::session_id_length() const { return SHA256_OUTPUT_LENGTH; } @@ -218,7 +218,7 @@ std::size_t olm::Session::session_id( bool olm::Session::matches_inbound_session( _olm_curve25519_public_key const * their_identity_key, std::uint8_t const * one_time_key_message, std::size_t message_length -) { +) const { olm::PreKeyMessageReader reader; decode_one_time_key_message(reader, one_time_key_message, message_length); @@ -248,7 +248,7 @@ bool olm::Session::matches_inbound_session( } -olm::MessageType olm::Session::encrypt_message_type() { +olm::MessageType olm::Session::encrypt_message_type() const { if (received_message) { return olm::MessageType::MESSAGE; } else { @@ -259,7 +259,7 @@ olm::MessageType olm::Session::encrypt_message_type() { std::size_t olm::Session::encrypt_message_length( std::size_t plaintext_length -) { +) const { std::size_t message_length = ratchet.encrypt_output_length( plaintext_length ); @@ -277,7 +277,7 @@ std::size_t olm::Session::encrypt_message_length( } -std::size_t olm::Session::encrypt_random_length() { +std::size_t olm::Session::encrypt_random_length() const { return ratchet.encrypt_random_length(); } diff --git a/src/utility.cpp b/src/utility.cpp index e9688de..b6bb56e 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -22,7 +22,7 @@ olm::Utility::Utility( } -size_t olm::Utility::sha256_length() { +size_t olm::Utility::sha256_length() const { return SHA256_OUTPUT_LENGTH; }