58 static int noise_symmetricstate_new
99 name_len = strlen(name);
100 if (name_len <= hash_len) {
101 memcpy(new_state->
h, name, name_len);
102 memset(new_state->
h + name_len, 0, hash_len - name_len);
105 (new_state->
hash, (
const uint8_t *)name, name_len,
106 new_state->
h, hash_len);
108 memcpy(new_state->
ck, new_state->
h, hash_len);
154 return noise_symmetricstate_new(state, name,
id);
190 name_len = strlen(name);
196 return noise_symmetricstate_new(state, name, &
id);
270 if (!state || !input)
281 (state->
hash, state->
ck, hash_len, input, size,
282 state->
ck, hash_len, temp_k, key_len);
309 if (!state || !input)
319 (state->
hash, state->
h, hash_len, input, size, state->
h, hash_len);
359 if (!state || !buffer || !(buffer->
data))
369 (state->
cipher, state->
h, hash_len, buffer);
410 if (!state || !buffer || !(buffer->
data))
430 (state->
hash, state->
h, hash_len,
431 buffer->
data, buffer->
size, temp, hash_len);
435 (state->
cipher, state->
h, hash_len, buffer);
442 memcpy(state->
h, temp, hash_len);
540 (state->
hash, state->
ck, hash_len, state->
ck, 0,
541 temp_k1, key_len, temp_k2, key_len);
Noise protocol name broken out into separate identifier fields.
#define NOISE_MAX_PAYLOAD_LEN
Maximum payload length for Noise packets.
int noise_cipherstate_init_key(NoiseCipherState *state, const uint8_t *key, size_t key_len)
Initializes the key on a CipherState object.
void noise_clean(void *data, size_t size)
Cleans a block of memory to destroy its contents.
#define NOISE_ERROR_INVALID_STATE
Operation cannot be performed in the current state.
uint8_t ck[NOISE_MAX_HASHLEN]
Current value of the chaining key for the handshake.
NoiseHashState * hash
Points to the HashState object for this SymmetricState.
#define NOISE_ERROR_INVALID_PARAM
Invalid parameter to function; e.g. a NULL value.
NoiseProtocolId id
Algorithm identifiers for the components of the protocol.
#define NOISE_ERROR_NONE
Success, no error.
size_t size
Total size of the structure.
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_protocol_name_to_id(NoiseProtocolId *id, const char *name, size_t name_len)
Parses a protocol name into a set of identifiers for the algorithms that are indicated by the name...
int noise_cipherstate_free(NoiseCipherState *state)
Frees a CipherState object after destroying all sensitive material.
int noise_symmetricstate_mix_key(NoiseSymmetricState *state, const uint8_t *input, size_t size)
Mixes new input data into the chaining key.
uint8_t h[NOISE_MAX_HASHLEN]
Current value of the handshake hash.
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.
int noise_symmetricstate_get_protocol_id(const NoiseSymmetricState *state, NoiseProtocolId *id)
Gets the protocol identifier associated with a SymmetricState object.
int noise_hashstate_new_by_id(NoiseHashState **state, int id)
Creates a new HashState object by its algorithm identifier.
#define NOISE_MAX_HASHLEN
Maximum hash length over all supported hash algorithms.
int noise_hashstate_hash_one(NoiseHashState *state, const uint8_t *data, size_t data_len, uint8_t *hash, size_t hash_len)
Hashes a single data buffer and returns the hash value.
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.
NoiseCipherState *(* create)(void)
Creates a new CipherState of the same type as this one.
#define NOISE_MAX_PROTOCOL_NAME
Maximum length of a protocol name string.
#define NOISE_ERROR_INVALID_LENGTH
Invalid length specified for a key, packet, etc.
NoiseCipherState * cipher
Points to the CipherState object for this SymmetricState.
int noise_symmetricstate_free(NoiseSymmetricState *state)
Frees a SymmetricState object after destroying all sensitive material.
Internal structure of the NoiseSymmetricState type.
int noise_hashstate_hkdf(NoiseHashState *state, const uint8_t *key, size_t key_len, const uint8_t *data, size_t data_len, uint8_t *output1, size_t output1_len, uint8_t *output2, size_t output2_len)
Hashes input data with a key to generate two output values.
size_t noise_symmetricstate_get_mac_length(const NoiseSymmetricState *state)
Gets the current length of packet MAC values for a SymmetricState object.
int noise_symmetricstate_new_by_id(NoiseSymmetricState **state, const NoiseProtocolId *id)
Creates a new SymmetricState object from a protocol identifier.
int noise_symmetricstate_mix_hash(NoiseSymmetricState *state, const uint8_t *input, size_t size)
Mixes new input data into the handshake hash.
#define NOISE_ERROR_NOT_APPLICABLE
An option was supplied that was not applicable to the selected protocol.
Internal definitions for the library.
int noise_symmetricstate_encrypt_and_hash(NoiseSymmetricState *state, NoiseBuffer *buffer)
Encrypts a block of data with this SymmetricState object and adds the ciphertext to the handshake has...
void noise_free(void *ptr, size_t size)
Destroys the contents of a block of memory and free it.
Internal structure of the NoiseCipherState type.
int noise_hashstate_free(NoiseHashState *state)
Frees a HashState object after destroying all sensitive material.
#define noise_new(type)
Allocates an object from the system and initializes it.
int noise_cipherstate_new_by_id(NoiseCipherState **state, int id)
Creates a new CipherState object by its algorithm identifier.
size_t noise_hashstate_get_hash_length(const NoiseHashState *state)
Gets the length of the hash output for a HashState object.
int noise_protocol_id_to_name(char *name, size_t name_len, const NoiseProtocolId *id)
Formats a protocol name from a set of identifiers for the algorithms that make up the name...
int noise_hashstate_hash_two(NoiseHashState *state, const uint8_t *data1, size_t data1_len, const uint8_t *data2, size_t data2_len, uint8_t *hash, size_t hash_len)
Hashes the concatenation of two data buffers and returns the combined hash value. ...
size_t size
Total size of the structure including subclass state.
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.
int noise_symmetricstate_split(NoiseSymmetricState *state, NoiseCipherState **c1, NoiseCipherState **c2)
Splits the transport encryption CipherState objects out of this SymmetricState object.
int noise_symmetricstate_new_by_name(NoiseSymmetricState **state, const char *name)
Creates a new SymmetricState object from a protocol name.
int noise_symmetricstate_decrypt_and_hash(NoiseSymmetricState *state, NoiseBuffer *buffer)
Decrypts a block of data with this SymmetricState object and adds the ciphertext to the handshake has...
Type that defines a region of memory for a data buffer.