aboutsummaryrefslogtreecommitdiff
path: root/src/sas.c
diff options
context:
space:
mode:
authorSaúl Ibarra Corretgé <s@saghul.net>2020-09-23 10:13:46 +0200
committerHubert Chathi <hubert@uhoreg.ca>2020-09-23 15:27:55 -0400
commit2ef1f6f4fc5bdc069483a527ab3a1b060c71fcad (patch)
tree40a3a0833442a59edc18378cc2aa0886eaa44b1a /src/sas.c
parent4bae4134eb115859038de4e8eab11b22baf80b0c (diff)
SAS: add olm_sas_is_their_key_set
Also make olm_sas_generate_bytes fail if their key wasn't set.
Diffstat (limited to 'src/sas.c')
-rw-r--r--src/sas.c12
1 files changed, 12 insertions, 0 deletions
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,