aboutsummaryrefslogtreecommitdiff
path: root/include/olm/crypto.hh
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-08-19 17:18:09 +0100
committerMark Haines <mark.haines@matrix.org>2015-08-19 17:32:06 +0100
commitb3180551851d6f736a98eb059d5b46b0872666e2 (patch)
treeeab45e085474fe190d9a87d16ed284a407d96925 /include/olm/crypto.hh
parenta378a40b3a139b789b00d778c1091a0818c4a8ad (diff)
Replace hard coded references to the 32-byte key length with a constant, add utilities for copying data to and from fixed sized arrays
Diffstat (limited to 'include/olm/crypto.hh')
-rw-r--r--include/olm/crypto.hh26
1 files changed, 10 insertions, 16 deletions
diff --git a/include/olm/crypto.hh b/include/olm/crypto.hh
index b845bfe..7a05f8d 100644
--- a/include/olm/crypto.hh
+++ b/include/olm/crypto.hh
@@ -20,28 +20,27 @@
namespace olm {
+static const std::size_t KEY_LENGTH = 32;
+static const std::size_t SIGNATURE_LENGTH = 64;
+static const std::size_t IV_LENGTH = 16;
struct Curve25519PublicKey {
- static const int LENGTH = 32;
- std::uint8_t public_key[32];
+ std::uint8_t public_key[KEY_LENGTH];
};
struct Curve25519KeyPair : public Curve25519PublicKey {
- static const int LENGTH = 64;
- std::uint8_t private_key[32];
+ std::uint8_t private_key[KEY_LENGTH];
};
struct Ed25519PublicKey {
- static const int LENGTH = 32;
- std::uint8_t public_key[32];
+ std::uint8_t public_key[KEY_LENGTH];
};
struct Ed25519KeyPair : public Ed25519PublicKey {
- static const int LENGTH = 64;
- std::uint8_t private_key[32];
+ std::uint8_t private_key[KEY_LENGTH];
};
@@ -52,9 +51,6 @@ void curve25519_generate_key(
);
-const std::size_t CURVE25519_SHARED_SECRET_LENGTH = 32;
-
-
/** Create a shared secret using our private key and their public key.
* The output buffer must be at least 32 bytes long. */
void curve25519_shared_secret(
@@ -109,14 +105,12 @@ bool ed25519_verify(
struct Aes256Key {
- static const int LENGTH = 32;
- std::uint8_t key[32];
+ std::uint8_t key[KEY_LENGTH];
};
struct Aes256Iv {
- static const int LENGTH = 16;
- std::uint8_t iv[16];
+ std::uint8_t iv[IV_LENGTH];
};
@@ -156,7 +150,7 @@ void sha256(
);
-const std::size_t HMAC_SHA256_OUTPUT_LENGTH = 32;
+const std::size_t SHA256_OUTPUT_LENGTH = 32;
/** HMAC: Keyed-Hashing for Message Authentication