diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/olm/crypto.h | 31 | ||||
-rw-r--r-- | include/olm/crypto.hh | 15 | ||||
-rw-r--r-- | include/olm/ratchet.hh | 7 |
3 files changed, 41 insertions, 12 deletions
diff --git a/include/olm/crypto.h b/include/olm/crypto.h index 31b9b60..325080e 100644 --- a/include/olm/crypto.h +++ b/include/olm/crypto.h @@ -27,7 +27,36 @@ extern "C" { #endif -const size_t SHA256_OUTPUT_LENGTH = 32; +/** length of a sha256 hash */ +#define SHA256_OUTPUT_LENGTH 32 + +/** length of a public or private Curve25519 key */ +#define CURVE25519_KEY_LENGTH 32 + +/** length of the shared secret created by a Curve25519 ECDH operation */ +#define CURVE25519_SHARED_SECRET_LENGTH 32 + +/** amount of random data required to create a Curve25519 keypair */ +#define CURVE25519_RANDOM_LENGTH CURVE25519_KEY_LENGTH + +/** length of a public Ed25519 key */ +#define ED25519_PUBLIC_KEY_LENGTH 32 + +/** length of a private Ed25519 key */ +#define ED25519_PRIVATE_KEY_LENGTH 64 + +/** amount of random data required to create a Ed25519 keypair */ +#define ED25519_RANDOM_LENGTH 32 + +/** length of an Ed25519 signature */ +#define ED25519_SIGNATURE_LENGTH 64 + +/** length of an aes256 key */ +#define AES256_KEY_LENGTH 32 + +/** length of an aes256 initialisation vector */ +#define AES256_IV_LENGTH 16 + /** Computes SHA-256 of the input. The output buffer must be a least 32 * bytes long. */ diff --git a/include/olm/crypto.hh b/include/olm/crypto.hh index 484dc83..13fd7e9 100644 --- a/include/olm/crypto.hh +++ b/include/olm/crypto.hh @@ -25,23 +25,18 @@ namespace olm { -static const std::size_t ED25519_PRIVATE_KEY_LENGTH = 64; -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 { - std::uint8_t public_key[KEY_LENGTH]; + std::uint8_t public_key[CURVE25519_KEY_LENGTH]; }; struct Curve25519KeyPair : public Curve25519PublicKey { - std::uint8_t private_key[KEY_LENGTH]; + std::uint8_t private_key[CURVE25519_KEY_LENGTH]; }; struct Ed25519PublicKey { - std::uint8_t public_key[KEY_LENGTH]; + std::uint8_t public_key[ED25519_PUBLIC_KEY_LENGTH]; }; @@ -93,12 +88,12 @@ bool ed25519_verify( struct Aes256Key { - std::uint8_t key[KEY_LENGTH]; + std::uint8_t key[AES256_KEY_LENGTH]; }; struct Aes256Iv { - std::uint8_t iv[IV_LENGTH]; + std::uint8_t iv[AES256_IV_LENGTH]; }; diff --git a/include/olm/ratchet.hh b/include/olm/ratchet.hh index 13f7097..e91d634 100644 --- a/include/olm/ratchet.hh +++ b/include/olm/ratchet.hh @@ -21,8 +21,13 @@ struct _olm_cipher; namespace olm { -typedef std::uint8_t SharedKey[olm::KEY_LENGTH]; +/** length of a shared key: the root key R(i), chain key C(i,j), and message key + * M(i,j)). They are all only used to stuff into HMACs, so could be any length + * for that. The chain key and message key are both derived from SHA256 + * operations, so their length is determined by that. */ +const std::size_t OLM_SHARED_KEY_LENGTH = SHA256_OUTPUT_LENGTH; +typedef std::uint8_t SharedKey[OLM_SHARED_KEY_LENGTH]; struct ChainKey { std::uint32_t index; |