77 *state = noise_curve25519_new();
81 *state = noise_curve448_new();
85 *state = noise_newhope_new();
374 (
NoiseDHState *state,
const uint8_t *private_key,
size_t private_key_len,
375 const uint8_t *public_key,
size_t public_key_len)
380 if (!state || !private_key || !public_key)
388 err = (*(state->
set_keypair))(state, private_key, public_key);
423 (
NoiseDHState *state,
const uint8_t *private_key,
size_t private_key_len)
428 if (!state || !private_key)
462 (
const NoiseDHState *state, uint8_t *private_key,
size_t private_key_len,
463 uint8_t *public_key,
size_t public_key_len)
466 if (!state || !private_key || !public_key)
475 memset(private_key, 0, private_key_len);
476 memset(public_key, 0, public_key_len);
481 memcpy(private_key, state->
private_key, private_key_len);
482 memcpy(public_key, state->
public_key, public_key_len);
511 (
NoiseDHState *state,
const uint8_t *public_key,
size_t public_key_len)
516 if (!state || !public_key)
525 err &= (is_null - 1);
531 memcpy(state->
public_key, public_key, public_key_len);
551 (
const NoiseDHState *state, uint8_t *public_key,
size_t public_key_len)
554 if (!state || !public_key)
560 memcpy(public_key, state->
public_key, public_key_len);
645 static void noise_cmove_zero(uint8_t *data,
size_t len,
int condition)
650 uint8_t mask = ~((uint8_t)(-condition));
688 uint8_t *shared_key,
size_t shared_key_len)
693 if (!private_key_state || !public_key_state || !shared_key)
695 if (private_key_state->
dh_id != public_key_state->
dh_id)
710 (private_key_state, public_key_state, shared_key);
714 noise_cmove_zero(shared_key, shared_key_len, is_null);
715 err &= (is_null - 1);
743 err = (*(state->
copy))(state, from, 0);
776 (
const NoiseDHState *state,
int fingerprint_type,
char *buffer,
size_t len)
791 (fingerprint_type, buffer, len,
807 return state ? state->
role : 0;
int noise_dhstate_get_public_key(const NoiseDHState *state, uint8_t *public_key, size_t public_key_len)
Gets the public key value from a DHState object.
uint8_t nulls_allowed
Non-zero if null public keys are allowed with this algorithm.
#define NOISE_ERROR_UNKNOWN_ID
Algorithm identifier is unknown.
int noise_dhstate_clear_key(NoiseDHState *state)
Clears the key in a DHState object.
size_t noise_dhstate_get_public_key_length(const NoiseDHState *state)
Gets the length of the public key for a DHState object.
int noise_dhstate_get_keypair(const NoiseDHState *state, uint8_t *private_key, size_t private_key_len, uint8_t *public_key, size_t public_key_len)
Gets the keypair from within a DHState object.
#define NOISE_ERROR_INVALID_STATE
Operation cannot be performed in the current state.
#define NOISE_ERROR_INVALID_PARAM
Invalid parameter to function; e.g. a NULL value.
uint8_t * public_key
Points to the public key in the subclass state.
size_t noise_dhstate_get_shared_key_length(const NoiseDHState *state)
Gets the length of the shared key for a DHState object.
int noise_dhstate_get_dh_id(const NoiseDHState *state)
Gets the algorithm identifier for a DHState object.
int noise_dhstate_format_fingerprint(const NoiseDHState *state, int fingerprint_type, char *buffer, size_t len)
Formats the public key fingerprint for the key within a DHState.
#define NOISE_ERROR_NONE
Success, no error.
#define NOISE_KEY_TYPE_NO_KEY
int(* validate_public_key)(const NoiseDHState *state, const uint8_t *public_key)
Validates a public key.
void(* destroy)(NoiseDHState *state)
Destroys this DHState prior to the memory being freed.
int noise_dhstate_get_role(const NoiseDHState *state)
Gets the role that a DHState object will play in a handshake.
void(* change_role)(NoiseDHState *state)
Changes the role for this object.
int noise_is_zero(const void *data, size_t size)
Determine if a block of memory consists of all zero bytes.
int noise_dhstate_new_by_id(NoiseDHState **state, int id)
Creates a new DHState object by its algorithm identifier.
int noise_format_fingerprint(int fingerprint_type, char *buffer, size_t len, const uint8_t *public_key, size_t public_key_len)
Formats the fingerprint for a raw public key value.
int(* set_keypair_private)(NoiseDHState *state, const uint8_t *private_key)
Sets a keypair using only the private key.
#define NOISE_DH_CATEGORY
Category for Diffie-Hellman algorithms.
int(* set_keypair)(NoiseDHState *state, const uint8_t *private_key, const uint8_t *public_key)
Sets a keypair.
#define NOISE_DH_CURVE448
Diffie-Hellman identifier for "448".
#define NOISE_KEY_TYPE_KEYPAIR
uint16_t shared_key_len
Length of the shared key for this algorithm in bytes.
Internal structure of the NoiseDHState type.
#define NOISE_ERROR_NO_MEMORY
Insufficient memory to complete the operation.
int noise_dhstate_is_ephemeral_only(const NoiseDHState *state)
Determine if a DHState object only supports ephemeral keys.
#define NOISE_ERROR_UNKNOWN_NAME
Algorithm name is unknown.
size_t size
Total size of the structure including subclass state.
#define NOISE_ERROR_INVALID_LENGTH
Invalid length specified for a key, packet, etc.
#define NOISE_DH_NEWHOPE
Diffie-Hellman identifier for "NewHope" (post-quantum, ephemeral key exchanges only).
uint8_t key_type
The type of key stored within this DHState object.
uint8_t ephemeral_only
Non-zero if this algorithm only supports ephemeral keys.
#define NOISE_ERROR_INVALID_PRIVATE_KEY
Invalid private key value.
int noise_dhstate_has_keypair(const NoiseDHState *state)
Determine if a DHState object contains a keypair.
#define NOISE_ROLE_INITIATOR
This end of the communications is the initiator.
int noise_dhstate_set_null_public_key(NoiseDHState *state)
Sets the public key in a DHState object to the special null value.
int noise_dhstate_calculate(const NoiseDHState *private_key_state, const NoiseDHState *public_key_state, uint8_t *shared_key, size_t shared_key_len)
Performs a Diffie-Hellman calculation.
int noise_name_to_id(int category, const char *name, size_t name_len)
Maps an algorithm name to the corresponding identifier.
int noise_dhstate_set_keypair(NoiseDHState *state, const uint8_t *private_key, size_t private_key_len, const uint8_t *public_key, size_t public_key_len)
Sets the keypair within a DHState object.
#define NOISE_ERROR_NOT_APPLICABLE
An option was supplied that was not applicable to the selected protocol.
int(* calculate)(const NoiseDHState *private_key_state, const NoiseDHState *public_key_state, uint8_t *shared_key)
Performs a Diffie-Hellman calculation.
Internal definitions for the library.
#define NOISE_ROLE_RESPONDER
This end of the communications is the responder.
int noise_dhstate_free(NoiseDHState *state)
Frees a DHState object after destroying all sensitive material.
#define NOISE_DH_CURVE25519
Diffie-Hellman identifier for "25519".
void noise_free(void *ptr, size_t size)
Destroys the contents of a block of memory and free it.
int noise_dhstate_generate_keypair(NoiseDHState *state)
Generates a new key pair within a DHState object.
#define NOISE_DH_NONE
Diffie-Hellman identifier that indicates "no DH".
int(* copy)(NoiseDHState *state, const NoiseDHState *from, const NoiseDHState *other)
Copies another key into this object.
int noise_dhstate_has_public_key(const NoiseDHState *state)
Determine if a DHState object contains a public key.
#define NOISE_KEY_TYPE_PUBLIC
int noise_dhstate_is_null_public_key(const NoiseDHState *state)
Determine if the public key in a DHState object has the special null value.
int noise_dhstate_new_by_name(NoiseDHState **state, const char *name)
Creates a new DHState object by its algorithm name.
uint16_t private_key_len
Length of the private key for this algorithm in bytes.
int(* generate_keypair)(NoiseDHState *state, const NoiseDHState *other)
Generates a new key pair for this Diffie-Hellman algorithm.
short dh_id
Algorithm identifier for the Diffie-Hellman operation.
int noise_dhstate_copy(NoiseDHState *state, const NoiseDHState *from)
Copies the keys from one DHState object to another.
size_t noise_dhstate_get_private_key_length(const NoiseDHState *state)
Gets the length of the private key for a DHState object.
int noise_dhstate_set_keypair_private(NoiseDHState *state, const uint8_t *private_key, size_t private_key_len)
Sets the keypair within a DHState object based on a private key only.
int noise_dhstate_set_public_key(NoiseDHState *state, const uint8_t *public_key, size_t public_key_len)
Sets the public key in a DHState object.
int noise_dhstate_set_role(NoiseDHState *state, int role)
Sets the role that a DHState object will play in a handshake.
int noise_dhstate_generate_dependent_keypair(NoiseDHState *state, const NoiseDHState *other)
Generates a new key pair within a DHState object that may depend upon the parameters from another DHS...
uint8_t * private_key
Points to the private key in the subclass state.
short role
The role; either initiator or responder or zero.
uint16_t public_key_len
Length of the public key for this algorithm in bytes.