aboutsummaryrefslogtreecommitdiff
path: root/src/pk.cpp
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2018-10-02 12:02:56 +0100
committerDavid Baker <dave@matrix.org>2018-10-02 12:02:56 +0100
commit0346145a813cfb719fdf218956cb2f29030134a8 (patch)
tree02cfc37642efe1c4f505e7358cfb68c4950059fa /src/pk.cpp
parent00384ba87a5943a8a12c9b8bfcb8903cc9be490f (diff)
Work with PkDecryption keys by their private keys
Change interface to allow the app to get the private part of the key and instantiate a decryption object from just the private part of the key. Changes the function generating a key from random bytes to be initialising a key with a private key (because it's exactly the same thing). Exports & imports private key parts as ArrayBuffer at JS level rather than base64 assuming we are moving that way in general.
Diffstat (limited to 'src/pk.cpp')
-rw-r--r--src/pk.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/pk.cpp b/src/pk.cpp
index e646dc4..20ab991 100644
--- a/src/pk.cpp
+++ b/src/pk.cpp
@@ -176,7 +176,7 @@ size_t olm_clear_pk_decryption(
return sizeof(OlmPkDecryption);
}
-size_t olm_pk_generate_key_random_length(void) {
+size_t olm_pk_private_key_length(void) {
return CURVE25519_KEY_LENGTH;
}
@@ -184,23 +184,23 @@ size_t olm_pk_key_length(void) {
return olm::encode_base64_length(CURVE25519_KEY_LENGTH);
}
-size_t olm_pk_generate_key(
+size_t olm_pk_key_from_private(
OlmPkDecryption * decryption,
void * pubkey, size_t pubkey_length,
- void * random, size_t random_length
+ void * privkey, size_t privkey_length
) {
if (pubkey_length < olm_pk_key_length()) {
decryption->last_error =
OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
return std::size_t(-1);
}
- if (random_length < olm_pk_generate_key_random_length()) {
+ if (privkey_length < olm_pk_private_key_length()) {
decryption->last_error =
- OlmErrorCode::OLM_NOT_ENOUGH_RANDOM;
+ OlmErrorCode::OLM_INPUT_BUFFER_TOO_SMALL;
return std::size_t(-1);
}
- _olm_crypto_curve25519_generate_key((uint8_t *) random, &decryption->key_pair);
+ _olm_crypto_curve25519_generate_key((uint8_t *) privkey, &decryption->key_pair);
olm::encode_base64((const uint8_t *)decryption->key_pair.public_key.public_key, CURVE25519_KEY_LENGTH, (uint8_t *)pubkey);
return 0;
}
@@ -352,4 +352,21 @@ size_t olm_pk_decrypt(
}
}
+size_t olm_pk_get_private_key(
+ OlmPkDecryption * decryption,
+ void *private_key, size_t private_key_length
+) {
+ if (private_key_length < olm_pk_private_key_length()) {
+ decryption->last_error =
+ OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
+ return std::size_t(-1);
+ }
+ std::memcpy(
+ private_key,
+ decryption->key_pair.private_key.private_key,
+ olm_pk_private_key_length()
+ );
+ return olm_pk_private_key_length();
+}
+
}