Remove crypto_xof_*_final

This commit is contained in:
Frank Denis
2025-11-18 12:00:59 +01:00
parent 7f7873c21b
commit d11e907107
20 changed files with 32 additions and 158 deletions
@@ -32,7 +32,8 @@ shake128_ref_update(shake128_state_internal *state,
size_t i;
if (state->phase != SHAKE128_PHASE_ABSORBING) {
return -1; /* Cannot absorb after squeezing */
state->phase = SHAKE128_PHASE_ABSORBING;
state->offset = 0;
}
for (i = 0; i < inlen; i++) {
@@ -71,16 +72,6 @@ shake128_finalize(shake128_state_internal *state)
state->phase = SHAKE128_PHASE_SQUEEZING;
}
int
shake128_ref_final(shake128_state_internal *state, unsigned char *out, size_t outlen)
{
if (state->phase == SHAKE128_PHASE_ABSORBING) {
shake128_finalize(state);
}
return shake128_ref_squeeze(state, out, outlen);
}
int
shake128_ref_squeeze(shake128_state_internal *state, unsigned char *out, size_t outlen)
{
@@ -109,7 +100,7 @@ shake128_ref(unsigned char *out, size_t outlen, const unsigned char *in, unsigne
shake128_ref_init(&state);
shake128_ref_update(&state, in, inlen);
shake128_ref_final(&state, out, outlen);
shake128_ref_squeeze(&state, out, outlen);
return 0;
}
@@ -26,8 +26,6 @@ int shake128_ref_update(shake128_state_internal *state,
const unsigned char *in,
unsigned long long inlen);
int shake128_ref_final(shake128_state_internal *state, unsigned char *out, size_t outlen);
int shake128_ref_squeeze(shake128_state_internal *state, unsigned char *out, size_t outlen);
#endif /* shake128_ref_H */
@@ -61,14 +61,6 @@ crypto_xof_shake128_update(crypto_xof_shake128_state *state,
return shake128_ref_update(st, in, inlen);
}
int
crypto_xof_shake128_final(crypto_xof_shake128_state *state, unsigned char *out, size_t outlen)
{
shake128_state_internal *st = (shake128_state_internal *) (void *) state;
return shake128_ref_final(st, out, outlen);
}
int
crypto_xof_shake128_squeeze(crypto_xof_shake128_state *state, unsigned char *out, size_t outlen)
{
@@ -32,7 +32,8 @@ shake256_ref_update(shake256_state_internal *state,
size_t i;
if (state->phase != SHAKE256_PHASE_ABSORBING) {
return -1; /* Cannot absorb after squeezing */
state->phase = SHAKE256_PHASE_ABSORBING;
state->offset = 0;
}
for (i = 0; i < inlen; i++) {
@@ -71,16 +72,6 @@ shake256_finalize(shake256_state_internal *state)
state->phase = SHAKE256_PHASE_SQUEEZING;
}
int
shake256_ref_final(shake256_state_internal *state, unsigned char *out, size_t outlen)
{
if (state->phase == SHAKE256_PHASE_ABSORBING) {
shake256_finalize(state);
}
return shake256_ref_squeeze(state, out, outlen);
}
int
shake256_ref_squeeze(shake256_state_internal *state, unsigned char *out, size_t outlen)
{
@@ -109,7 +100,7 @@ shake256_ref(unsigned char *out, size_t outlen, const unsigned char *in, unsigne
shake256_ref_init(&state);
shake256_ref_update(&state, in, inlen);
shake256_ref_final(&state, out, outlen);
shake256_ref_squeeze(&state, out, outlen);
return 0;
}
@@ -26,8 +26,6 @@ int shake256_ref_update(shake256_state_internal *state,
const unsigned char *in,
unsigned long long inlen);
int shake256_ref_final(shake256_state_internal *state, unsigned char *out, size_t outlen);
int shake256_ref_squeeze(shake256_state_internal *state, unsigned char *out, size_t outlen);
#endif /* shake256_ref_H */
@@ -61,14 +61,6 @@ crypto_xof_shake256_update(crypto_xof_shake256_state *state,
return shake256_ref_update(st, in, inlen);
}
int
crypto_xof_shake256_final(crypto_xof_shake256_state *state, unsigned char *out, size_t outlen)
{
shake256_state_internal *st = (shake256_state_internal *) (void *) state;
return shake256_ref_final(st, out, outlen);
}
int
crypto_xof_shake256_squeeze(crypto_xof_shake256_state *state, unsigned char *out, size_t outlen)
{
@@ -32,7 +32,8 @@ turboshake128_ref_update(turboshake128_state_internal *state,
size_t i;
if (state->phase != TURBOSHAKE128_PHASE_ABSORBING) {
return -1; /* Cannot absorb after squeezing */
state->phase = TURBOSHAKE128_PHASE_ABSORBING;
state->offset = 0;
}
for (i = 0; i < inlen; i++) {
@@ -71,16 +72,6 @@ turboshake128_finalize(turboshake128_state_internal *state)
state->phase = TURBOSHAKE128_PHASE_SQUEEZING;
}
int
turboshake128_ref_final(turboshake128_state_internal *state, unsigned char *out, size_t outlen)
{
if (state->phase == TURBOSHAKE128_PHASE_ABSORBING) {
turboshake128_finalize(state);
}
return turboshake128_ref_squeeze(state, out, outlen);
}
int
turboshake128_ref_squeeze(turboshake128_state_internal *state, unsigned char *out, size_t outlen)
{
@@ -110,7 +101,7 @@ turboshake128_ref(unsigned char *out, size_t outlen, const unsigned char *in,
turboshake128_ref_init(&state);
turboshake128_ref_update(&state, in, inlen);
turboshake128_ref_final(&state, out, outlen);
turboshake128_ref_squeeze(&state, out, outlen);
return 0;
}
@@ -29,8 +29,6 @@ int turboshake128_ref_update(turboshake128_state_internal *state,
const unsigned char *in,
unsigned long long inlen);
int turboshake128_ref_final(turboshake128_state_internal *state, unsigned char *out, size_t outlen);
int turboshake128_ref_squeeze(turboshake128_state_internal *state, unsigned char *out,
size_t outlen);
@@ -62,15 +62,6 @@ crypto_xof_turboshake128_update(crypto_xof_turboshake128_state *state,
return turboshake128_ref_update(st, in, inlen);
}
int
crypto_xof_turboshake128_final(crypto_xof_turboshake128_state *state, unsigned char *out,
size_t outlen)
{
turboshake128_state_internal *st = (turboshake128_state_internal *) (void *) state;
return turboshake128_ref_final(st, out, outlen);
}
int
crypto_xof_turboshake128_squeeze(crypto_xof_turboshake128_state *state, unsigned char *out,
size_t outlen)
@@ -32,7 +32,8 @@ turboshake256_ref_update(turboshake256_state_internal *state,
size_t i;
if (state->phase != TURBOSHAKE256_PHASE_ABSORBING) {
return -1; /* Cannot absorb after squeezing */
state->phase = TURBOSHAKE256_PHASE_ABSORBING;
state->offset = 0;
}
for (i = 0; i < inlen; i++) {
@@ -71,16 +72,6 @@ turboshake256_finalize(turboshake256_state_internal *state)
state->phase = TURBOSHAKE256_PHASE_SQUEEZING;
}
int
turboshake256_ref_final(turboshake256_state_internal *state, unsigned char *out, size_t outlen)
{
if (state->phase == TURBOSHAKE256_PHASE_ABSORBING) {
turboshake256_finalize(state);
}
return turboshake256_ref_squeeze(state, out, outlen);
}
int
turboshake256_ref_squeeze(turboshake256_state_internal *state, unsigned char *out, size_t outlen)
{
@@ -110,7 +101,7 @@ turboshake256_ref(unsigned char *out, size_t outlen, const unsigned char *in,
turboshake256_ref_init(&state);
turboshake256_ref_update(&state, in, inlen);
turboshake256_ref_final(&state, out, outlen);
turboshake256_ref_squeeze(&state, out, outlen);
return 0;
}
@@ -29,8 +29,6 @@ int turboshake256_ref_update(turboshake256_state_internal *state,
const unsigned char *in,
unsigned long long inlen);
int turboshake256_ref_final(turboshake256_state_internal *state, unsigned char *out, size_t outlen);
int turboshake256_ref_squeeze(turboshake256_state_internal *state, unsigned char *out,
size_t outlen);
@@ -62,15 +62,6 @@ crypto_xof_turboshake256_update(crypto_xof_turboshake256_state *state,
return turboshake256_ref_update(st, in, inlen);
}
int
crypto_xof_turboshake256_final(crypto_xof_turboshake256_state *state, unsigned char *out,
size_t outlen)
{
turboshake256_state_internal *st = (turboshake256_state_internal *) (void *) state;
return turboshake256_ref_final(st, out, outlen);
}
int
crypto_xof_turboshake256_squeeze(crypto_xof_turboshake256_state *state, unsigned char *out,
size_t outlen)
@@ -44,10 +44,6 @@ int crypto_xof_shake128_update(crypto_xof_shake128_state *state,
const unsigned char *in,
unsigned long long inlen) __attribute__((nonnull(1)));
SODIUM_EXPORT
int crypto_xof_shake128_final(crypto_xof_shake128_state *state, unsigned char *out, size_t outlen)
__attribute__((nonnull));
SODIUM_EXPORT
int crypto_xof_shake128_squeeze(crypto_xof_shake128_state *state, unsigned char *out, size_t outlen)
__attribute__((nonnull));
@@ -43,10 +43,6 @@ int crypto_xof_shake256_update(crypto_xof_shake256_state *state,
const unsigned char *in,
unsigned long long inlen) __attribute__((nonnull(1)));
SODIUM_EXPORT
int crypto_xof_shake256_final(crypto_xof_shake256_state *state, unsigned char *out, size_t outlen)
__attribute__((nonnull));
SODIUM_EXPORT
int crypto_xof_shake256_squeeze(crypto_xof_shake256_state *state, unsigned char *out, size_t outlen)
__attribute__((nonnull));
@@ -43,10 +43,6 @@ int crypto_xof_turboshake128_update(crypto_xof_turboshake128_state *state,
const unsigned char *in,
unsigned long long inlen) __attribute__((nonnull(1)));
SODIUM_EXPORT
int crypto_xof_turboshake128_final(crypto_xof_turboshake128_state *state, unsigned char *out,
size_t outlen) __attribute__((nonnull));
SODIUM_EXPORT
int crypto_xof_turboshake128_squeeze(crypto_xof_turboshake128_state *state, unsigned char *out,
size_t outlen) __attribute__((nonnull));
@@ -43,10 +43,6 @@ int crypto_xof_turboshake256_update(crypto_xof_turboshake256_state *state,
const unsigned char *in,
unsigned long long inlen) __attribute__((nonnull(1)));
SODIUM_EXPORT
int crypto_xof_turboshake256_final(crypto_xof_turboshake256_state *state, unsigned char *out,
size_t outlen) __attribute__((nonnull));
SODIUM_EXPORT
int crypto_xof_turboshake256_squeeze(crypto_xof_turboshake256_state *state, unsigned char *out,
size_t outlen) __attribute__((nonnull));
+5 -13
View File
@@ -80,7 +80,7 @@ main(void)
for (i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
crypto_xof_shake128_init(&state);
crypto_xof_shake128_update(&state, vectors[i].msg, vectors[i].msg_len);
crypto_xof_shake128_final(&state, out, vectors[i].out_len);
crypto_xof_shake128_squeeze(&state, out, vectors[i].out_len);
if (memcmp(out, vectors[i].out, vectors[i].out_len) != 0) {
printf("Test vector %zu failed (streaming)\n", i);
return 1;
@@ -90,7 +90,7 @@ main(void)
/* Test multiple squeeze calls */
crypto_xof_shake128_init(&state);
crypto_xof_shake128_update(&state, msg_abc, 3);
crypto_xof_shake128_final(&state, out, 16);
crypto_xof_shake128_squeeze(&state, out, 16);
crypto_xof_shake128_squeeze(&state, out + 16, 16);
if (memcmp(out, out_abc_32, 32) != 0) {
printf("Multiple squeeze test failed\n");
@@ -100,11 +100,11 @@ main(void)
/* Test custom domain byte produces different output */
crypto_xof_shake128_init(&state);
crypto_xof_shake128_update(&state, msg_abc, 3);
crypto_xof_shake128_final(&state, out, 32);
crypto_xof_shake128_squeeze(&state, out, 32);
crypto_xof_shake128_init_with_domain(&state, 0x99);
crypto_xof_shake128_update(&state, msg_abc, 3);
crypto_xof_shake128_final(&state, out + 32, 32);
crypto_xof_shake128_squeeze(&state, out + 32, 32);
if (memcmp(out, out + 32, 32) == 0) {
printf("Custom domain byte test failed (outputs should differ)\n");
@@ -114,21 +114,13 @@ main(void)
/* Test standard domain constant */
crypto_xof_shake128_init_with_domain(&state, crypto_xof_shake128_domain_standard());
crypto_xof_shake128_update(&state, msg_abc, 3);
crypto_xof_shake128_final(&state, out + 64, 32);
crypto_xof_shake128_squeeze(&state, out + 64, 32);
if (memcmp(out, out + 64, 32) != 0) {
printf("Domain constant test failed (should match standard init)\n");
return 1;
}
/* Test cannot absorb after squeezing */
crypto_xof_shake128_init(&state);
crypto_xof_shake128_final(&state, out, 32);
if (crypto_xof_shake128_update(&state, msg_abc, 3) == 0) {
printf("Should not be able to absorb after squeezing\n");
return 1;
}
printf("All SHAKE-128 tests passed\n");
return 0;
}
+5 -13
View File
@@ -81,7 +81,7 @@ main(void)
for (i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
crypto_xof_shake256_init(&state);
crypto_xof_shake256_update(&state, vectors[i].msg, vectors[i].msg_len);
crypto_xof_shake256_final(&state, out, vectors[i].out_len);
crypto_xof_shake256_squeeze(&state, out, vectors[i].out_len);
if (memcmp(out, vectors[i].out, vectors[i].out_len) != 0) {
printf("Test vector %zu failed (streaming)\n", i);
return 1;
@@ -91,7 +91,7 @@ main(void)
/* Test multiple squeeze calls */
crypto_xof_shake256_init(&state);
crypto_xof_shake256_update(&state, msg_abc, 3);
crypto_xof_shake256_final(&state, out, 16);
crypto_xof_shake256_squeeze(&state, out, 16);
crypto_xof_shake256_squeeze(&state, out + 16, 16);
if (memcmp(out, out_abc_32, 32) != 0) {
printf("Multiple squeeze test failed\n");
@@ -101,11 +101,11 @@ main(void)
/* Test custom domain byte produces different output */
crypto_xof_shake256_init(&state);
crypto_xof_shake256_update(&state, msg_abc, 3);
crypto_xof_shake256_final(&state, out, 32);
crypto_xof_shake256_squeeze(&state, out, 32);
crypto_xof_shake256_init_with_domain(&state, 0x99);
crypto_xof_shake256_update(&state, msg_abc, 3);
crypto_xof_shake256_final(&state, out + 32, 32);
crypto_xof_shake256_squeeze(&state, out + 32, 32);
if (memcmp(out, out + 32, 32) == 0) {
printf("Custom domain byte test failed (outputs should differ)\n");
@@ -115,21 +115,13 @@ main(void)
/* Test standard domain constant */
crypto_xof_shake256_init_with_domain(&state, crypto_xof_shake256_domain_standard());
crypto_xof_shake256_update(&state, msg_abc, 3);
crypto_xof_shake256_final(&state, out + 64, 32);
crypto_xof_shake256_squeeze(&state, out + 64, 32);
if (memcmp(out, out + 64, 32) != 0) {
printf("Domain constant test failed (should match standard init)\n");
return 1;
}
/* Test cannot absorb after squeezing */
crypto_xof_shake256_init(&state);
crypto_xof_shake256_final(&state, out, 32);
if (crypto_xof_shake256_update(&state, msg_abc, 3) == 0) {
printf("Should not be able to absorb after squeezing\n");
return 1;
}
printf("All SHAKE-256 tests passed\n");
return 0;
}
+5 -13
View File
@@ -80,7 +80,7 @@ main(void)
for (i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
crypto_xof_turboshake128_init(&state);
crypto_xof_turboshake128_update(&state, vectors[i].msg, vectors[i].msg_len);
crypto_xof_turboshake128_final(&state, out, vectors[i].out_len);
crypto_xof_turboshake128_squeeze(&state, out, vectors[i].out_len);
if (memcmp(out, vectors[i].out, vectors[i].out_len) != 0) {
printf("Test vector %zu failed (streaming)\n", i);
return 1;
@@ -90,7 +90,7 @@ main(void)
/* Test multiple squeeze calls */
crypto_xof_turboshake128_init(&state);
crypto_xof_turboshake128_update(&state, msg_abc, 3);
crypto_xof_turboshake128_final(&state, out, 16);
crypto_xof_turboshake128_squeeze(&state, out, 16);
crypto_xof_turboshake128_squeeze(&state, out + 16, 16);
if (memcmp(out, out_abc_32, 32) != 0) {
printf("Multiple squeeze test failed\n");
@@ -100,11 +100,11 @@ main(void)
/* Test custom domain byte produces different output */
crypto_xof_turboshake128_init(&state);
crypto_xof_turboshake128_update(&state, msg_abc, 3);
crypto_xof_turboshake128_final(&state, out, 32);
crypto_xof_turboshake128_squeeze(&state, out, 32);
crypto_xof_turboshake128_init_with_domain(&state, 0x99);
crypto_xof_turboshake128_update(&state, msg_abc, 3);
crypto_xof_turboshake128_final(&state, out + 32, 32);
crypto_xof_turboshake128_squeeze(&state, out + 32, 32);
if (memcmp(out, out + 32, 32) == 0) {
printf("Custom domain byte test failed (outputs should differ)\n");
@@ -114,21 +114,13 @@ main(void)
/* Test standard domain constant */
crypto_xof_turboshake128_init_with_domain(&state, crypto_xof_turboshake128_domain_standard());
crypto_xof_turboshake128_update(&state, msg_abc, 3);
crypto_xof_turboshake128_final(&state, out + 64, 32);
crypto_xof_turboshake128_squeeze(&state, out + 64, 32);
if (memcmp(out, out + 64, 32) != 0) {
printf("Domain constant test failed (should match standard init)\n");
return 1;
}
/* Test cannot absorb after squeezing */
crypto_xof_turboshake128_init(&state);
crypto_xof_turboshake128_final(&state, out, 32);
if (crypto_xof_turboshake128_update(&state, msg_abc, 3) == 0) {
printf("Should not be able to absorb after squeezing\n");
return 1;
}
printf("All TurboSHAKE-128 tests passed\n");
return 0;
}
+5 -13
View File
@@ -80,7 +80,7 @@ main(void)
for (i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
crypto_xof_turboshake256_init(&state);
crypto_xof_turboshake256_update(&state, vectors[i].msg, vectors[i].msg_len);
crypto_xof_turboshake256_final(&state, out, vectors[i].out_len);
crypto_xof_turboshake256_squeeze(&state, out, vectors[i].out_len);
if (memcmp(out, vectors[i].out, vectors[i].out_len) != 0) {
printf("Test vector %zu failed (streaming)\n", i);
return 1;
@@ -90,7 +90,7 @@ main(void)
/* Test multiple squeeze calls */
crypto_xof_turboshake256_init(&state);
crypto_xof_turboshake256_update(&state, msg_abc, 3);
crypto_xof_turboshake256_final(&state, out, 16);
crypto_xof_turboshake256_squeeze(&state, out, 16);
crypto_xof_turboshake256_squeeze(&state, out + 16, 16);
if (memcmp(out, out_abc_32, 32) != 0) {
printf("Multiple squeeze test failed\n");
@@ -100,11 +100,11 @@ main(void)
/* Test custom domain byte produces different output */
crypto_xof_turboshake256_init(&state);
crypto_xof_turboshake256_update(&state, msg_abc, 3);
crypto_xof_turboshake256_final(&state, out, 32);
crypto_xof_turboshake256_squeeze(&state, out, 32);
crypto_xof_turboshake256_init_with_domain(&state, 0x99);
crypto_xof_turboshake256_update(&state, msg_abc, 3);
crypto_xof_turboshake256_final(&state, out + 32, 32);
crypto_xof_turboshake256_squeeze(&state, out + 32, 32);
if (memcmp(out, out + 32, 32) == 0) {
printf("Custom domain byte test failed (outputs should differ)\n");
@@ -114,21 +114,13 @@ main(void)
/* Test standard domain constant */
crypto_xof_turboshake256_init_with_domain(&state, crypto_xof_turboshake256_domain_standard());
crypto_xof_turboshake256_update(&state, msg_abc, 3);
crypto_xof_turboshake256_final(&state, out + 64, 32);
crypto_xof_turboshake256_squeeze(&state, out + 64, 32);
if (memcmp(out, out + 64, 32) != 0) {
printf("Domain constant test failed (should match standard init)\n");
return 1;
}
/* Test cannot absorb after squeezing */
crypto_xof_turboshake256_init(&state);
crypto_xof_turboshake256_final(&state, out, 32);
if (crypto_xof_turboshake256_update(&state, msg_abc, 3) == 0) {
printf("Should not be able to absorb after squeezing\n");
return 1;
}
printf("All TurboSHAKE-256 tests passed\n");
return 0;
}