Noise-C
|
Typedefs | |
typedef struct NoiseDHState_s | NoiseDHState |
Opaque object that represents a DHState. More... | |
Functions | |
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. More... | |
int | noise_dhstate_clear_key (NoiseDHState *state) |
Clears the key in a DHState object. More... | |
int | noise_dhstate_copy (NoiseDHState *state, const NoiseDHState *from) |
Copies the keys from one DHState object to another. More... | |
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. More... | |
int | noise_dhstate_free (NoiseDHState *state) |
Frees a DHState object after destroying all sensitive material. More... | |
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 DHState object. More... | |
int | noise_dhstate_generate_keypair (NoiseDHState *state) |
Generates a new key pair within a DHState object. More... | |
int | noise_dhstate_get_dh_id (const NoiseDHState *state) |
Gets the algorithm identifier for a DHState object. More... | |
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. More... | |
size_t | noise_dhstate_get_private_key_length (const NoiseDHState *state) |
Gets the length of the private key for a DHState object. More... | |
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. More... | |
size_t | noise_dhstate_get_public_key_length (const NoiseDHState *state) |
Gets the length of the public key for a DHState object. More... | |
int | noise_dhstate_get_role (const NoiseDHState *state) |
Gets the role that a DHState object will play in a handshake. More... | |
size_t | noise_dhstate_get_shared_key_length (const NoiseDHState *state) |
Gets the length of the shared key for a DHState object. More... | |
int | noise_dhstate_has_keypair (const NoiseDHState *state) |
Determine if a DHState object contains a keypair. More... | |
int | noise_dhstate_has_public_key (const NoiseDHState *state) |
Determine if a DHState object contains a public key. More... | |
int | noise_dhstate_is_ephemeral_only (const NoiseDHState *state) |
Determine if a DHState object only supports ephemeral keys. More... | |
int | noise_dhstate_is_null_public_key (const NoiseDHState *state) |
Determine if the public key in a DHState object has the special null value. More... | |
int | noise_dhstate_new_by_id (NoiseDHState **state, int id) |
Creates a new DHState object by its algorithm identifier. More... | |
int | noise_dhstate_new_by_name (NoiseDHState **state, const char *name) |
Creates a new DHState object by its algorithm name. More... | |
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. More... | |
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. More... | |
int | noise_dhstate_set_null_public_key (NoiseDHState *state) |
Sets the public key in a DHState object to the special null value. More... | |
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. More... | |
int | noise_dhstate_set_role (NoiseDHState *state, int role) |
Sets the role that a DHState object will play in a handshake. More... | |
DHState objects are used to store the keypairs for the local party or the public keys for remote parties. Once the keys have been set, noise_dhstate_calculate() can be used to perform a Diffie-Hellman operation with two DHState objects.
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.
private_key_state | Points to the DHState containing the private key. |
public_key_state | Points to the DHState containing the public key. |
shared_key | Points to the shared key on exit. |
shared_key_len | The length of the shared_key buffer in bytes. |
If the input public key is the special null value, then the output shared_key will also be the null value and NOISE_ERROR_NONE will be returned.
int noise_dhstate_clear_key | ( | NoiseDHState * | state | ) |
Clears the key in a DHState object.
state | The DHState object. |
int noise_dhstate_copy | ( | NoiseDHState * | state, |
const NoiseDHState * | from | ||
) |
Copies the keys from one DHState object to another.
state | The DHState to copy into. |
from | The DHState to copy from. |
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.
state | The DHState object. |
fingerprint_type | The type of fingerprint to format, NOISE_FINGERPRINT_BASIC or NOISE_FINGERPRINT_FULL. |
buffer | The buffer to write the fingerprint string to, including a terminating NUL. |
len | The length of buffer in bytes. |
Fingerprints are created by hashing the public key with SHA256 and then formatting the value in hexadecimal with bytes separated by colons. If the fingerprint_type is NOISE_FINGERPRINT_BASIC, then the SHA256 hash value is truncated to the first 16 bytes. If the type is NOISE_FINGERPRINT_FULL, then the entire 32 byte hash value is formatted.
int noise_dhstate_free | ( | NoiseDHState * | state | ) |
Frees a DHState object after destroying all sensitive material.
state | The DHState object to free. |
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 DHState object.
state | The DHState object. |
other | The other DHState object to obtain parameters from, which may be NULL. |
This function is intended for generating ephemeral keypairs for algorithms like New Hope where the keypair for Bob depends upon parameters that are transmitted in Alice's public key. If the algorithm does not require dependent parameters to generate the keypair, other is ignored.
int noise_dhstate_generate_keypair | ( | NoiseDHState * | state | ) |
Generates a new key pair within a DHState object.
state | The DHState object. |
int noise_dhstate_get_dh_id | ( | const NoiseDHState * | state | ) |
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.
state | The DHState object. |
private_key | Points to the buffer to receive the private key. |
private_key_len | The private key buffer length in bytes. |
public_key | Points to the buffer to receive the public key. |
public_key_len | The public key buffer length in bytes. |
size_t noise_dhstate_get_private_key_length | ( | const NoiseDHState * | state | ) |
Gets the length of the private key for a DHState object.
state | The DHState object. |
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.
state | The DHState object. |
public_key | The buffer to receive the public key value. |
public_key_len | The public key length in bytes. |
size_t noise_dhstate_get_public_key_length | ( | const NoiseDHState * | state | ) |
Gets the length of the public key for a DHState object.
state | The DHState object. |
int noise_dhstate_get_role | ( | const NoiseDHState * | state | ) |
Gets the role that a DHState object will play in a handshake.
state | The DHState object. |
size_t noise_dhstate_get_shared_key_length | ( | const NoiseDHState * | state | ) |
Gets the length of the shared key for a DHState object.
state | The DHState object. |
int noise_dhstate_has_keypair | ( | const NoiseDHState * | state | ) |
Determine if a DHState object contains a keypair.
state | The DHState object. |
int noise_dhstate_has_public_key | ( | const NoiseDHState * | state | ) |
Determine if a DHState object contains a public key.
state | The DHState object. |
int noise_dhstate_is_ephemeral_only | ( | const NoiseDHState * | state | ) |
Determine if a DHState object only supports ephemeral keys.
state | The DHState object. |
Some algorithms like "NewHope" can only be used to generate ephemeral keys during a session and have no support for long-term static keys.
int noise_dhstate_is_null_public_key | ( | const NoiseDHState * | state | ) |
Determine if the public key in a DHState object has the special null value.
state | The DHState object. |
int noise_dhstate_new_by_id | ( | NoiseDHState ** | state, |
int | id | ||
) |
Creates a new DHState object by its algorithm identifier.
state | Points to the variable where to store the pointer to the new DHState object. |
id | The algorithm identifier; NOISE_DH_CURVE25519, NOISE_DH_CURVE448, etc. |
int noise_dhstate_new_by_name | ( | NoiseDHState ** | state, |
const char * | name | ||
) |
Creates a new DHState object by its algorithm name.
state | Points to the variable where to store the pointer to the new DHState object. |
name | The name of the Diffie-Hellman algorithm; e.g. "25519". This string must be NUL-terminated. |
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.
state | The DHState object. |
private_key | Points to the private key. |
private_key_len | The private key length in bytes. |
public_key | Points to the public key. |
public_key_len | The public key length in bytes. |
The algorithm may decide to defer NOISE_ERROR_INVALID_PRIVATE_KEY or NOISE_ERROR_INVALID_PUBLIC_KEY to later when the keypair is actually used during noise_dhstate_calculate().
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.
state | The DHState object. |
private_key | Points to the private key. |
private_key_len | The private key length in bytes. |
The algorithm may decide to defer NOISE_ERROR_INVALID_PRIVATE_KEY or NOISE_ERROR_INVALID_PUBLIC_KEY to later when the keypair is actually used during noise_dhstate_calculate().
This function only takes the private key as an argument. The public key in the keypair is derived from the private key.
int noise_dhstate_set_null_public_key | ( | NoiseDHState * | state | ) |
Sets the public key in a DHState object to the special null value.
state | The DHState object. |
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.
state | The DHState object. |
public_key | Points to the public key. |
public_key_len | The public key length in bytes. |
After this function succeeds, the DHState will only contain a public key. Any existing private key will be cleared. Thus, this function is useful to set the public key of a remote party. Use noise_dhstate_set_keypair() to set both the public and private key for the local party.
The algorithm may decide to defer NOISE_ERROR_INVALID_PUBLIC_KEY to later when the public key is actually used during noise_dhstate_calculate().
int noise_dhstate_set_role | ( | NoiseDHState * | state, |
int | role | ||
) |
Sets the role that a DHState object will play in a handshake.
state | The DHState object. |
role | The role, NOISE_ROLE_INITIATOR or NOISE_ROLE_RESPONDER, or zero if the role is unspecified. |
This function is intended for use with algorithms that have a different method for calculating public keys and shared secrets for the two parties in a communication. An example is the post-quantum SIDH algorithm where "Alice" and "Bob" differ in the calculations they perform.
To assist with supporting such algorithms, the HandshakeState labels DHState objects as either initiator or responder depending upon who owns that specific key. The algorithm-specific back end can then use the role information to determine which object it wants to treat as "Alice" and which object should be treated as "Bob".