diff --git a/ref/fips202.c b/ref/fips202.c index c710c06a..020a9b13 100644 --- a/ref/fips202.c +++ b/ref/fips202.c @@ -711,162 +711,3 @@ void shake256(uint8_t *output, size_t outlen, } shake256_ctx_release(&s); } - -void sha3_256_inc_init(sha3_256incctx *state) { - keccak_inc_init(state->ctx); -} - -void sha3_256_inc_ctx_clone(sha3_256incctx *dest, const sha3_256incctx *src) { - memcpy(dest->ctx, src->ctx, SPX_SHAKEINCCTX_BYTES); -} - -void sha3_256_inc_ctx_release(sha3_256incctx *state) { - (void)state; // avoid unused variable warnings -} - -void sha3_256_inc_absorb(sha3_256incctx *state, const uint8_t *input, size_t inlen) { - keccak_inc_absorb(state->ctx, SHA3_256_RATE, input, inlen); -} - -void sha3_256_inc_finalize(uint8_t *output, sha3_256incctx *state) { - uint8_t t[SHA3_256_RATE]; - keccak_inc_finalize(state->ctx, SHA3_256_RATE, 0x06); - - keccak_squeezeblocks(t, 1, state->ctx, SHA3_256_RATE); - - sha3_256_inc_ctx_release(state); - - for (size_t i = 0; i < 32; i++) { - output[i] = t[i]; - } -} - -/************************************************* - * Name: sha3_256 - * - * Description: SHA3-256 with non-incremental API - * - * Arguments: - uint8_t *output: pointer to output - * - const uint8_t *input: pointer to input - * - size_t inlen: length of input in bytes - **************************************************/ -void sha3_256(uint8_t *output, const uint8_t *input, size_t inlen) { - uint64_t s[25]; - uint8_t t[SHA3_256_RATE]; - - /* Absorb input */ - keccak_absorb(s, SHA3_256_RATE, input, inlen, 0x06); - - /* Squeeze output */ - keccak_squeezeblocks(t, 1, s, SHA3_256_RATE); - - for (size_t i = 0; i < 32; i++) { - output[i] = t[i]; - } -} - -void sha3_384_inc_init(sha3_384incctx *state) { - keccak_inc_init(state->ctx); -} - -void sha3_384_inc_ctx_clone(sha3_384incctx *dest, const sha3_384incctx *src) { - memcpy(dest->ctx, src->ctx, SPX_SHAKEINCCTX_BYTES); -} - -void sha3_384_inc_absorb(sha3_384incctx *state, const uint8_t *input, size_t inlen) { - keccak_inc_absorb(state->ctx, SHA3_384_RATE, input, inlen); -} - -void sha3_384_inc_ctx_release(sha3_384incctx *state) { - (void)state; // avoid unused variable warnings -} - -void sha3_384_inc_finalize(uint8_t *output, sha3_384incctx *state) { - uint8_t t[SHA3_384_RATE]; - keccak_inc_finalize(state->ctx, SHA3_384_RATE, 0x06); - - keccak_squeezeblocks(t, 1, state->ctx, SHA3_384_RATE); - - sha3_384_inc_ctx_release(state); - - for (size_t i = 0; i < 48; i++) { - output[i] = t[i]; - } -} - -/************************************************* - * Name: sha3_384 - * - * Description: SHA3-256 with non-incremental API - * - * Arguments: - uint8_t *output: pointer to output - * - const uint8_t *input: pointer to input - * - size_t inlen: length of input in bytes - **************************************************/ -void sha3_384(uint8_t *output, const uint8_t *input, size_t inlen) { - uint64_t s[25]; - uint8_t t[SHA3_384_RATE]; - - /* Absorb input */ - keccak_absorb(s, SHA3_384_RATE, input, inlen, 0x06); - - /* Squeeze output */ - keccak_squeezeblocks(t, 1, s, SHA3_384_RATE); - - for (size_t i = 0; i < 48; i++) { - output[i] = t[i]; - } -} - -void sha3_512_inc_init(sha3_512incctx *state) { - keccak_inc_init(state->ctx); -} - -void sha3_512_inc_ctx_clone(sha3_512incctx *dest, const sha3_512incctx *src) { - memcpy(dest->ctx, src->ctx, SPX_SHAKEINCCTX_BYTES); -} - -void sha3_512_inc_absorb(sha3_512incctx *state, const uint8_t *input, size_t inlen) { - keccak_inc_absorb(state->ctx, SHA3_512_RATE, input, inlen); -} - -void sha3_512_inc_ctx_release(sha3_512incctx *state) { - (void)state; // avoid unused variable warnings -} - -void sha3_512_inc_finalize(uint8_t *output, sha3_512incctx *state) { - uint8_t t[SHA3_512_RATE]; - keccak_inc_finalize(state->ctx, SHA3_512_RATE, 0x06); - - keccak_squeezeblocks(t, 1, state->ctx, SHA3_512_RATE); - - sha3_512_inc_ctx_release(state); - - for (size_t i = 0; i < 64; i++) { - output[i] = t[i]; - } -} - -/************************************************* - * Name: sha3_512 - * - * Description: SHA3-512 with non-incremental API - * - * Arguments: - uint8_t *output: pointer to output - * - const uint8_t *input: pointer to input - * - size_t inlen: length of input in bytes - **************************************************/ -void sha3_512(uint8_t *output, const uint8_t *input, size_t inlen) { - uint64_t s[25]; - uint8_t t[SHA3_512_RATE]; - - /* Absorb input */ - keccak_absorb(s, SHA3_512_RATE, input, inlen, 0x06); - - /* Squeeze output */ - keccak_squeezeblocks(t, 1, s, SHA3_512_RATE); - - for (size_t i = 0; i < 64; i++) { - output[i] = t[i]; - } -} diff --git a/ref/fips202.h b/ref/fips202.h index 02215c5f..57beee59 100644 --- a/ref/fips202.h +++ b/ref/fips202.h @@ -34,21 +34,6 @@ typedef struct { uint64_t ctx[SPX_SHAKECTX_BYTES]; } shake256ctx; -// Context for incremental API -typedef struct { - uint64_t ctx[SPX_SHAKEINCCTX_BYTES]; -} sha3_256incctx; - -// Context for incremental API -typedef struct { - uint64_t ctx[SPX_SHAKEINCCTX_BYTES]; -} sha3_384incctx; - -// Context for incremental API -typedef struct { - uint64_t ctx[SPX_SHAKEINCCTX_BYTES]; -} sha3_512incctx; - /* Initialize the state and absorb the provided input. * * This function does not support being called multiple times @@ -123,45 +108,4 @@ void shake128(uint8_t *output, size_t outlen, void shake256(uint8_t *output, size_t outlen, const uint8_t *input, size_t inlen); -/* Initialize the incremental hashing state */ -void sha3_256_inc_init(sha3_256incctx *state); -/* Absorb blocks into SHA3 */ -void sha3_256_inc_absorb(sha3_256incctx *state, const uint8_t *input, size_t inlen); -/* Obtain the output of the function and free `state` */ -void sha3_256_inc_finalize(uint8_t *output, sha3_256incctx *state); -/* Copy the context */ -void sha3_256_inc_ctx_clone(sha3_256incctx *dest, const sha3_256incctx *src); -/* Release the state, don't use if `_finalize` has been used */ -void sha3_256_inc_ctx_release(sha3_256incctx *state); - -void sha3_256(uint8_t *output, const uint8_t *input, size_t inlen); - -/* Initialize the incremental hashing state */ -void sha3_384_inc_init(sha3_384incctx *state); -/* Absorb blocks into SHA3 */ -void sha3_384_inc_absorb(sha3_384incctx *state, const uint8_t *input, size_t inlen); -/* Obtain the output of the function and free `state` */ -void sha3_384_inc_finalize(uint8_t *output, sha3_384incctx *state); -/* Copy the context */ -void sha3_384_inc_ctx_clone(sha3_384incctx *dest, const sha3_384incctx *src); -/* Release the state, don't use if `_finalize` has been used */ -void sha3_384_inc_ctx_release(sha3_384incctx *state); - -/* One-stop SHA3-384 shop */ -void sha3_384(uint8_t *output, const uint8_t *input, size_t inlen); - -/* Initialize the incremental hashing state */ -void sha3_512_inc_init(sha3_512incctx *state); -/* Absorb blocks into SHA3 */ -void sha3_512_inc_absorb(sha3_512incctx *state, const uint8_t *input, size_t inlen); -/* Obtain the output of the function and free `state` */ -void sha3_512_inc_finalize(uint8_t *output, sha3_512incctx *state); -/* Copy the context */ -void sha3_512_inc_ctx_clone(sha3_512incctx *dest, const sha3_512incctx *src); -/* Release the state, don't use if `_finalize` has been used */ -void sha3_512_inc_ctx_release(sha3_512incctx *state); - -/* One-stop SHA3-512 shop */ -void sha3_512(uint8_t *output, const uint8_t *input, size_t inlen); - #endif