From 2ef1f6f4fc5bdc069483a527ab3a1b060c71fcad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Wed, 23 Sep 2020 10:13:46 +0200 Subject: SAS: add olm_sas_is_their_key_set Also make olm_sas_generate_bytes fail if their key wasn't set. --- src/error.c | 1 + src/sas.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) (limited to 'src') diff --git a/src/error.c b/src/error.c index 5147b5c..7d39637 100644 --- a/src/error.c +++ b/src/error.c @@ -32,6 +32,7 @@ static const char * ERRORS[] = { "BAD_LEGACY_ACCOUNT_PICKLE", "BAD_SIGNATURE", "OLM_INPUT_BUFFER_TOO_SMALL", + "OLM_SAS_THEIR_KEY_NOT_SET" }; const char * _olm_error_to_string(enum OlmErrorCode error) diff --git a/src/sas.c b/src/sas.c index 76e4576..8d239b1 100644 --- a/src/sas.c +++ b/src/sas.c @@ -23,6 +23,7 @@ struct OlmSAS { enum OlmErrorCode last_error; struct _olm_curve25519_key_pair curve25519_key; uint8_t secret[CURVE25519_SHARED_SECRET_LENGTH]; + int their_key_set; }; const char * olm_sas_last_error( @@ -95,14 +96,25 @@ size_t olm_sas_set_their_key( } _olm_decode_base64(their_key, their_key_length, their_key); _olm_crypto_curve25519_shared_secret(&sas->curve25519_key, their_key, sas->secret); + sas->their_key_set = 1; return 0; } +int olm_sas_is_their_key_set( + OlmSAS *sas +) { + return sas->their_key_set; +} + size_t olm_sas_generate_bytes( OlmSAS * sas, const void * info, size_t info_length, void * output, size_t output_length ) { + if (!sas->their_key_set) { + sas->last_error = OLM_SAS_THEIR_KEY_NOT_SET; + return (size_t)-1; + } _olm_crypto_hkdf_sha256( sas->secret, sizeof(sas->secret), NULL, 0, -- cgit v1.2.3