aboutsummaryrefslogtreecommitdiff
path: root/include
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 /include
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 'include')
-rw-r--r--include/olm/error.h7
-rw-r--r--include/olm/pk.h41
2 files changed, 37 insertions, 11 deletions
diff --git a/include/olm/error.h b/include/olm/error.h
index 9d44a94..ee2187c 100644
--- a/include/olm/error.h
+++ b/include/olm/error.h
@@ -51,6 +51,13 @@ enum OlmErrorCode {
*/
OLM_BAD_SIGNATURE = 14,
+ OLM_INPUT_BUFFER_TOO_SMALL = 15,
+
+ // Not an error code, just here to pad out the enum past 16 because
+ // otherwise the compiler warns about a redunant check. If you're
+ // adding an error code, replace this one!
+ OLM_ERROR_NOT_INVENTED_YET = 16,
+
/* remember to update the list of string constants in error.c when updating
* this list. */
};
diff --git a/include/olm/pk.h b/include/olm/pk.h
index 1f3f9ff..5e779ce 100644
--- a/include/olm/pk.h
+++ b/include/olm/pk.h
@@ -76,7 +76,7 @@ size_t olm_pk_encrypt_random_length(
* ciphertext, mac, or ephemeral_key buffers were too small then
* olm_pk_encryption_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". If there
* weren't enough random bytes then olm_pk_encryption_last_error() will be
- * "NOT_ENOUGH_RANDOM". */
+ * "OLM_INPUT_BUFFER_TOO_SMALL". */
size_t olm_pk_encrypt(
OlmPkEncryption *encryption,
void const * plaintext, size_t plaintext_length,
@@ -108,18 +108,24 @@ size_t olm_clear_pk_decryption(
OlmPkDecryption *decryption
);
-/** The number of random bytes needed to generate a new key. */
-size_t olm_pk_generate_key_random_length(void);
-
-/** Generate a new key to use for decrypting messages. The associated public
- * key will be written to the pubkey buffer. Returns olm_error() on failure. If
- * the pubkey buffer is too small then olm_pk_decryption_last_error() will be
- * "OUTPUT_BUFFER_TOO_SMALL". If there weren't enough random bytes then
- * olm_pk_decryption_last_error() will be "NOT_ENOUGH_RANDOM". */
-size_t olm_pk_generate_key(
+/** Get the number of bytes required to store an olm private key
+ */
+size_t olm_pk_private_key_length();
+
+/** Initialise the key from the private part of a key as returned by
+ * olm_pk_get_private_key(). The associated public key will be written to the
+ * pubkey buffer. Returns olm_error() on failure. If the pubkey buffer is too
+ * small then olm_pk_decryption_last_error() will be "OUTPUT_BUFFER_TOO_SMALL".
+ * If the private key was not long enough then olm_pk_decryption_last_error()
+ * will be "OLM_INPUT_BUFFER_TOO_SMALL".
+ *
+ * Note that the pubkey is a base64 encoded string, but the private key is
+ * an unencoded byte array
+ */
+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
);
/** Returns the number of bytes needed to store a decryption object. */
@@ -171,6 +177,19 @@ size_t olm_pk_decrypt(
void * plaintext, size_t max_plaintext_length
);
+/**
+ * Get the private key for an OlmDecryption object as an unencoded byte array
+ * private_key must be a pointer to a buffer of at least
+ * olm_pk_private_key_length() bytes and this length must be passed in
+ * private_key_length. If the given buffer is too small, returns olm_error()
+ * and olm_pk_encryption_last_error() will be "OUTPUT_BUFFER_TOO_SMALL".
+ * Returns the number of bytes written.
+ */
+size_t olm_pk_get_private_key(
+ OlmPkDecryption * decryption,
+ void *private_key, size_t private_key_length
+);
+
#ifdef __cplusplus
}
#endif