diff options
author | Richard van der Hoff <richard@matrix.org> | 2016-09-02 15:13:24 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2016-09-05 10:40:39 +0100 |
commit | f0acf6582f88ca66b3fabf7d622278da51a94c10 (patch) | |
tree | 28581d2ab5ec6cfd835b18aa9be9e1a46109d2b8 /include/olm/crypto.h | |
parent | 2aad4cfa860e33228372d525b4bc6a8bcdfbb8f6 (diff) |
Convert Ed25519 and Curve25519 functions to plain C
Diffstat (limited to 'include/olm/crypto.h')
-rw-r--r-- | include/olm/crypto.h | 79 |
1 files changed, 76 insertions, 3 deletions
diff --git a/include/olm/crypto.h b/include/olm/crypto.h index 325080e..9fc3842 100644 --- a/include/olm/crypto.h +++ b/include/olm/crypto.h @@ -57,9 +57,35 @@ extern "C" { /** length of an aes256 initialisation vector */ #define AES256_IV_LENGTH 16 +struct _olm_curve25519_public_key { + uint8_t public_key[CURVE25519_KEY_LENGTH]; +}; -/** Computes SHA-256 of the input. The output buffer must be a least 32 - * bytes long. */ +struct _olm_curve25519_private_key { + uint8_t private_key[CURVE25519_KEY_LENGTH]; +}; + +struct _olm_curve25519_key_pair { + struct _olm_curve25519_public_key public_key; + struct _olm_curve25519_private_key private_key; +}; + +struct _olm_ed25519_public_key { + uint8_t public_key[ED25519_PUBLIC_KEY_LENGTH]; +}; + +struct _olm_ed25519_private_key { + uint8_t private_key[ED25519_PRIVATE_KEY_LENGTH]; +}; + +struct _olm_ed25519_key_pair { + struct _olm_ed25519_public_key public_key; + struct _olm_ed25519_private_key private_key; +}; + + +/** Computes SHA-256 of the input. The output buffer must be a least + * SHA256_OUTPUT_LENGTH (32) bytes long. */ void _olm_crypto_sha256( uint8_t const * input, size_t input_length, uint8_t * output @@ -68,7 +94,7 @@ void _olm_crypto_sha256( /** HMAC: Keyed-Hashing for Message Authentication * http://tools.ietf.org/html/rfc2104 * Computes HMAC-SHA-256 of the input for the key. The output buffer must - * be at least 32 bytes long. */ + * be at least SHA256_OUTPUT_LENGTH (32) bytes long. */ void _olm_crypto_hmac_sha256( uint8_t const * key, size_t key_length, uint8_t const * input, size_t input_length, @@ -87,6 +113,53 @@ void _olm_crypto_hkdf_sha256( ); +/** Generate a curve25519 key pair + * random_32_bytes should be CURVE25519_RANDOM_LENGTH (32) bytes long. + */ +void _olm_crypto_curve25519_generate_key( + uint8_t const * random_32_bytes, + struct _olm_curve25519_key_pair *output +); + + +/** Create a shared secret using our private key and their public key. + * The output buffer must be at least CURVE25519_SHARED_SECRET_LENGTH (32) bytes long. + */ +void _olm_crypto_curve25519_shared_secret( + const struct _olm_curve25519_key_pair *our_key, + const struct _olm_curve25519_public_key *their_key, + uint8_t * output +); + +/** Generate an ed25519 key pair + * random_32_bytes should be ED25519_RANDOM_LENGTH (32) bytes long. + */ +void _olm_crypto_ed25519_generate_key( + uint8_t const * random_bytes, + struct _olm_ed25519_key_pair *output +); + +/** Signs the message using our private key. + * + * The output buffer must be at least ED25519_SIGNATURE_LENGTH (64) bytes + * long. */ +void _olm_crypto_ed25519_sign( + const struct _olm_ed25519_key_pair *our_key, + const uint8_t * message, size_t message_length, + uint8_t * output +); + +/** Verify an ed25519 signature + * The signature input buffer must be ED25519_SIGNATURE_LENGTH (64) bytes long. + * Returns non-zero if the signature is valid. */ +int _olm_crypto_ed25519_verify( + const struct _olm_ed25519_public_key *their_key, + const uint8_t * message, size_t message_length, + const uint8_t * signature +); + + + #ifdef __cplusplus } // extern "C" #endif |