aboutsummaryrefslogtreecommitdiff
path: root/include/olm
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2016-05-24 12:06:47 +0100
committerRichard van der Hoff <richard@matrix.org>2016-05-24 12:06:47 +0100
commit2fd28a66824bda7b86c08b065736009c39761987 (patch)
tree8bd7226ffd290b7eb2863733460e2ec0f2685306 /include/olm
parentd4a3c8dbaa6730519d3b6b13004e7fd9ea288870 (diff)
Rewrite _olm_cipher_aes_sha_256 initialisation
Replace the init-static-var dance with some preprocessor macros
Diffstat (limited to 'include/olm')
-rw-r--r--include/olm/cipher.h31
1 files changed, 18 insertions, 13 deletions
diff --git a/include/olm/cipher.h b/include/olm/cipher.h
index 5f7185c..b26f8ba 100644
--- a/include/olm/cipher.h
+++ b/include/olm/cipher.h
@@ -102,28 +102,33 @@ struct _olm_cipher {
struct _olm_cipher_aes_sha_256 {
struct _olm_cipher base_cipher;
+ /** context string for the HKDF used for deriving the AES256 key, HMAC key,
+ * and AES IV, from the key material passed to encrypt/decrypt.
+ */
uint8_t const * kdf_info;
+
+ /** length of context string kdf_info */
size_t kdf_info_length;
};
+extern const struct _olm_cipher_ops _olm_cipher_aes_sha_256_ops;
/**
- * initialises a cipher type which uses AES256 for encryption and SHA256 for
- * authentication.
- *
- * cipher: structure to be initialised
+ * get an initializer for an instance of struct _olm_cipher_aes_sha_256.
*
- * kdf_info: context string for the HKDF used for deriving the AES256 key, HMAC
- * key, and AES IV, from the key material passed to encrypt/decrypt. Note that
- * this is NOT copied so must have a lifetime at least as long as the cipher
- * instance.
+ * To use it, declare:
*
- * kdf_info_length: length of context string kdf_info
+ * struct _olm_cipher_aes_sha_256 MY_CIPHER =
+ * OLM_CIPHER_INIT_AES_SHA_256("MY_KDF");
+ * struct _olm_cipher *cipher = OLM_CIPHER_BASE(&MY_CIPHER);
*/
-struct _olm_cipher *_olm_cipher_aes_sha_256_init(
- struct _olm_cipher_aes_sha_256 *cipher,
- uint8_t const * kdf_info,
- size_t kdf_info_length);
+#define OLM_CIPHER_INIT_AES_SHA_256(KDF_INFO) { \
+ .base_cipher = { &_olm_cipher_aes_sha_256_ops },\
+ .kdf_info = (uint8_t *)(KDF_INFO), \
+ .kdf_info_length = sizeof(KDF_INFO) - 1 \
+}
+#define OLM_CIPHER_BASE(CIPHER) \
+ (&((CIPHER)->base_cipher))
#ifdef __cplusplus