diff options
author | Hubert Chathi <hubertc@matrix.org> | 2020-09-17 21:42:25 +0000 |
---|---|---|
committer | Hubert Chathi <hubertc@matrix.org> | 2020-09-17 21:42:25 +0000 |
commit | 3cd6b15853923fff512138ebb5e8ba390cfb38e2 (patch) | |
tree | 6830d4d13f7c1106f8e4e772e16f9204d523fcd5 /include | |
parent | 89050dc0b68f0d5f1bf9f9f386f7c2f4ac043f4f (diff) | |
parent | c47c6ca3992c74489700cda44443ec29c3cb3b13 (diff) |
Merge branch 'uhoreg/fallback' into 'master'
add support for fallback keys
See merge request matrix-org/olm!13
Diffstat (limited to 'include')
-rw-r--r-- | include/olm/account.hh | 31 | ||||
-rw-r--r-- | include/olm/olm.h | 25 |
2 files changed, 56 insertions, 0 deletions
diff --git a/include/olm/account.hh b/include/olm/account.hh index 7e58ca3..826b26d 100644 --- a/include/olm/account.hh +++ b/include/olm/account.hh @@ -43,6 +43,8 @@ struct Account { Account(); IdentityKeys identity_keys; List<OneTimeKey, MAX_ONE_TIME_KEYS> one_time_keys; + OneTimeKey current_fallback_key; + OneTimeKey prev_fallback_key; std::uint32_t next_one_time_key_id; OlmErrorCode last_error; @@ -126,6 +128,35 @@ struct Account { std::uint8_t const * random, std::size_t random_length ); + /** The number of random bytes needed to generate a fallback key. */ + std::size_t generate_fallback_key_random_length(); + + /** 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 + * NOT_ENOUGH_RANDOM */ + std::size_t generate_fallback_key( + std::uint8_t const * random, std::size_t random_length + ); + + /** Number of bytes needed to output the one time keys for this account */ + std::size_t get_fallback_key_json_length(); + + /** Output the fallback key as JSON: + * + * {"curve25519": + * ["<6 byte key id>":"<43 base64 characters>" + * ,"<6 byte key id>":"<43 base64 characters>" + * ... + * ] + * } + * + * Returns the size of the JSON written or std::size_t(-1) on error. + * If the buffer is too small last_error will be OUTPUT_BUFFER_TOO_SMALL. + */ + std::size_t get_fallback_key_json( + std::uint8_t * fallback_json, std::size_t fallback_json_length + ); + /** Lookup a one time key with the given public key */ OneTimeKey const * lookup_key( _olm_curve25519_public_key const & public_key diff --git a/include/olm/olm.h b/include/olm/olm.h index 6a2b3fb..11d99b4 100644 --- a/include/olm/olm.h +++ b/include/olm/olm.h @@ -254,6 +254,31 @@ size_t olm_account_generate_one_time_keys( void * random, size_t random_length ); +/** The number of random bytes needed to generate a fallback key. */ +size_t olm_account_generate_fallback_key_random_length( + OlmAccount * account +); + +/** Generates a new fallback key. Only one previous fallback key is + * stored. Returns olm_error() on error. If the number of random bytes is too + * small then olm_account_last_error() will be "NOT_ENOUGH_RANDOM". */ +size_t olm_account_generate_fallback_key( + OlmAccount * account, + void * random, size_t random_length +); + +/** 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 +); + +size_t olm_account_fallback_key( + OlmAccount * account, + void * fallback_key, size_t fallback_key_size +); + + /** The number of random bytes needed to create an outbound session */ size_t olm_create_outbound_session_random_length( OlmSession * session |