Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a noise_cipherstate_get_nonce test function #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/noise/protocol/cipherstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ int noise_cipherstate_decrypt_with_ad
int noise_cipherstate_encrypt(NoiseCipherState *state, NoiseBuffer *buffer);
int noise_cipherstate_decrypt(NoiseCipherState *state, NoiseBuffer *buffer);
int noise_cipherstate_set_nonce(NoiseCipherState *state, uint64_t nonce);
int noise_cipherstate_get_nonce(const NoiseCipherState *state, uint64_t *nonce);
int noise_cipherstate_get_max_key_length(void);
int noise_cipherstate_get_max_mac_length(void);

Expand Down
29 changes: 29 additions & 0 deletions src/protocol/cipherstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,35 @@ int noise_cipherstate_set_nonce(NoiseCipherState *state, uint64_t nonce)
return NOISE_ERROR_NONE;
}

/**
* \brief Gets the nonce value for this cipherstate object.
*
* \param state The CipherState object.
* \param nonce The nonce value to get.
*
* \return NOISE_ERROR_NONE on success.
* \return NOISE_ERROR_INVALID_PARAM if \a state or \a nonce is NULL.
* \return NOISE_ERROR_INVALID_STATE if the key has not been set yet.
*
* \warning This function is intended for testing purposes only.
*
* \sa noise_cipherstate_init_key()
*/
int noise_cipherstate_get_nonce(const NoiseCipherState *state, uint64_t * nonce)
{
/* Bail out if the state or the nonce is NULL */
if (!state || !nonce)
return NOISE_ERROR_INVALID_PARAM;

/* If the key hasn't been set yet, we cannot do this */
if (!state->has_key)
return NOISE_ERROR_INVALID_STATE;

/* Set the nonce param and return */
*nonce = state->n;
return NOISE_ERROR_NONE;
}

/**
* \brief Gets the maximum key length for the supported algorithms.
*
Expand Down