From d11e9071070bed2484b6069bd44db40548fb62f8 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 18 Nov 2025 12:00:59 +0100 Subject: [PATCH] Remove crypto_xof_*_final --- .../crypto_xof/shake128/ref/shake128_ref.c | 15 +++------------ .../crypto_xof/shake128/ref/shake128_ref.h | 2 -- .../crypto_xof/shake128/xof_shake128.c | 8 -------- .../crypto_xof/shake256/ref/shake256_ref.c | 15 +++------------ .../crypto_xof/shake256/ref/shake256_ref.h | 2 -- .../crypto_xof/shake256/xof_shake256.c | 8 -------- .../turboshake128/ref/turboshake128_ref.c | 15 +++------------ .../turboshake128/ref/turboshake128_ref.h | 2 -- .../turboshake128/xof_turboshake128.c | 9 --------- .../turboshake256/ref/turboshake256_ref.c | 15 +++------------ .../turboshake256/ref/turboshake256_ref.h | 2 -- .../turboshake256/xof_turboshake256.c | 9 --------- .../include/sodium/crypto_xof_shake128.h | 4 ---- .../include/sodium/crypto_xof_shake256.h | 4 ---- .../include/sodium/crypto_xof_turboshake128.h | 4 ---- .../include/sodium/crypto_xof_turboshake256.h | 4 ---- test/default/xof_shake128.c | 18 +++++------------- test/default/xof_shake256.c | 18 +++++------------- test/default/xof_turboshake128.c | 18 +++++------------- test/default/xof_turboshake256.c | 18 +++++------------- 20 files changed, 32 insertions(+), 158 deletions(-) diff --git a/src/libsodium/crypto_xof/shake128/ref/shake128_ref.c b/src/libsodium/crypto_xof/shake128/ref/shake128_ref.c index 168df33f..a0bf7a31 100644 --- a/src/libsodium/crypto_xof/shake128/ref/shake128_ref.c +++ b/src/libsodium/crypto_xof/shake128/ref/shake128_ref.c @@ -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; } diff --git a/src/libsodium/crypto_xof/shake128/ref/shake128_ref.h b/src/libsodium/crypto_xof/shake128/ref/shake128_ref.h index a90634c3..55fe6100 100644 --- a/src/libsodium/crypto_xof/shake128/ref/shake128_ref.h +++ b/src/libsodium/crypto_xof/shake128/ref/shake128_ref.h @@ -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 */ diff --git a/src/libsodium/crypto_xof/shake128/xof_shake128.c b/src/libsodium/crypto_xof/shake128/xof_shake128.c index 5b4d28e3..6643c98e 100644 --- a/src/libsodium/crypto_xof/shake128/xof_shake128.c +++ b/src/libsodium/crypto_xof/shake128/xof_shake128.c @@ -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) { diff --git a/src/libsodium/crypto_xof/shake256/ref/shake256_ref.c b/src/libsodium/crypto_xof/shake256/ref/shake256_ref.c index 9e86422f..07caea5d 100644 --- a/src/libsodium/crypto_xof/shake256/ref/shake256_ref.c +++ b/src/libsodium/crypto_xof/shake256/ref/shake256_ref.c @@ -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; } diff --git a/src/libsodium/crypto_xof/shake256/ref/shake256_ref.h b/src/libsodium/crypto_xof/shake256/ref/shake256_ref.h index c65b6681..d3a3fbc5 100644 --- a/src/libsodium/crypto_xof/shake256/ref/shake256_ref.h +++ b/src/libsodium/crypto_xof/shake256/ref/shake256_ref.h @@ -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 */ diff --git a/src/libsodium/crypto_xof/shake256/xof_shake256.c b/src/libsodium/crypto_xof/shake256/xof_shake256.c index 37402fa0..364170db 100644 --- a/src/libsodium/crypto_xof/shake256/xof_shake256.c +++ b/src/libsodium/crypto_xof/shake256/xof_shake256.c @@ -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) { diff --git a/src/libsodium/crypto_xof/turboshake128/ref/turboshake128_ref.c b/src/libsodium/crypto_xof/turboshake128/ref/turboshake128_ref.c index bd232948..4e03f41d 100644 --- a/src/libsodium/crypto_xof/turboshake128/ref/turboshake128_ref.c +++ b/src/libsodium/crypto_xof/turboshake128/ref/turboshake128_ref.c @@ -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; } diff --git a/src/libsodium/crypto_xof/turboshake128/ref/turboshake128_ref.h b/src/libsodium/crypto_xof/turboshake128/ref/turboshake128_ref.h index 04a4a6c9..ace155a5 100644 --- a/src/libsodium/crypto_xof/turboshake128/ref/turboshake128_ref.h +++ b/src/libsodium/crypto_xof/turboshake128/ref/turboshake128_ref.h @@ -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); diff --git a/src/libsodium/crypto_xof/turboshake128/xof_turboshake128.c b/src/libsodium/crypto_xof/turboshake128/xof_turboshake128.c index 798988ae..3824f10d 100644 --- a/src/libsodium/crypto_xof/turboshake128/xof_turboshake128.c +++ b/src/libsodium/crypto_xof/turboshake128/xof_turboshake128.c @@ -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) diff --git a/src/libsodium/crypto_xof/turboshake256/ref/turboshake256_ref.c b/src/libsodium/crypto_xof/turboshake256/ref/turboshake256_ref.c index c49f2659..98949117 100644 --- a/src/libsodium/crypto_xof/turboshake256/ref/turboshake256_ref.c +++ b/src/libsodium/crypto_xof/turboshake256/ref/turboshake256_ref.c @@ -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; } diff --git a/src/libsodium/crypto_xof/turboshake256/ref/turboshake256_ref.h b/src/libsodium/crypto_xof/turboshake256/ref/turboshake256_ref.h index 9d6c3cee..09dfff7b 100644 --- a/src/libsodium/crypto_xof/turboshake256/ref/turboshake256_ref.h +++ b/src/libsodium/crypto_xof/turboshake256/ref/turboshake256_ref.h @@ -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); diff --git a/src/libsodium/crypto_xof/turboshake256/xof_turboshake256.c b/src/libsodium/crypto_xof/turboshake256/xof_turboshake256.c index 7e0e15b3..0280da73 100644 --- a/src/libsodium/crypto_xof/turboshake256/xof_turboshake256.c +++ b/src/libsodium/crypto_xof/turboshake256/xof_turboshake256.c @@ -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) diff --git a/src/libsodium/include/sodium/crypto_xof_shake128.h b/src/libsodium/include/sodium/crypto_xof_shake128.h index 3ac2c0b6..2a33239a 100644 --- a/src/libsodium/include/sodium/crypto_xof_shake128.h +++ b/src/libsodium/include/sodium/crypto_xof_shake128.h @@ -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)); diff --git a/src/libsodium/include/sodium/crypto_xof_shake256.h b/src/libsodium/include/sodium/crypto_xof_shake256.h index c2f6d58f..05401b0e 100644 --- a/src/libsodium/include/sodium/crypto_xof_shake256.h +++ b/src/libsodium/include/sodium/crypto_xof_shake256.h @@ -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)); diff --git a/src/libsodium/include/sodium/crypto_xof_turboshake128.h b/src/libsodium/include/sodium/crypto_xof_turboshake128.h index d7513171..ccef3fca 100644 --- a/src/libsodium/include/sodium/crypto_xof_turboshake128.h +++ b/src/libsodium/include/sodium/crypto_xof_turboshake128.h @@ -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)); diff --git a/src/libsodium/include/sodium/crypto_xof_turboshake256.h b/src/libsodium/include/sodium/crypto_xof_turboshake256.h index e8ecd269..4f49d9bc 100644 --- a/src/libsodium/include/sodium/crypto_xof_turboshake256.h +++ b/src/libsodium/include/sodium/crypto_xof_turboshake256.h @@ -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)); diff --git a/test/default/xof_shake128.c b/test/default/xof_shake128.c index 072378fe..9c7e3a46 100644 --- a/test/default/xof_shake128.c +++ b/test/default/xof_shake128.c @@ -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; } diff --git a/test/default/xof_shake256.c b/test/default/xof_shake256.c index fbbdec7f..96dcb1c8 100644 --- a/test/default/xof_shake256.c +++ b/test/default/xof_shake256.c @@ -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; } diff --git a/test/default/xof_turboshake128.c b/test/default/xof_turboshake128.c index a5040823..ba862ccc 100644 --- a/test/default/xof_turboshake128.c +++ b/test/default/xof_turboshake128.c @@ -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; } diff --git a/test/default/xof_turboshake256.c b/test/default/xof_turboshake256.c index 68420006..bf7bc3f0 100644 --- a/test/default/xof_turboshake256.c +++ b/test/default/xof_turboshake256.c @@ -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; }