54 #define NOISE_MAX_KEY_LEN 32
57 #define NOISE_MAX_MAC_LEN 16
87 *state = noise_chachapoly_new();
190 return state ? state->
key_len : 0;
204 return state ? state->
mac_len : 0;
249 return state ? state->
has_key : 0;
300 if (!state || (!ad && ad_len) || !buffer || !(buffer->
data))
321 if (state->
n == 0xFFFFFFFFFFFFFFFFULL)
325 err = (*(state->
encrypt))(state, ad, ad_len, buffer->
data, buffer->
size);
380 if (!state || (!ad && ad_len) || !buffer || !(buffer->
data))
396 if (state->
n == 0xFFFFFFFFFFFFFFFFULL)
528 if (state->
n > nonce)
543 return NOISE_MAX_KEY_LEN;
553 return NOISE_MAX_MAC_LEN;
#define NOISE_MAX_PAYLOAD_LEN
Maximum payload length for Noise packets.
int noise_cipherstate_decrypt(NoiseCipherState *state, NoiseBuffer *buffer)
Decrypts a block of data with this CipherState object.
int(* decrypt)(NoiseCipherState *state, const uint8_t *ad, size_t ad_len, uint8_t *data, size_t len)
Decrypts data with this CipherState.
#define NOISE_ERROR_UNKNOWN_ID
Algorithm identifier is unknown.
uint8_t mac_len
Length of the MAC for this cipher in bytes.
int(* encrypt)(NoiseCipherState *state, const uint8_t *ad, size_t ad_len, uint8_t *data, size_t len)
Encrypts data with this CipherState.
int noise_cipherstate_init_key(NoiseCipherState *state, const uint8_t *key, size_t key_len)
Initializes the key on a CipherState object.
#define NOISE_ERROR_INVALID_STATE
Operation cannot be performed in the current state.
int noise_cipherstate_get_cipher_id(const NoiseCipherState *state)
Gets the algorithm identifier for a CipherState object.
#define NOISE_ERROR_INVALID_PARAM
Invalid parameter to function; e.g. a NULL value.
NoiseCipherState * noise_aesgcm_new(void)
Creates a new AES-GCM CipherState object.
#define NOISE_ERROR_NONE
Success, no error.
#define NOISE_CIPHER_AESGCM
Cipher identifier for "AESGCM".
int noise_cipherstate_set_nonce(NoiseCipherState *state, uint64_t nonce)
Sets the nonce value for this cipherstate object.
uint8_t has_key
Non-zero if the key has been set on this cipher.
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.
int noise_cipherstate_free(NoiseCipherState *state)
Frees a CipherState object after destroying all sensitive material.
int noise_cipherstate_get_max_mac_length(void)
Gets the maximum MAC length for the supported algorithms.
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.
size_t noise_cipherstate_get_mac_length(const NoiseCipherState *state)
Gets the length of packet MAC values for a CipherState object.
#define NOISE_ERROR_NO_MEMORY
Insufficient memory to complete the operation.
uint8_t key_len
Length of the key for this cipher in bytes.
#define NOISE_ERROR_UNKNOWN_NAME
Algorithm name is unknown.
#define NOISE_CIPHER_CHACHAPOLY
Cipher identifier for "ChaChaPoly".
uint64_t n
The nonce value for the next packet.
#define NOISE_ERROR_INVALID_LENGTH
Invalid length specified for a key, packet, etc.
int cipher_id
Algorithm identifier for the cipher.
int noise_name_to_id(int category, const char *name, size_t name_len)
Maps an algorithm name to the corresponding identifier.
#define NOISE_CIPHER_CATEGORY
Category for cipher algorithms.
Internal definitions for the library.
void noise_free(void *ptr, size_t size)
Destroys the contents of a block of memory and free it.
size_t size
Total size of the structure including subclass state.
Internal structure of the NoiseCipherState type.
void(* destroy)(NoiseCipherState *state)
Destroys this CipherState prior to the memory being freed.
int noise_cipherstate_get_max_key_length(void)
Gets the maximum key length for the supported algorithms.
#define NOISE_ERROR_INVALID_NONCE
Invalid nonce value.
int noise_cipherstate_new_by_name(NoiseCipherState **state, const char *name)
Creates a new CipherState object by its algorithm name.
void(* init_key)(NoiseCipherState *state, const uint8_t *key)
Sets the key for this CipherState.
int noise_cipherstate_new_by_id(NoiseCipherState **state, int id)
Creates a new CipherState object by its algorithm identifier.
int noise_cipherstate_encrypt(NoiseCipherState *state, NoiseBuffer *buffer)
Encrypts a block of data with this CipherState object.
int noise_cipherstate_has_key(const NoiseCipherState *state)
Determine if the key has been set on a CipherState object.
size_t noise_cipherstate_get_key_length(const NoiseCipherState *state)
Gets the length of the encryption key for a CipherState object.
#define NOISE_CIPHER_NONE
Cipher identifier that indicates "no cipher".
Type that defines a region of memory for a data buffer.