add more consts and comments

This commit is contained in:
Hubert Chathi 2019-05-14 22:02:50 -04:00
parent 0757e6df40
commit 969c8b45e5
2 changed files with 34 additions and 14 deletions

View file

@ -87,7 +87,7 @@ size_t olm_pk_encrypt(
void * ciphertext, size_t ciphertext_length, void * ciphertext, size_t ciphertext_length,
void * mac, size_t mac_length, void * mac, size_t mac_length,
void * ephemeral_key, size_t ephemeral_key_size, void * ephemeral_key, size_t ephemeral_key_size,
void * random, size_t random_length const void * random, size_t random_length
); );
typedef struct OlmPkDecryption OlmPkDecryption; typedef struct OlmPkDecryption OlmPkDecryption;
@ -133,7 +133,7 @@ size_t olm_pk_generate_key_random_length(void);
size_t olm_pk_key_from_private( size_t olm_pk_key_from_private(
OlmPkDecryption * decryption, OlmPkDecryption * decryption,
void * pubkey, size_t pubkey_length, void * pubkey, size_t pubkey_length,
void * privkey, size_t privkey_length const void * privkey, size_t privkey_length
); );
/** DEPRECATED: Use olm_pk_key_from_private /** DEPRECATED: Use olm_pk_key_from_private
@ -141,7 +141,7 @@ size_t olm_pk_key_from_private(
size_t olm_pk_generate_key( size_t olm_pk_generate_key(
OlmPkDecryption * decryption, OlmPkDecryption * decryption,
void * pubkey, size_t pubkey_length, void * pubkey, size_t pubkey_length,
void * privkey, size_t privkey_length const void * privkey, size_t privkey_length
); );
/** Returns the number of bytes needed to store a decryption object. */ /** Returns the number of bytes needed to store a decryption object. */
@ -230,19 +230,39 @@ size_t olm_clear_pk_signing(
); );
/** /**
* Initialise the signing object with a public/private keypair from a seed * Initialise the signing object with a public/private keypair from a seed. The
* associated public key will be written to the pubkey buffer. Returns
* olm_error() on failure. If the public key buffer is too small then
* olm_pk_signing_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". If the seed
* buffer is too small then olm_pk_signing_last_error() will be
* "INPUT_BUFFER_TOO_SMALL".
*/ */
size_t olm_pk_signing_key_from_seed( size_t olm_pk_signing_key_from_seed(
OlmPkSigning * sign, OlmPkSigning * sign,
void * pubkey, size_t pubkey_length, void * pubkey, size_t pubkey_length,
void * seed, size_t seed_length const void * seed, size_t seed_length
); );
/**
* The size required for the seed for initialising a signing object.
*/
size_t olm_pk_signing_seed_length(void); size_t olm_pk_signing_seed_length(void);
/**
* The size of the public key of a signing object.
*/
size_t olm_pk_signing_public_key_length(void); size_t olm_pk_signing_public_key_length(void);
size_t olm_pk_signature_length(); /**
* The size of a signature created by a signing object.
*/
size_t olm_pk_signature_length(void);
/**
* Sign a message. The signature will be written to the signature
* buffer. Returns olm_error() on failure. If the signature buffer is too
* small, olm_pk_signing_last_error() will be "OUTPUT_BUFFER_TOO_SMALL".
*/
size_t olm_pk_sign( size_t olm_pk_sign(
OlmPkSigning *sign, OlmPkSigning *sign,
uint8_t const * message, size_t message_length, uint8_t const * message, size_t message_length,

View file

@ -108,7 +108,7 @@ size_t olm_pk_encrypt(
void * ciphertext, size_t ciphertext_length, void * ciphertext, size_t ciphertext_length,
void * mac, size_t mac_length, void * mac, size_t mac_length,
void * ephemeral_key, size_t ephemeral_key_size, void * ephemeral_key, size_t ephemeral_key_size,
void * random, size_t random_length const void * random, size_t random_length
) { ) {
if (ciphertext_length if (ciphertext_length
< olm_pk_ciphertext_length(encryption, plaintext_length) < olm_pk_ciphertext_length(encryption, plaintext_length)
@ -127,7 +127,7 @@ size_t olm_pk_encrypt(
} }
_olm_curve25519_key_pair ephemeral_keypair; _olm_curve25519_key_pair ephemeral_keypair;
_olm_crypto_curve25519_generate_key((uint8_t *) random, &ephemeral_keypair); _olm_crypto_curve25519_generate_key((const uint8_t *) random, &ephemeral_keypair);
olm::encode_base64( olm::encode_base64(
(const uint8_t *)ephemeral_keypair.public_key.public_key, (const uint8_t *)ephemeral_keypair.public_key.public_key,
CURVE25519_KEY_LENGTH, CURVE25519_KEY_LENGTH,
@ -202,7 +202,7 @@ size_t olm_pk_key_length(void) {
size_t olm_pk_key_from_private( size_t olm_pk_key_from_private(
OlmPkDecryption * decryption, OlmPkDecryption * decryption,
void * pubkey, size_t pubkey_length, void * pubkey, size_t pubkey_length,
void * privkey, size_t privkey_length const void * privkey, size_t privkey_length
) { ) {
if (pubkey_length < olm_pk_key_length()) { if (pubkey_length < olm_pk_key_length()) {
decryption->last_error = decryption->last_error =
@ -215,7 +215,7 @@ size_t olm_pk_key_from_private(
return std::size_t(-1); return std::size_t(-1);
} }
_olm_crypto_curve25519_generate_key((uint8_t *) privkey, &decryption->key_pair); _olm_crypto_curve25519_generate_key((const uint8_t *) privkey, &decryption->key_pair);
olm::encode_base64( olm::encode_base64(
(const uint8_t *)decryption->key_pair.public_key.public_key, (const uint8_t *)decryption->key_pair.public_key.public_key,
CURVE25519_KEY_LENGTH, CURVE25519_KEY_LENGTH,
@ -227,7 +227,7 @@ size_t olm_pk_key_from_private(
size_t olm_pk_generate_key( size_t olm_pk_generate_key(
OlmPkDecryption * decryption, OlmPkDecryption * decryption,
void * pubkey, size_t pubkey_length, void * pubkey, size_t pubkey_length,
void * privkey, size_t privkey_length const void * privkey, size_t privkey_length
) { ) {
return olm_pk_key_from_private(decryption, pubkey, pubkey_length, privkey, privkey_length); return olm_pk_key_from_private(decryption, pubkey, pubkey_length, privkey, privkey_length);
} }
@ -447,7 +447,7 @@ size_t olm_pk_signing_public_key_length(void) {
size_t olm_pk_signing_key_from_seed( size_t olm_pk_signing_key_from_seed(
OlmPkSigning * signing, OlmPkSigning * signing,
void * pubkey, size_t pubkey_length, void * pubkey, size_t pubkey_length,
void * seed, size_t seed_length const void * seed, size_t seed_length
) { ) {
if (pubkey_length < olm_pk_signing_public_key_length()) { if (pubkey_length < olm_pk_signing_public_key_length()) {
signing->last_error = signing->last_error =
@ -460,7 +460,7 @@ size_t olm_pk_signing_key_from_seed(
return std::size_t(-1); return std::size_t(-1);
} }
_olm_crypto_ed25519_generate_key((uint8_t *) seed, &signing->key_pair); _olm_crypto_ed25519_generate_key((const uint8_t *) seed, &signing->key_pair);
olm::encode_base64( olm::encode_base64(
(const uint8_t *)signing->key_pair.public_key.public_key, (const uint8_t *)signing->key_pair.public_key.public_key,
ED25519_PUBLIC_KEY_LENGTH, ED25519_PUBLIC_KEY_LENGTH,
@ -469,7 +469,7 @@ size_t olm_pk_signing_key_from_seed(
return 0; return 0;
} }
size_t olm_pk_signature_length() { size_t olm_pk_signature_length(void) {
return olm::encode_base64_length(ED25519_SIGNATURE_LENGTH); return olm::encode_base64_length(ED25519_SIGNATURE_LENGTH);
} }