Noise-C
|
Typedefs | |
typedef struct NoiseCipherState_s | NoiseCipherState |
Opaque object that represents a CipherState. More... | |
Functions | |
int | noise_cipherstate_decrypt (NoiseCipherState *state, NoiseBuffer *buffer) |
Decrypts a block of data with this CipherState object. More... | |
int | noise_cipherstate_decrypt_with_ad (NoiseCipherState *state, const uint8_t *ad, size_t ad_len, NoiseBuffer *buffer) |
Decrypts a block of data with this CipherState object. More... | |
int | noise_cipherstate_encrypt (NoiseCipherState *state, NoiseBuffer *buffer) |
Encrypts a block of data with this CipherState object. More... | |
int | noise_cipherstate_encrypt_with_ad (NoiseCipherState *state, const uint8_t *ad, size_t ad_len, NoiseBuffer *buffer) |
Encrypts a block of data with this CipherState object. More... | |
int | noise_cipherstate_free (NoiseCipherState *state) |
Frees a CipherState object after destroying all sensitive material. More... | |
int | noise_cipherstate_get_cipher_id (const NoiseCipherState *state) |
Gets the algorithm identifier for a CipherState object. More... | |
size_t | noise_cipherstate_get_key_length (const NoiseCipherState *state) |
Gets the length of the encryption key for a CipherState object. More... | |
size_t | noise_cipherstate_get_mac_length (const NoiseCipherState *state) |
Gets the length of packet MAC values for a CipherState object. More... | |
int | noise_cipherstate_get_max_key_length (void) |
Gets the maximum key length for the supported algorithms. More... | |
int | noise_cipherstate_get_max_mac_length (void) |
Gets the maximum MAC length for the supported algorithms. More... | |
int | noise_cipherstate_has_key (const NoiseCipherState *state) |
Determine if the key has been set on a CipherState object. More... | |
int | noise_cipherstate_init_key (NoiseCipherState *state, const uint8_t *key, size_t key_len) |
Initializes the key on a CipherState object. More... | |
int | noise_cipherstate_new_by_id (NoiseCipherState **state, int id) |
Creates a new CipherState object by its algorithm identifier. More... | |
int | noise_cipherstate_new_by_name (NoiseCipherState **state, const char *name) |
Creates a new CipherState object by its algorithm name. More... | |
int | noise_cipherstate_set_nonce (NoiseCipherState *state, uint64_t nonce) |
Sets the nonce value for this cipherstate object. More... | |
CipherState objects are used to encrypt or decrypt data during a session. Once the handshake has completed, noise_symmetricstate_split() will create two CipherState objects for encrypting packets sent to the other party, and decrypting packets received from the other party.
Opaque object that represents a CipherState.
Definition at line 32 of file cipherstate.h.
int noise_cipherstate_decrypt | ( | NoiseCipherState * | state, |
NoiseBuffer * | buffer | ||
) |
Decrypts a block of data with this CipherState object.
state | The CipherState object. |
buffer | The buffer containing the ciphertext plus MAC on entry and the plaintext on exit. |
This is a convenience function which decrypts the contents of a buffer without any associated data. It is otherwise identical to noise_cipherstate_decrypt_with_ad().
The ciphertext is decrypted in-place with the plaintext also written to buffer. In other words, it is assumed that the ciphertext plus MAC is in an input buffer ready to be processed once the MAC has been checked and the ciphertext has been decrypted.
The following example demonstrates how to initialize a buffer for use with this function. The message
is a byte array containing ciphertext_size
bytes of ciphertext plus MAC on entry. On exit, buffer.size
will contain the number of bytes of plaintext:
Definition at line 493 of file cipherstate.c.
int noise_cipherstate_decrypt_with_ad | ( | NoiseCipherState * | state, |
const uint8_t * | ad, | ||
size_t | ad_len, | ||
NoiseBuffer * | buffer | ||
) |
Decrypts a block of data with this CipherState object.
state | The CipherState object. |
ad | Points to the associated data, which can be NULL only if ad_len is zero. |
ad_len | The length of the associated data in bytes. |
buffer | The buffer containing the ciphertext plus MAC on entry and the plaintext on exit. |
The ciphertext is decrypted in-place with the plaintext also written to buffer. In other words, it is assumed that the ciphertext plus MAC is in an input buffer ready to be processed once the MAC has been checked and the ciphertext has been decrypted.
The following example demonstrates how to initialize a buffer for use with this function. The message
is a byte array containing ciphertext_size
bytes of ciphertext plus MAC on entry. On exit, buffer.size
will contain the number of bytes of plaintext:
Definition at line 374 of file cipherstate.c.
int noise_cipherstate_encrypt | ( | NoiseCipherState * | state, |
NoiseBuffer * | buffer | ||
) |
Encrypts a block of data with this CipherState object.
state | The CipherState object. |
buffer | The buffer containing the plaintext on entry and the ciphertext plus MAC on exit. |
This is a convenience function which encrypts the contents of a buffer without any associated data. It is otherwise identical to noise_cipherstate_encrypt_with_ad().
The plaintext is encrypted in-place with the ciphertext also written to buffer. There must be enough room on the end of buffer to hold the extra MAC value that will be appended. In other words, it is assumed that the plaintext is in an output buffer ready to be transmitted once the data has been encrypted and the final packet length has been determined.
The following example demonstrates how to initialize a buffer for use with this function. The message
is a byte array containing plaintext_size
bytes of plaintext on entry. On exit, buffer.size
will contain the number of bytes of ciphertext plus MAC to be transmitted:
Definition at line 451 of file cipherstate.c.
int noise_cipherstate_encrypt_with_ad | ( | NoiseCipherState * | state, |
const uint8_t * | ad, | ||
size_t | ad_len, | ||
NoiseBuffer * | buffer | ||
) |
Encrypts a block of data with this CipherState object.
state | The CipherState object. |
ad | Points to the associated data, which can be NULL only if ad_len is zero. |
ad_len | The length of the associated data in bytes. |
buffer | The buffer containing the plaintext on entry and the ciphertext plus MAC on exit. |
The plaintext is encrypted in-place with the ciphertext also written to buffer. There must be enough room on the end of buffer to hold the extra MAC value that will be appended. In other words, it is assumed that the plaintext is in an output buffer ready to be transmitted once the data has been encrypted and the final packet length has been determined.
The following example demonstrates how to initialize a buffer for use with this function. The message
is a byte array containing plaintext_size
bytes of plaintext on entry. On exit, buffer.size
will contain the number of bytes of ciphertext plus MAC to be transmitted:
Definition at line 294 of file cipherstate.c.
int noise_cipherstate_free | ( | NoiseCipherState * | state | ) |
Frees a CipherState object after destroying all sensitive material.
state | The CipherState object to free. |
Definition at line 152 of file cipherstate.c.
int noise_cipherstate_get_cipher_id | ( | const NoiseCipherState * | state | ) |
Gets the algorithm identifier for a CipherState object.
state | The CipherState object. |
Definition at line 174 of file cipherstate.c.
size_t noise_cipherstate_get_key_length | ( | const NoiseCipherState * | state | ) |
Gets the length of the encryption key for a CipherState object.
state | The CipherState object. |
Definition at line 188 of file cipherstate.c.
size_t noise_cipherstate_get_mac_length | ( | const NoiseCipherState * | state | ) |
Gets the length of packet MAC values for a CipherState object.
state | The CipherState object. |
Definition at line 202 of file cipherstate.c.
int noise_cipherstate_get_max_key_length | ( | void | ) |
Gets the maximum key length for the supported algorithms.
Definition at line 541 of file cipherstate.c.
int noise_cipherstate_get_max_mac_length | ( | void | ) |
Gets the maximum MAC length for the supported algorithms.
Definition at line 551 of file cipherstate.c.
int noise_cipherstate_has_key | ( | const NoiseCipherState * | state | ) |
Determine if the key has been set on a CipherState object.
state | The CipherState object. |
Definition at line 247 of file cipherstate.c.
int noise_cipherstate_init_key | ( | NoiseCipherState * | state, |
const uint8_t * | key, | ||
size_t | key_len | ||
) |
Initializes the key on a CipherState object.
state | The CipherState object. |
key | Points to the key. |
key_len | The length of the key in bytes. |
Definition at line 222 of file cipherstate.c.
int noise_cipherstate_new_by_id | ( | NoiseCipherState ** | state, |
int | id | ||
) |
Creates a new CipherState object by its algorithm identifier.
state | Points to the variable where to store the pointer to the new CipherState object. |
id | The algorithm identifier; NOISE_CIPHER_CHACHAPOLY, NOISE_CIPHER_AESGCM, etc. |
Definition at line 77 of file cipherstate.c.
int noise_cipherstate_new_by_name | ( | NoiseCipherState ** | state, |
const char * | name | ||
) |
Creates a new CipherState object by its algorithm name.
state | Points to the variable where to store the pointer to the new CipherState object. |
name | The name of the cipher algorithm; e.g. "ChaChaPoly". This string must be NUL-terminated. |
Definition at line 122 of file cipherstate.c.
int noise_cipherstate_set_nonce | ( | NoiseCipherState * | state, |
uint64_t | nonce | ||
) |
Sets the nonce value for this cipherstate object.
state | The CipherState object. |
nonce | The new nonce value to set. This must be greater than or equal to the current nonce value in the state. |
Definition at line 517 of file cipherstate.c.