Import SHAKE128, SHAKE256, TurboSHAKE128, and TurboSHAKE256

- crypto_core_keccak1600: Keccak-f[1600] permutation
- crypto_xof_shake128/256: FIPS 202 SHAKE functions
- crypto_xof_turboshake128/256: TurboSHAKE (faster, 12-round variant)
This commit is contained in:
Frank Denis
2026-01-06 15:42:07 +01:00
parent 348456f37a
commit 350604eb25
38 changed files with 3361 additions and 59 deletions
+33 -3
View File
@@ -29,6 +29,7 @@ EXTRA_DIST = \
chacha20.exp \
codecs.exp \
core_ed25519.exp \
core_keccak1600.exp \
core_ristretto255.exp \
core1.exp \
core2.exp \
@@ -84,7 +85,11 @@ EXTRA_DIST = \
stream3.exp \
stream4.exp \
verify1.exp \
xchacha20.exp
xchacha20.exp \
xof_shake128.exp \
xof_shake256.exp \
xof_turboshake128.exp \
xof_turboshake256.exp
DISTCLEANFILES = \
aead_aegis128l.res \
@@ -111,6 +116,7 @@ DISTCLEANFILES = \
chacha20.res \
codecs.res \
core_ed25519.res \
core_keccak1600.res \
core_ristretto255.res \
core1.res \
core2.res \
@@ -167,7 +173,11 @@ DISTCLEANFILES = \
stream3.res \
stream4.res \
verify1.res \
xchacha20.res
xchacha20.res \
xof_shake128.res \
xof_shake256.res \
xof_turboshake128.res \
xof_turboshake256.res
AM_CPPFLAGS = \
-DTEST_SRCDIR=\"@srcdir@\" \
@@ -203,6 +213,7 @@ TESTS_TARGETS = \
box_seed \
chacha20 \
codecs \
core_keccak1600 \
core1 \
core2 \
core3 \
@@ -248,7 +259,11 @@ TESTS_TARGETS = \
stream2 \
stream3 \
stream4 \
verify1
verify1 \
xof_shake128 \
xof_shake256 \
xof_turboshake128 \
xof_turboshake256
if !EMSCRIPTEN
TESTS_TARGETS += \
@@ -335,6 +350,9 @@ codecs_LDADD = $(TESTS_LDADD)
core_ed25519_SOURCE = cmptest.h core_ed25519.c
core_ed25519_LDADD = $(TESTS_LDADD)
core_keccak1600_SOURCE = cmptest.h core_keccak1600.c
core_keccak1600_LDADD = $(TESTS_LDADD)
core_ristretto255_SOURCE = cmptest.h core_ristretto255.c
core_ristretto255_LDADD = $(TESTS_LDADD)
@@ -503,6 +521,18 @@ verify1_LDADD = $(TESTS_LDADD)
xchacha20_SOURCE = cmptest.h xchacha20.c
xchacha20_LDADD = $(TESTS_LDADD)
xof_shake128_SOURCE = cmptest.h xof_shake128.c
xof_shake128_LDADD = $(TESTS_LDADD)
xof_shake256_SOURCE = cmptest.h xof_shake256.c
xof_shake256_LDADD = $(TESTS_LDADD)
xof_turboshake128_SOURCE = cmptest.h xof_turboshake128.c
xof_turboshake128_LDADD = $(TESTS_LDADD)
xof_turboshake256_SOURCE = cmptest.h xof_turboshake256.c
xof_turboshake256_LDADD = $(TESTS_LDADD)
if !MINIMAL
TESTS_TARGETS += \
core_ed25519 \
+169 -52
View File
@@ -144,23 +144,25 @@ am__EXEEXT_3 = aead_aegis128l$(EXEEXT) aead_aegis256$(EXEEXT) \
box$(EXEEXT) box2$(EXEEXT) box7$(EXEEXT) box8$(EXEEXT) \
box_easy$(EXEEXT) box_easy2$(EXEEXT) box_seal$(EXEEXT) \
box_seed$(EXEEXT) chacha20$(EXEEXT) codecs$(EXEEXT) \
core1$(EXEEXT) core2$(EXEEXT) core3$(EXEEXT) core4$(EXEEXT) \
core5$(EXEEXT) core6$(EXEEXT) ed25519_convert$(EXEEXT) \
generichash$(EXEEXT) generichash2$(EXEEXT) \
generichash3$(EXEEXT) hash$(EXEEXT) hash3$(EXEEXT) \
kdf$(EXEEXT) keygen$(EXEEXT) kx$(EXEEXT) metamorphic$(EXEEXT) \
misuse$(EXEEXT) onetimeauth$(EXEEXT) onetimeauth2$(EXEEXT) \
onetimeauth7$(EXEEXT) pwhash_argon2i$(EXEEXT) \
pwhash_argon2id$(EXEEXT) randombytes$(EXEEXT) \
scalarmult$(EXEEXT) scalarmult2$(EXEEXT) scalarmult5$(EXEEXT) \
scalarmult6$(EXEEXT) scalarmult7$(EXEEXT) scalarmult8$(EXEEXT) \
secretbox$(EXEEXT) secretbox2$(EXEEXT) secretbox7$(EXEEXT) \
secretbox8$(EXEEXT) secretbox_easy$(EXEEXT) \
secretbox_easy2$(EXEEXT) \
core_keccak1600$(EXEEXT) core1$(EXEEXT) core2$(EXEEXT) \
core3$(EXEEXT) core4$(EXEEXT) core5$(EXEEXT) core6$(EXEEXT) \
ed25519_convert$(EXEEXT) generichash$(EXEEXT) \
generichash2$(EXEEXT) generichash3$(EXEEXT) hash$(EXEEXT) \
hash3$(EXEEXT) kdf$(EXEEXT) keygen$(EXEEXT) kx$(EXEEXT) \
metamorphic$(EXEEXT) misuse$(EXEEXT) onetimeauth$(EXEEXT) \
onetimeauth2$(EXEEXT) onetimeauth7$(EXEEXT) \
pwhash_argon2i$(EXEEXT) pwhash_argon2id$(EXEEXT) \
randombytes$(EXEEXT) scalarmult$(EXEEXT) scalarmult2$(EXEEXT) \
scalarmult5$(EXEEXT) scalarmult6$(EXEEXT) scalarmult7$(EXEEXT) \
scalarmult8$(EXEEXT) secretbox$(EXEEXT) secretbox2$(EXEEXT) \
secretbox7$(EXEEXT) secretbox8$(EXEEXT) \
secretbox_easy$(EXEEXT) secretbox_easy2$(EXEEXT) \
secretstream_xchacha20poly1305$(EXEEXT) shorthash$(EXEEXT) \
sign$(EXEEXT) sodium_core$(EXEEXT) sodium_utils$(EXEEXT) \
sodium_version$(EXEEXT) stream$(EXEEXT) stream2$(EXEEXT) \
stream3$(EXEEXT) stream4$(EXEEXT) verify1$(EXEEXT) \
xof_shake128$(EXEEXT) xof_shake256$(EXEEXT) \
xof_turboshake128$(EXEEXT) xof_turboshake256$(EXEEXT) \
$(am__EXEEXT_1) $(am__EXEEXT_2)
aead_aegis128l_SOURCES = aead_aegis128l.c
aead_aegis128l_OBJECTS = aead_aegis128l.$(OBJEXT)
@@ -256,6 +258,9 @@ core6_DEPENDENCIES = $(TESTS_LDADD)
core_ed25519_SOURCES = core_ed25519.c
core_ed25519_OBJECTS = core_ed25519.$(OBJEXT)
core_ed25519_DEPENDENCIES = $(TESTS_LDADD)
core_keccak1600_SOURCES = core_keccak1600.c
core_keccak1600_OBJECTS = core_keccak1600.$(OBJEXT)
core_keccak1600_DEPENDENCIES = $(TESTS_LDADD)
core_ristretto255_SOURCES = core_ristretto255.c
core_ristretto255_OBJECTS = core_ristretto255.$(OBJEXT)
core_ristretto255_DEPENDENCIES = $(TESTS_LDADD)
@@ -408,6 +413,18 @@ verify1_DEPENDENCIES = $(TESTS_LDADD)
xchacha20_SOURCES = xchacha20.c
xchacha20_OBJECTS = xchacha20.$(OBJEXT)
xchacha20_DEPENDENCIES = $(TESTS_LDADD)
xof_shake128_SOURCES = xof_shake128.c
xof_shake128_OBJECTS = xof_shake128.$(OBJEXT)
xof_shake128_DEPENDENCIES = $(TESTS_LDADD)
xof_shake256_SOURCES = xof_shake256.c
xof_shake256_OBJECTS = xof_shake256.$(OBJEXT)
xof_shake256_DEPENDENCIES = $(TESTS_LDADD)
xof_turboshake128_SOURCES = xof_turboshake128.c
xof_turboshake128_OBJECTS = xof_turboshake128.$(OBJEXT)
xof_turboshake128_DEPENDENCIES = $(TESTS_LDADD)
xof_turboshake256_SOURCES = xof_turboshake256.c
xof_turboshake256_OBJECTS = xof_turboshake256.$(OBJEXT)
xof_turboshake256_DEPENDENCIES = $(TESTS_LDADD)
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
@@ -437,7 +454,8 @@ am__depfiles_remade = ./$(DEPDIR)/aead_aegis128l.Po \
./$(DEPDIR)/chacha20.Po ./$(DEPDIR)/codecs.Po \
./$(DEPDIR)/core1.Po ./$(DEPDIR)/core2.Po ./$(DEPDIR)/core3.Po \
./$(DEPDIR)/core4.Po ./$(DEPDIR)/core5.Po ./$(DEPDIR)/core6.Po \
./$(DEPDIR)/core_ed25519.Po ./$(DEPDIR)/core_ristretto255.Po \
./$(DEPDIR)/core_ed25519.Po ./$(DEPDIR)/core_keccak1600.Po \
./$(DEPDIR)/core_ristretto255.Po \
./$(DEPDIR)/ed25519_convert.Po ./$(DEPDIR)/generichash.Po \
./$(DEPDIR)/generichash2.Po ./$(DEPDIR)/generichash3.Po \
./$(DEPDIR)/hash.Po ./$(DEPDIR)/hash3.Po ./$(DEPDIR)/kdf.Po \
@@ -462,7 +480,10 @@ am__depfiles_remade = ./$(DEPDIR)/aead_aegis128l.Po \
./$(DEPDIR)/sodium_utils3.Po ./$(DEPDIR)/sodium_version.Po \
./$(DEPDIR)/stream.Po ./$(DEPDIR)/stream2.Po \
./$(DEPDIR)/stream3.Po ./$(DEPDIR)/stream4.Po \
./$(DEPDIR)/verify1.Po ./$(DEPDIR)/xchacha20.Po
./$(DEPDIR)/verify1.Po ./$(DEPDIR)/xchacha20.Po \
./$(DEPDIR)/xof_shake128.Po ./$(DEPDIR)/xof_shake256.Po \
./$(DEPDIR)/xof_turboshake128.Po \
./$(DEPDIR)/xof_turboshake256.Po
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -488,38 +509,42 @@ SOURCES = aead_aegis128l.c aead_aegis256.c aead_aes256gcm.c \
auth2.c auth3.c auth5.c auth6.c auth7.c box.c box2.c box7.c \
box8.c box_easy.c box_easy2.c box_seal.c box_seed.c chacha20.c \
codecs.c core1.c core2.c core3.c core4.c core5.c core6.c \
core_ed25519.c core_ristretto255.c ed25519_convert.c \
generichash.c generichash2.c generichash3.c hash.c hash3.c \
kdf.c kdf_hkdf.c keygen.c kx.c metamorphic.c misuse.c \
onetimeauth.c onetimeauth2.c onetimeauth7.c pwhash_argon2i.c \
pwhash_argon2id.c pwhash_scrypt.c pwhash_scrypt_ll.c \
randombytes.c scalarmult.c scalarmult2.c scalarmult5.c \
scalarmult6.c scalarmult7.c scalarmult8.c scalarmult_ed25519.c \
scalarmult_ristretto255.c secretbox.c secretbox2.c \
secretbox7.c secretbox8.c secretbox_easy.c secretbox_easy2.c \
secretstream_xchacha20poly1305.c shorthash.c sign.c \
siphashx24.c sodium_core.c sodium_utils.c sodium_utils2.c \
sodium_utils3.c sodium_version.c stream.c stream2.c stream3.c \
stream4.c verify1.c xchacha20.c
core_ed25519.c core_keccak1600.c core_ristretto255.c \
ed25519_convert.c generichash.c generichash2.c generichash3.c \
hash.c hash3.c kdf.c kdf_hkdf.c keygen.c kx.c metamorphic.c \
misuse.c onetimeauth.c onetimeauth2.c onetimeauth7.c \
pwhash_argon2i.c pwhash_argon2id.c pwhash_scrypt.c \
pwhash_scrypt_ll.c randombytes.c scalarmult.c scalarmult2.c \
scalarmult5.c scalarmult6.c scalarmult7.c scalarmult8.c \
scalarmult_ed25519.c scalarmult_ristretto255.c secretbox.c \
secretbox2.c secretbox7.c secretbox8.c secretbox_easy.c \
secretbox_easy2.c secretstream_xchacha20poly1305.c shorthash.c \
sign.c siphashx24.c sodium_core.c sodium_utils.c \
sodium_utils2.c sodium_utils3.c sodium_version.c stream.c \
stream2.c stream3.c stream4.c verify1.c xchacha20.c \
xof_shake128.c xof_shake256.c xof_turboshake128.c \
xof_turboshake256.c
DIST_SOURCES = aead_aegis128l.c aead_aegis256.c aead_aes256gcm.c \
aead_aes256gcm2.c aead_chacha20poly1305.c \
aead_chacha20poly13052.c aead_xchacha20poly1305.c auth.c \
auth2.c auth3.c auth5.c auth6.c auth7.c box.c box2.c box7.c \
box8.c box_easy.c box_easy2.c box_seal.c box_seed.c chacha20.c \
codecs.c core1.c core2.c core3.c core4.c core5.c core6.c \
core_ed25519.c core_ristretto255.c ed25519_convert.c \
generichash.c generichash2.c generichash3.c hash.c hash3.c \
kdf.c kdf_hkdf.c keygen.c kx.c metamorphic.c misuse.c \
onetimeauth.c onetimeauth2.c onetimeauth7.c pwhash_argon2i.c \
pwhash_argon2id.c pwhash_scrypt.c pwhash_scrypt_ll.c \
randombytes.c scalarmult.c scalarmult2.c scalarmult5.c \
scalarmult6.c scalarmult7.c scalarmult8.c scalarmult_ed25519.c \
scalarmult_ristretto255.c secretbox.c secretbox2.c \
secretbox7.c secretbox8.c secretbox_easy.c secretbox_easy2.c \
secretstream_xchacha20poly1305.c shorthash.c sign.c \
siphashx24.c sodium_core.c sodium_utils.c sodium_utils2.c \
sodium_utils3.c sodium_version.c stream.c stream2.c stream3.c \
stream4.c verify1.c xchacha20.c
core_ed25519.c core_keccak1600.c core_ristretto255.c \
ed25519_convert.c generichash.c generichash2.c generichash3.c \
hash.c hash3.c kdf.c kdf_hkdf.c keygen.c kx.c metamorphic.c \
misuse.c onetimeauth.c onetimeauth2.c onetimeauth7.c \
pwhash_argon2i.c pwhash_argon2id.c pwhash_scrypt.c \
pwhash_scrypt_ll.c randombytes.c scalarmult.c scalarmult2.c \
scalarmult5.c scalarmult6.c scalarmult7.c scalarmult8.c \
scalarmult_ed25519.c scalarmult_ristretto255.c secretbox.c \
secretbox2.c secretbox7.c secretbox8.c secretbox_easy.c \
secretbox_easy2.c secretstream_xchacha20poly1305.c shorthash.c \
sign.c siphashx24.c sodium_core.c sodium_utils.c \
sodium_utils2.c sodium_utils3.c sodium_version.c stream.c \
stream2.c stream3.c stream4.c verify1.c xchacha20.c \
xof_shake128.c xof_shake256.c xof_turboshake128.c \
xof_turboshake256.c
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
@@ -957,6 +982,7 @@ EXTRA_DIST = \
chacha20.exp \
codecs.exp \
core_ed25519.exp \
core_keccak1600.exp \
core_ristretto255.exp \
core1.exp \
core2.exp \
@@ -1012,7 +1038,11 @@ EXTRA_DIST = \
stream3.exp \
stream4.exp \
verify1.exp \
xchacha20.exp
xchacha20.exp \
xof_shake128.exp \
xof_shake256.exp \
xof_turboshake128.exp \
xof_turboshake256.exp
DISTCLEANFILES = \
aead_aegis128l.res \
@@ -1039,6 +1069,7 @@ DISTCLEANFILES = \
chacha20.res \
codecs.res \
core_ed25519.res \
core_keccak1600.res \
core_ristretto255.res \
core1.res \
core2.res \
@@ -1095,7 +1126,11 @@ DISTCLEANFILES = \
stream3.res \
stream4.res \
verify1.res \
xchacha20.res
xchacha20.res \
xof_shake128.res \
xof_shake256.res \
xof_turboshake128.res \
xof_turboshake256.res
AM_CPPFLAGS = \
-DTEST_SRCDIR=\"@srcdir@\" \
@@ -1110,15 +1145,17 @@ TESTS_TARGETS = aead_aegis128l aead_aegis256 aead_aes256gcm \
aead_aes256gcm2 aead_chacha20poly1305 aead_chacha20poly13052 \
aead_xchacha20poly1305 auth auth2 auth3 auth5 auth6 auth7 box \
box2 box7 box8 box_easy box_easy2 box_seal box_seed chacha20 \
codecs core1 core2 core3 core4 core5 core6 ed25519_convert \
generichash generichash2 generichash3 hash hash3 kdf keygen kx \
metamorphic misuse onetimeauth onetimeauth2 onetimeauth7 \
pwhash_argon2i pwhash_argon2id randombytes scalarmult \
scalarmult2 scalarmult5 scalarmult6 scalarmult7 scalarmult8 \
secretbox secretbox2 secretbox7 secretbox8 secretbox_easy \
secretbox_easy2 secretstream_xchacha20poly1305 shorthash sign \
sodium_core sodium_utils sodium_version stream stream2 stream3 \
stream4 verify1 $(am__append_1) $(am__append_2)
codecs core_keccak1600 core1 core2 core3 core4 core5 core6 \
ed25519_convert generichash generichash2 generichash3 hash \
hash3 kdf keygen kx metamorphic misuse onetimeauth \
onetimeauth2 onetimeauth7 pwhash_argon2i pwhash_argon2id \
randombytes scalarmult scalarmult2 scalarmult5 scalarmult6 \
scalarmult7 scalarmult8 secretbox secretbox2 secretbox7 \
secretbox8 secretbox_easy secretbox_easy2 \
secretstream_xchacha20poly1305 shorthash sign sodium_core \
sodium_utils sodium_version stream stream2 stream3 stream4 \
verify1 xof_shake128 xof_shake256 xof_turboshake128 \
xof_turboshake256 $(am__append_1) $(am__append_2)
TESTS_LDADD = \
${top_builddir}/src/libsodium/libsodium.la
@@ -1170,6 +1207,8 @@ codecs_SOURCE = cmptest.h codecs.c
codecs_LDADD = $(TESTS_LDADD)
core_ed25519_SOURCE = cmptest.h core_ed25519.c
core_ed25519_LDADD = $(TESTS_LDADD)
core_keccak1600_SOURCE = cmptest.h core_keccak1600.c
core_keccak1600_LDADD = $(TESTS_LDADD)
core_ristretto255_SOURCE = cmptest.h core_ristretto255.c
core_ristretto255_LDADD = $(TESTS_LDADD)
core1_SOURCE = cmptest.h core1.c
@@ -1282,6 +1321,14 @@ verify1_SOURCE = cmptest.h verify1.c
verify1_LDADD = $(TESTS_LDADD)
xchacha20_SOURCE = cmptest.h xchacha20.c
xchacha20_LDADD = $(TESTS_LDADD)
xof_shake128_SOURCE = cmptest.h xof_shake128.c
xof_shake128_LDADD = $(TESTS_LDADD)
xof_shake256_SOURCE = cmptest.h xof_shake256.c
xof_shake256_LDADD = $(TESTS_LDADD)
xof_turboshake128_SOURCE = cmptest.h xof_turboshake128.c
xof_turboshake128_LDADD = $(TESTS_LDADD)
xof_turboshake256_SOURCE = cmptest.h xof_turboshake256.c
xof_turboshake256_LDADD = $(TESTS_LDADD)
@WASI_TRUE@LOG_COMPILER = ./wasi-test-wrapper.sh
all: all-am
@@ -1441,6 +1488,10 @@ core_ed25519$(EXEEXT): $(core_ed25519_OBJECTS) $(core_ed25519_DEPENDENCIES) $(EX
@rm -f core_ed25519$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(core_ed25519_OBJECTS) $(core_ed25519_LDADD) $(LIBS)
core_keccak1600$(EXEEXT): $(core_keccak1600_OBJECTS) $(core_keccak1600_DEPENDENCIES) $(EXTRA_core_keccak1600_DEPENDENCIES)
@rm -f core_keccak1600$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(core_keccak1600_OBJECTS) $(core_keccak1600_LDADD) $(LIBS)
core_ristretto255$(EXEEXT): $(core_ristretto255_OBJECTS) $(core_ristretto255_DEPENDENCIES) $(EXTRA_core_ristretto255_DEPENDENCIES)
@rm -f core_ristretto255$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(core_ristretto255_OBJECTS) $(core_ristretto255_LDADD) $(LIBS)
@@ -1641,6 +1692,22 @@ xchacha20$(EXEEXT): $(xchacha20_OBJECTS) $(xchacha20_DEPENDENCIES) $(EXTRA_xchac
@rm -f xchacha20$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(xchacha20_OBJECTS) $(xchacha20_LDADD) $(LIBS)
xof_shake128$(EXEEXT): $(xof_shake128_OBJECTS) $(xof_shake128_DEPENDENCIES) $(EXTRA_xof_shake128_DEPENDENCIES)
@rm -f xof_shake128$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(xof_shake128_OBJECTS) $(xof_shake128_LDADD) $(LIBS)
xof_shake256$(EXEEXT): $(xof_shake256_OBJECTS) $(xof_shake256_DEPENDENCIES) $(EXTRA_xof_shake256_DEPENDENCIES)
@rm -f xof_shake256$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(xof_shake256_OBJECTS) $(xof_shake256_LDADD) $(LIBS)
xof_turboshake128$(EXEEXT): $(xof_turboshake128_OBJECTS) $(xof_turboshake128_DEPENDENCIES) $(EXTRA_xof_turboshake128_DEPENDENCIES)
@rm -f xof_turboshake128$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(xof_turboshake128_OBJECTS) $(xof_turboshake128_LDADD) $(LIBS)
xof_turboshake256$(EXEEXT): $(xof_turboshake256_OBJECTS) $(xof_turboshake256_DEPENDENCIES) $(EXTRA_xof_turboshake256_DEPENDENCIES)
@rm -f xof_turboshake256$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(xof_turboshake256_OBJECTS) $(xof_turboshake256_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@@ -1677,6 +1744,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/core5.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/core6.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/core_ed25519.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/core_keccak1600.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/core_ristretto255.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ed25519_convert.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generichash.Po@am__quote@ # am--include-marker
@@ -1727,6 +1795,10 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream4.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/verify1.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xchacha20.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xof_shake128.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xof_shake256.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xof_turboshake128.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xof_turboshake256.Po@am__quote@ # am--include-marker
$(am__depfiles_remade):
@$(MKDIR_P) $(@D)
@@ -2143,6 +2215,13 @@ codecs.log: codecs$(EXEEXT)
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
core_keccak1600.log: core_keccak1600$(EXEEXT)
@p='core_keccak1600$(EXEEXT)'; \
b='core_keccak1600'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
core1.log: core1$(EXEEXT)
@p='core1$(EXEEXT)'; \
b='core1'; \
@@ -2465,6 +2544,34 @@ verify1.log: verify1$(EXEEXT)
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
xof_shake128.log: xof_shake128$(EXEEXT)
@p='xof_shake128$(EXEEXT)'; \
b='xof_shake128'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
xof_shake256.log: xof_shake256$(EXEEXT)
@p='xof_shake256$(EXEEXT)'; \
b='xof_shake256'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
xof_turboshake128.log: xof_turboshake128$(EXEEXT)
@p='xof_turboshake128$(EXEEXT)'; \
b='xof_turboshake128'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
xof_turboshake256.log: xof_turboshake256$(EXEEXT)
@p='xof_turboshake256$(EXEEXT)'; \
b='xof_turboshake256'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
sodium_utils2.log: sodium_utils2$(EXEEXT)
@p='sodium_utils2$(EXEEXT)'; \
b='sodium_utils2'; \
@@ -2666,6 +2773,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/core5.Po
-rm -f ./$(DEPDIR)/core6.Po
-rm -f ./$(DEPDIR)/core_ed25519.Po
-rm -f ./$(DEPDIR)/core_keccak1600.Po
-rm -f ./$(DEPDIR)/core_ristretto255.Po
-rm -f ./$(DEPDIR)/ed25519_convert.Po
-rm -f ./$(DEPDIR)/generichash.Po
@@ -2716,6 +2824,10 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/stream4.Po
-rm -f ./$(DEPDIR)/verify1.Po
-rm -f ./$(DEPDIR)/xchacha20.Po
-rm -f ./$(DEPDIR)/xof_shake128.Po
-rm -f ./$(DEPDIR)/xof_shake256.Po
-rm -f ./$(DEPDIR)/xof_turboshake128.Po
-rm -f ./$(DEPDIR)/xof_turboshake256.Po
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
@@ -2791,6 +2903,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/core5.Po
-rm -f ./$(DEPDIR)/core6.Po
-rm -f ./$(DEPDIR)/core_ed25519.Po
-rm -f ./$(DEPDIR)/core_keccak1600.Po
-rm -f ./$(DEPDIR)/core_ristretto255.Po
-rm -f ./$(DEPDIR)/ed25519_convert.Po
-rm -f ./$(DEPDIR)/generichash.Po
@@ -2841,6 +2954,10 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/stream4.Po
-rm -f ./$(DEPDIR)/verify1.Po
-rm -f ./$(DEPDIR)/xchacha20.Po
-rm -f ./$(DEPDIR)/xof_shake128.Po
-rm -f ./$(DEPDIR)/xof_shake256.Po
-rm -f ./$(DEPDIR)/xof_turboshake128.Po
-rm -f ./$(DEPDIR)/xof_turboshake256.Po
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
+235
View File
@@ -0,0 +1,235 @@
#define TEST_NAME "core_keccak1600"
#include "cmptest.h"
static void
print_hex(const char *label, const unsigned char *data, size_t len)
{
size_t i;
printf("%s", label);
for (i = 0; i < len; i++) {
printf("%02x", data[i]);
}
printf("\n");
}
static int
compare_states(const char *label, const unsigned char *actual, const unsigned char *expected,
size_t len)
{
size_t i;
for (i = 0; i < len; i++) {
if (actual[i] != expected[i]) {
printf("FAIL: %s mismatch at byte %u\n", label, (unsigned int) i);
printf(" Expected: ");
for (size_t j = 0; j < len; j++) {
printf("%02x", expected[j]);
}
printf("\n Got: ");
for (size_t j = 0; j < len; j++) {
printf("%02x", actual[j]);
}
printf("\n");
return -1;
}
}
printf("PASS: %s\n", label);
return 0;
}
int
main(void)
{
unsigned char state[crypto_core_keccak1600_STATEBYTES];
unsigned char extracted[64];
size_t i;
int test_failures = 0;
/* Test vectors for Keccak-f[1600] (24 rounds) */
/* Test vector 1: All-zero input for Keccak-f[1600] */
static const unsigned char keccak_f_1600_zero_input[200] = { 0 };
static const unsigned char keccak_f_1600_zero_expected[200] = {
0xe7, 0xdd, 0xe1, 0x40, 0x79, 0x8f, 0x25, 0xf1, 0x8a, 0x47, 0xc0, 0x33, 0xf9, 0xcc, 0xd5,
0x84, 0xee, 0xa9, 0x5a, 0xa6, 0x1e, 0x26, 0x98, 0xd5, 0x4d, 0x49, 0x80, 0x6f, 0x30, 0x47,
0x15, 0xbd, 0x57, 0xd0, 0x53, 0x62, 0x05, 0x4e, 0x28, 0x8b, 0xd4, 0x6f, 0x8e, 0x7f, 0x2d,
0xa4, 0x97, 0xff, 0xc4, 0x47, 0x46, 0xa4, 0xa0, 0xe5, 0xfe, 0x90, 0x76, 0x2e, 0x19, 0xd6,
0x0c, 0xda, 0x5b, 0x8c, 0x9c, 0x05, 0x19, 0x1b, 0xf7, 0xa6, 0x30, 0xad, 0x64, 0xfc, 0x8f,
0xd0, 0xb7, 0x5a, 0x93, 0x30, 0x35, 0xd6, 0x17, 0x23, 0x3f, 0xa9, 0x5a, 0xeb, 0x03, 0x21,
0x71, 0x0d, 0x26, 0xe6, 0xa6, 0xa9, 0x5f, 0x55, 0xcf, 0xdb, 0x16, 0x7c, 0xa5, 0x81, 0x26,
0xc8, 0x47, 0x03, 0xcd, 0x31, 0xb8, 0x43, 0x9f, 0x56, 0xa5, 0x11, 0x1a, 0x2f, 0xf2, 0x01,
0x61, 0xae, 0xd9, 0x21, 0x5a, 0x63, 0xe5, 0x05, 0xf2, 0x70, 0xc9, 0x8c, 0xf2, 0xfe, 0xbe,
0x64, 0x11, 0x66, 0xc4, 0x7b, 0x95, 0x70, 0x36, 0x61, 0xcb, 0x0e, 0xd0, 0x4f, 0x55, 0x5a,
0x7c, 0xb8, 0xc8, 0x32, 0xcf, 0x1c, 0x8a, 0xe8, 0x3e, 0x8c, 0x14, 0x26, 0x3a, 0xae, 0x22,
0x79, 0x0c, 0x94, 0xe4, 0x09, 0xc5, 0xa2, 0x24, 0xf9, 0x41, 0x18, 0xc2, 0x65, 0x04, 0xe7,
0x26, 0x35, 0xf5, 0x16, 0x3b, 0xa1, 0x30, 0x7f, 0xe9, 0x44, 0xf6, 0x75, 0x49, 0xa2, 0xec,
0x5c, 0x7b, 0xff, 0xf1, 0xea
};
/* Test vector 2: Pattern input for Keccak-f[1600] */
static const unsigned char keccak_f_1600_pattern_input[200] = {
0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
0xa3, 0xa3, 0xa3, 0xa3, 0xa3
};
static const unsigned char keccak_f_1600_pattern_expected[200] = {
0xcc, 0x44, 0x83, 0xfe, 0xb5, 0x5e, 0x43, 0xf4, 0x6d, 0x88, 0x81, 0xbd, 0x35, 0x8e, 0xbf,
0x75, 0x9a, 0x06, 0xe7, 0xcd, 0x81, 0xf5, 0xca, 0x48, 0xbf, 0xb7, 0x1b, 0x19, 0xc8, 0x02,
0x61, 0x45, 0x00, 0x0a, 0x17, 0x39, 0xb1, 0x18, 0x89, 0xc7, 0x3d, 0x53, 0xa9, 0x78, 0x17,
0xd2, 0x82, 0x4e, 0x52, 0xe6, 0x76, 0xbd, 0xe5, 0xce, 0xee, 0x9a, 0x86, 0x6e, 0x8b, 0x4c,
0xca, 0x8c, 0xf2, 0x99, 0xd8, 0x18, 0x53, 0xa0, 0x06, 0x15, 0x02, 0xff, 0x1a, 0x7b, 0x11,
0x82, 0x7c, 0x96, 0x7d, 0x8c, 0xf2, 0xc6, 0x21, 0xa6, 0x24, 0xda, 0x96, 0x75, 0xd2, 0xab,
0xc9, 0x30, 0x89, 0x22, 0x18, 0x14, 0x7e, 0xa9, 0x07, 0xa6, 0xf0, 0x88, 0x7a, 0x86, 0x6c,
0x7b, 0x79, 0x89, 0xe0, 0x6c, 0xcf, 0x82, 0x66, 0x62, 0x63, 0x79, 0x98, 0x37, 0x44, 0xce,
0x1d, 0xe1, 0xb1, 0xb5, 0x12, 0xca, 0x63, 0x6f, 0x25, 0x47, 0x14, 0x1d, 0xef, 0x48, 0x47,
0xac, 0x64, 0x6a, 0x76, 0xbc, 0x25, 0xbc, 0xed, 0x98, 0xb7, 0x34, 0xfd, 0xd6, 0x65, 0x15,
0x4d, 0x85, 0xe8, 0x1e, 0x65, 0x08, 0x09, 0x28, 0x19, 0x39, 0x04, 0xf7, 0x6f, 0xec, 0x96,
0x27, 0xa2, 0x23, 0x3b, 0x2f, 0x75, 0x02, 0x09, 0x25, 0x0d, 0x46, 0xb9, 0x77, 0x65, 0xd0,
0x19, 0xa5, 0x5a, 0x97, 0xc8, 0xf9, 0x81, 0x4b, 0xfd, 0xb5, 0x38, 0xb9, 0xbc, 0x68, 0x55,
0xac, 0x35, 0x1b, 0xf1, 0xe4
};
/* Test vectors for Keccak-p[1600,12] (12 rounds, TurboSHAKE) */
/* Test vector 3: All-zero input for Keccak-p[1600,12] */
static const unsigned char keccak_p_12_zero_expected[200] = {
0x17, 0x86, 0xa7, 0xb9, 0x38, 0x54, 0x5e, 0x8e, 0x1e, 0xd0, 0x59, 0xf2, 0x50, 0x6a, 0xcd,
0xd9, 0x35, 0x1f, 0xa9, 0x52, 0xc6, 0xe7, 0xb8, 0x87, 0xc5, 0xe0, 0xe4, 0xcd, 0x67, 0xe0,
0x93, 0x10, 0x45, 0x5a, 0xd9, 0xf2, 0x90, 0xab, 0x33, 0xb0, 0x45, 0x1a, 0xdd, 0xa8, 0x72,
0x2f, 0xa7, 0xe0, 0x9c, 0x2f, 0x67, 0x14, 0xaa, 0x80, 0x37, 0xc5, 0x1d, 0x07, 0x51, 0x00,
0xf5, 0x47, 0xdd, 0x3e, 0xcc, 0x8a, 0x17, 0x0c, 0x31, 0x1d, 0xa3, 0xb3, 0xa0, 0xaa, 0x57,
0x92, 0xa5, 0x86, 0xb5, 0x79, 0x9b, 0xf9, 0xb1, 0xb3, 0x3d, 0x7c, 0x4a, 0xbc, 0x93, 0x67,
0x8a, 0xe6, 0x63, 0x40, 0x87, 0x68, 0x66, 0x25, 0x0e, 0x2e, 0x33, 0x03, 0x6c, 0x5c, 0xda,
0x30, 0xf0, 0xb9, 0x02, 0x12, 0xaa, 0x9c, 0x9f, 0x7a, 0xcf, 0x2b, 0x78, 0x9a, 0x3b, 0x5f,
0x23, 0x79, 0xae, 0x61, 0xe0, 0xc1, 0x36, 0xe5, 0xec, 0x87, 0x3c, 0xb7, 0x18, 0xb6, 0xe9,
0x6d, 0xc2, 0x8a, 0x91, 0x70, 0xf1, 0xd1, 0xbe, 0x2a, 0xb7, 0x24, 0xed, 0xda, 0x53, 0xbd,
0xab, 0x6a, 0x5a, 0xe1, 0x2e, 0x2c, 0x6a, 0x41, 0xc1, 0xbf, 0xaf, 0x52, 0x09, 0xb9, 0x36,
0xe0, 0xcf, 0xc6, 0xd7, 0x60, 0x70, 0xdc, 0x17, 0x36, 0x50, 0x45, 0xe4, 0x7a, 0x9f, 0xc2,
0xb2, 0x11, 0x56, 0x62, 0x7a, 0x64, 0x30, 0x2c, 0xdb, 0x71, 0x36, 0xd4, 0x1c, 0xa0, 0x2c,
0x22, 0x76, 0x0d, 0xfd, 0xcf
};
printf("=== Keccak-1600 Core Function Tests ===\n\n");
/* Basic API tests */
printf("Test 1: API constants\n");
printf(" statebytes: %u\n", (unsigned int) crypto_core_keccak1600_statebytes());
assert(crypto_core_keccak1600_statebytes() == crypto_core_keccak1600_STATEBYTES);
assert(crypto_core_keccak1600_STATEBYTES == 200U);
printf(" PASS: statebytes = 200\n\n");
/* Test 2: Init function */
printf("Test 2: crypto_core_keccak1600_init\n");
memset(state, 0xFF, sizeof state);
crypto_core_keccak1600_init(state);
for (i = 0; i < crypto_core_keccak1600_STATEBYTES; i++) {
if (state[i] != 0) {
printf(" FAIL: State not zeroed at byte %u\n", (unsigned int) i);
test_failures++;
break;
}
}
if (i == crypto_core_keccak1600_STATEBYTES) {
printf(" PASS: State initialized to zeros\n\n");
}
/* Test 3: XOR and extract functions */
printf("Test 3: crypto_core_keccak1600_xor_bytes and extract_bytes\n");
crypto_core_keccak1600_init(state);
unsigned char test_data[64];
for (i = 0; i < sizeof test_data; i++) {
test_data[i] = (unsigned char) i;
}
crypto_core_keccak1600_xor_bytes(state, test_data, 0, sizeof test_data);
crypto_core_keccak1600_extract_bytes(state, extracted, 0, sizeof test_data);
if (memcmp(extracted, test_data, sizeof test_data) == 0) {
printf(" PASS: XOR and extract work correctly\n\n");
} else {
printf(" FAIL: XOR/extract mismatch\n\n");
test_failures++;
}
/* Test 4: Keccak-f[1600] with all-zero input (24 rounds) */
printf("Test 4: Keccak-f[1600] (24 rounds) - Zero input\n");
memcpy(state, keccak_f_1600_zero_input, 200);
crypto_core_keccak1600_permute_24(state);
test_failures +=
compare_states(" Keccak-f[1600] zero", state, keccak_f_1600_zero_expected, 200);
printf("\n");
/* Test 5: Keccak-f[1600] with pattern input (24 rounds) */
printf("Test 5: Keccak-f[1600] (24 rounds) - Pattern 0xa3 input\n");
memcpy(state, keccak_f_1600_pattern_input, 200);
crypto_core_keccak1600_permute_24(state);
test_failures +=
compare_states(" Keccak-f[1600] pattern", state, keccak_f_1600_pattern_expected, 200);
printf("\n");
/* Test 6: Keccak-p[1600,12] with all-zero input (12 rounds) */
printf("Test 6: Keccak-p[1600,12] (12 rounds) - Zero input\n");
crypto_core_keccak1600_init(state);
crypto_core_keccak1600_permute_12(state);
test_failures +=
compare_states(" Keccak-p[1600,12] zero", state, keccak_p_12_zero_expected, 200);
printf("\n");
/* Test 7: Verify 12 and 24 rounds produce different outputs */
printf("Test 7: Verify 12-round and 24-round differ\n");
unsigned char state_12[200], state_24[200];
crypto_core_keccak1600_init(state_12);
crypto_core_keccak1600_init(state_24);
crypto_core_keccak1600_permute_12(state_12);
crypto_core_keccak1600_permute_24(state_24);
int differs = 0;
for (i = 0; i < 200; i++) {
if (state_12[i] != state_24[i]) {
differs = 1;
break;
}
}
if (differs) {
printf(" PASS: 12-round and 24-round produce different outputs\n");
printf(" First difference at byte %u: 12-round=0x%02x, 24-round=0x%02x\n\n",
(unsigned int) i, state_12[i], state_24[i]);
} else {
printf(" FAIL: 12-round and 24-round produce identical outputs\n\n");
test_failures++;
}
/* Test 8: Multiple permutations */
printf("Test 8: Double permutation consistency\n");
crypto_core_keccak1600_init(state);
crypto_core_keccak1600_permute_24(state);
memcpy(state_24, state, 200);
crypto_core_keccak1600_permute_24(state);
printf(" After 24+24 rounds: ");
print_hex("", state, 32);
crypto_core_keccak1600_init(state);
crypto_core_keccak1600_permute_12(state);
memcpy(state_12, state, 200);
crypto_core_keccak1600_permute_12(state);
printf(" After 12+12 rounds: ");
print_hex("", state, 32);
printf("\n");
/* Final summary */
printf("=== Test Summary ===\n");
if (test_failures == 0) {
printf("All tests PASSED!\n");
return 0;
} else {
printf("FAILED: %d test(s) failed\n", test_failures);
return 1;
}
}
+31
View File
@@ -0,0 +1,31 @@
=== Keccak-1600 Core Function Tests ===
Test 1: API constants
statebytes: 200
PASS: statebytes = 200
Test 2: crypto_core_keccak1600_init
PASS: State initialized to zeros
Test 3: crypto_core_keccak1600_xor_bytes and extract_bytes
PASS: XOR and extract work correctly
Test 4: Keccak-f[1600] (24 rounds) - Zero input
PASS: Keccak-f[1600] zero
Test 5: Keccak-f[1600] (24 rounds) - Pattern 0xa3 input
PASS: Keccak-f[1600] pattern
Test 6: Keccak-p[1600,12] (12 rounds) - Zero input
PASS: Keccak-p[1600,12] zero
Test 7: Verify 12-round and 24-round differ
PASS: 12-round and 24-round produce different outputs
First difference at byte 0: 12-round=0x17, 24-round=0xe7
Test 8: Double permutation consistency
After 24+24 rounds: 3ccb6ef94d955c2d6db55770d02c336a6c6bd770128d3d0994d06955b2d9208a
After 12+12 rounds: 048cbb36dc66034bc96a2de69835165f46e73b55de051b436c7a6154c9469f48
=== Test Summary ===
All tests PASSED!
+215
View File
@@ -0,0 +1,215 @@
#define TEST_NAME "xof_shake128"
#include "cmptest.h"
typedef struct {
const unsigned char *msg;
size_t msg_len;
const unsigned char *out;
size_t out_len;
} testvector;
static void
shake128_manual_with_domain(unsigned char *out, size_t outlen, const unsigned char *in,
size_t inlen, unsigned char domain)
{
unsigned char state[crypto_core_keccak1600_STATEBYTES];
size_t rate = crypto_xof_shake128_blockbytes();
size_t offset = 0;
size_t consumed = 0;
size_t chunk_size;
size_t extracted = 0;
unsigned char pad;
crypto_core_keccak1600_init(state);
while (consumed < inlen) {
if (offset == rate) {
crypto_core_keccak1600_permute_24(state);
offset = 0;
}
chunk_size = rate - offset;
if (chunk_size > inlen - consumed) {
chunk_size = inlen - consumed;
}
crypto_core_keccak1600_xor_bytes(state, &in[consumed], offset, chunk_size);
offset += chunk_size;
consumed += chunk_size;
}
if (offset == rate) {
crypto_core_keccak1600_permute_24(state);
offset = 0;
}
if (offset == rate - 1) {
pad = (unsigned char) (domain ^ 0x80);
crypto_core_keccak1600_xor_bytes(state, &pad, offset, 1);
} else {
crypto_core_keccak1600_xor_bytes(state, &domain, offset, 1);
pad = 0x80;
crypto_core_keccak1600_xor_bytes(state, &pad, rate - 1, 1);
}
crypto_core_keccak1600_permute_24(state);
offset = 0;
while (extracted < outlen) {
if (offset == rate) {
crypto_core_keccak1600_permute_24(state);
offset = 0;
}
chunk_size = rate - offset;
if (chunk_size > outlen - extracted) {
chunk_size = outlen - extracted;
}
crypto_core_keccak1600_extract_bytes(state, &out[extracted], offset, chunk_size);
offset += chunk_size;
extracted += chunk_size;
}
}
int
main(void)
{
/* Test vectors from NIST and various sources */
static const unsigned char msg_empty[] = "";
static const unsigned char msg_abc[] = { 0x61, 0x62, 0x63 };
static const unsigned char msg_fox[] = { 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b,
0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f,
0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f,
0x76, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c,
0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67 };
static const unsigned char msg_rate_block[168] = { 0 };
static const unsigned char out_empty_32[] = { 0x7f, 0x9c, 0x2b, 0xa4, 0xe8, 0x8f, 0x82, 0x7d,
0x61, 0x60, 0x45, 0x50, 0x76, 0x05, 0x85, 0x3e,
0xd7, 0x3b, 0x80, 0x93, 0xf6, 0xef, 0xbc, 0x88,
0xeb, 0x1a, 0x6e, 0xac, 0xfa, 0x66, 0xef, 0x26 };
static const unsigned char out_empty_64[] = {
0x7f, 0x9c, 0x2b, 0xa4, 0xe8, 0x8f, 0x82, 0x7d, 0x61, 0x60, 0x45, 0x50, 0x76,
0x05, 0x85, 0x3e, 0xd7, 0x3b, 0x80, 0x93, 0xf6, 0xef, 0xbc, 0x88, 0xeb, 0x1a,
0x6e, 0xac, 0xfa, 0x66, 0xef, 0x26, 0x3c, 0xb1, 0xee, 0xa9, 0x88, 0x00, 0x4b,
0x93, 0x10, 0x3c, 0xfb, 0x0a, 0xee, 0xfd, 0x2a, 0x68, 0x6e, 0x01, 0xfa, 0x4a,
0x58, 0xe8, 0xa3, 0x63, 0x9c, 0xa8, 0xa1, 0xe3, 0xf9, 0xae, 0x57, 0xe2
};
static const unsigned char out_abc_32[] = { 0x58, 0x81, 0x09, 0x2d, 0xd8, 0x18, 0xbf, 0x5c,
0xf8, 0xa3, 0xdd, 0xb7, 0x93, 0xfb, 0xcb, 0xa7,
0x40, 0x97, 0xd5, 0xc5, 0x26, 0xa6, 0xd3, 0x5f,
0x97, 0xb8, 0x33, 0x51, 0x94, 0x0f, 0x2c, 0xc8 };
static const unsigned char out_fox_32[] = { 0xf4, 0x20, 0x2e, 0x3c, 0x58, 0x52, 0xf9, 0x18,
0x2a, 0x04, 0x30, 0xfd, 0x81, 0x44, 0xf0, 0xa7,
0x4b, 0x95, 0xe7, 0x41, 0x7e, 0xca, 0xe1, 0x7d,
0xb0, 0xf8, 0xcf, 0xee, 0xd0, 0xe3, 0xe6, 0x6e };
static const unsigned char out_fox_64[] = {
0xf4, 0x20, 0x2e, 0x3c, 0x58, 0x52, 0xf9, 0x18, 0x2a, 0x04, 0x30, 0xfd, 0x81,
0x44, 0xf0, 0xa7, 0x4b, 0x95, 0xe7, 0x41, 0x7e, 0xca, 0xe1, 0x7d, 0xb0, 0xf8,
0xcf, 0xee, 0xd0, 0xe3, 0xe6, 0x6e, 0xb5, 0x58, 0x5e, 0xc6, 0xf8, 0x60, 0x21,
0xca, 0xcf, 0x27, 0x2c, 0x79, 0x8b, 0xcf, 0x97, 0xd3, 0x68, 0xb8, 0x86, 0xb1,
0x8f, 0xec, 0x3a, 0x57, 0x1f, 0x09, 0x60, 0x86, 0xa5, 0x23, 0x71, 0x7a
};
static const unsigned char out_rate_block_32[] = { 0x7c, 0x00, 0xff, 0x47, 0x48, 0x87, 0x0c,
0xb2, 0x6d, 0xa4, 0xdc, 0x07, 0x8a, 0xff,
0x74, 0x47, 0x7a, 0xb1, 0x53, 0xfa, 0x11,
0x91, 0xc7, 0xb6, 0x36, 0xfe, 0xa6, 0xc0,
0x1e, 0xcc, 0x1f, 0xab };
testvector vectors[] = { { msg_empty, 0, out_empty_32, 32 },
{ msg_empty, 0, out_empty_64, 64 },
{ msg_abc, 3, out_abc_32, 32 },
{ msg_fox, 43, out_fox_32, 32 },
{ msg_fox, 43, out_fox_64, 64 },
{ msg_rate_block, sizeof msg_rate_block, out_rate_block_32, 32 } };
unsigned char out[256];
crypto_xof_shake128_state state;
size_t i;
/* Test constants */
assert(crypto_xof_shake128_blockbytes() == 168);
assert(crypto_xof_shake128_statebytes() == 256);
assert(crypto_xof_shake128_domain_standard() == 0x1F);
/* Test one-shot API */
for (i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
crypto_xof_shake128(out, vectors[i].out_len, vectors[i].msg, vectors[i].msg_len);
if (memcmp(out, vectors[i].out, vectors[i].out_len) != 0) {
printf("Test vector %zu failed (one-shot)\n", i);
return 1;
}
}
/* Test streaming API */
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_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;
}
}
/* Test multiple squeeze calls */
crypto_xof_shake128_init(&state);
crypto_xof_shake128_update(&state, msg_abc, 3);
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");
return 1;
}
/* Test custom domain byte produces different output */
crypto_xof_shake128_init(&state);
crypto_xof_shake128_update(&state, msg_abc, 3);
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_squeeze(&state, out + 32, 32);
if (memcmp(out, out + 32, 32) == 0) {
printf("Custom domain byte test failed (outputs should differ)\n");
return 1;
}
/* 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_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 domain byte with MSB set when padding overlaps */
{
unsigned char msg[crypto_xof_shake128_BLOCKBYTES - 1];
unsigned char out_manual[32];
unsigned char out_impl[32];
const unsigned char domain = 0x99;
memset(msg, 0xAA, sizeof msg);
shake128_manual_with_domain(out_manual, sizeof out_manual, msg, sizeof msg, domain);
crypto_xof_shake128_init_with_domain(&state, domain);
crypto_xof_shake128_update(&state, msg, sizeof msg);
crypto_xof_shake128_squeeze(&state, out_impl, sizeof out_impl);
if (memcmp(out_manual, out_impl, sizeof out_manual) != 0) {
printf("Domain MSB padding test failed\n");
return 1;
}
}
printf("All SHAKE-128 tests passed\n");
return 0;
}
+1
View File
@@ -0,0 +1 @@
All SHAKE-128 tests passed
+216
View File
@@ -0,0 +1,216 @@
#define TEST_NAME "xof_shake256"
#include "cmptest.h"
typedef struct {
const unsigned char *msg;
size_t msg_len;
const unsigned char *out;
size_t out_len;
} testvector;
static void
shake256_manual_with_domain(unsigned char *out, size_t outlen, const unsigned char *in,
size_t inlen, unsigned char domain)
{
unsigned char state[crypto_core_keccak1600_STATEBYTES];
size_t rate = crypto_xof_shake256_blockbytes();
size_t offset = 0;
size_t consumed = 0;
size_t chunk_size;
size_t extracted = 0;
unsigned char pad;
crypto_core_keccak1600_init(state);
while (consumed < inlen) {
if (offset == rate) {
crypto_core_keccak1600_permute_24(state);
offset = 0;
}
chunk_size = rate - offset;
if (chunk_size > inlen - consumed) {
chunk_size = inlen - consumed;
}
crypto_core_keccak1600_xor_bytes(state, &in[consumed], offset, chunk_size);
offset += chunk_size;
consumed += chunk_size;
}
if (offset == rate) {
crypto_core_keccak1600_permute_24(state);
offset = 0;
}
if (offset == rate - 1) {
pad = (unsigned char) (domain ^ 0x80);
crypto_core_keccak1600_xor_bytes(state, &pad, offset, 1);
} else {
crypto_core_keccak1600_xor_bytes(state, &domain, offset, 1);
pad = 0x80;
crypto_core_keccak1600_xor_bytes(state, &pad, rate - 1, 1);
}
crypto_core_keccak1600_permute_24(state);
offset = 0;
while (extracted < outlen) {
if (offset == rate) {
crypto_core_keccak1600_permute_24(state);
offset = 0;
}
chunk_size = rate - offset;
if (chunk_size > outlen - extracted) {
chunk_size = outlen - extracted;
}
crypto_core_keccak1600_extract_bytes(state, &out[extracted], offset, chunk_size);
offset += chunk_size;
extracted += chunk_size;
}
}
int
main(void)
{
/* Test vectors from NIST FIPS 202 and various sources */
static const unsigned char msg_empty[] = "";
static const unsigned char msg_abc[] = { 0x61, 0x62, 0x63 };
static const unsigned char msg_fox[] = { 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b,
0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f,
0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f,
0x76, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c,
0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67 };
static const unsigned char msg_rate_block[136] = { 0 };
/* SHAKE-256 test vectors */
static const unsigned char out_empty_32[] = { 0x46, 0xb9, 0xdd, 0x2b, 0x0b, 0xa8, 0x8d, 0x13,
0x23, 0x3b, 0x3f, 0xeb, 0x74, 0x3e, 0xeb, 0x24,
0x3f, 0xcd, 0x52, 0xea, 0x62, 0xb8, 0x1b, 0x82,
0xb5, 0x0c, 0x27, 0x64, 0x6e, 0xd5, 0x76, 0x2f };
static const unsigned char out_empty_64[] = {
0x46, 0xb9, 0xdd, 0x2b, 0x0b, 0xa8, 0x8d, 0x13, 0x23, 0x3b, 0x3f, 0xeb, 0x74,
0x3e, 0xeb, 0x24, 0x3f, 0xcd, 0x52, 0xea, 0x62, 0xb8, 0x1b, 0x82, 0xb5, 0x0c,
0x27, 0x64, 0x6e, 0xd5, 0x76, 0x2f, 0xd7, 0x5d, 0xc4, 0xdd, 0xd8, 0xc0, 0xf2,
0x00, 0xcb, 0x05, 0x01, 0x9d, 0x67, 0xb5, 0x92, 0xf6, 0xfc, 0x82, 0x1c, 0x49,
0x47, 0x9a, 0xb4, 0x86, 0x40, 0x29, 0x2e, 0xac, 0xb3, 0xb7, 0xc4, 0xbe
};
static const unsigned char out_abc_32[] = { 0x48, 0x33, 0x66, 0x60, 0x13, 0x60, 0xa8, 0x77,
0x1c, 0x68, 0x63, 0x08, 0x0c, 0xc4, 0x11, 0x4d,
0x8d, 0xb4, 0x45, 0x30, 0xf8, 0xf1, 0xe1, 0xee,
0x4f, 0x94, 0xea, 0x37, 0xe7, 0x8b, 0x57, 0x39 };
static const unsigned char out_fox_32[] = { 0x2f, 0x67, 0x13, 0x43, 0xd9, 0xb2, 0xe1, 0x60,
0x4d, 0xc9, 0xdc, 0xf0, 0x75, 0x3e, 0x5f, 0xe1,
0x5c, 0x7c, 0x64, 0xa0, 0xd2, 0x83, 0xcb, 0xbf,
0x72, 0x2d, 0x41, 0x1a, 0x0e, 0x36, 0xf6, 0xca };
static const unsigned char out_fox_64[] = {
0x2f, 0x67, 0x13, 0x43, 0xd9, 0xb2, 0xe1, 0x60, 0x4d, 0xc9, 0xdc, 0xf0, 0x75,
0x3e, 0x5f, 0xe1, 0x5c, 0x7c, 0x64, 0xa0, 0xd2, 0x83, 0xcb, 0xbf, 0x72, 0x2d,
0x41, 0x1a, 0x0e, 0x36, 0xf6, 0xca, 0x1d, 0x01, 0xd1, 0x36, 0x9a, 0x23, 0x53,
0x9c, 0xd8, 0x0f, 0x7c, 0x05, 0x4b, 0x6e, 0x5d, 0xaf, 0x9c, 0x96, 0x2c, 0xad,
0x5b, 0x8e, 0xd5, 0xbd, 0x11, 0x99, 0x8b, 0x40, 0xd5, 0x73, 0x44, 0x42
};
static const unsigned char out_rate_block_32[] = { 0xea, 0x94, 0x7b, 0x83, 0x5f, 0xec, 0x1f,
0x9b, 0x0a, 0x7e, 0xab, 0xba, 0x90, 0x1d,
0xeb, 0x78, 0x81, 0xfd, 0x99, 0x99, 0xa1,
0xcb, 0xd5, 0xcc, 0xbb, 0x5a, 0x9a, 0xfa,
0xb7, 0xf6, 0xfe, 0x70 };
testvector vectors[] = { { msg_empty, 0, out_empty_32, 32 },
{ msg_empty, 0, out_empty_64, 64 },
{ msg_abc, 3, out_abc_32, 32 },
{ msg_fox, 43, out_fox_32, 32 },
{ msg_fox, 43, out_fox_64, 64 },
{ msg_rate_block, sizeof msg_rate_block, out_rate_block_32, 32 } };
unsigned char out[256];
crypto_xof_shake256_state state;
size_t i;
/* Test constants */
assert(crypto_xof_shake256_blockbytes() == 136);
assert(crypto_xof_shake256_statebytes() == 256);
assert(crypto_xof_shake256_domain_standard() == 0x1F);
/* Test one-shot API */
for (i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
crypto_xof_shake256(out, vectors[i].out_len, vectors[i].msg, vectors[i].msg_len);
if (memcmp(out, vectors[i].out, vectors[i].out_len) != 0) {
printf("Test vector %zu failed (one-shot)\n", i);
return 1;
}
}
/* Test streaming API */
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_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;
}
}
/* Test multiple squeeze calls */
crypto_xof_shake256_init(&state);
crypto_xof_shake256_update(&state, msg_abc, 3);
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");
return 1;
}
/* Test custom domain byte produces different output */
crypto_xof_shake256_init(&state);
crypto_xof_shake256_update(&state, msg_abc, 3);
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_squeeze(&state, out + 32, 32);
if (memcmp(out, out + 32, 32) == 0) {
printf("Custom domain byte test failed (outputs should differ)\n");
return 1;
}
/* 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_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 domain byte with MSB set when padding overlaps */
{
unsigned char msg[crypto_xof_shake256_BLOCKBYTES - 1];
unsigned char out_manual[32];
unsigned char out_impl[32];
const unsigned char domain = 0x99;
memset(msg, 0xAA, sizeof msg);
shake256_manual_with_domain(out_manual, sizeof out_manual, msg, sizeof msg, domain);
crypto_xof_shake256_init_with_domain(&state, domain);
crypto_xof_shake256_update(&state, msg, sizeof msg);
crypto_xof_shake256_squeeze(&state, out_impl, sizeof out_impl);
if (memcmp(out_manual, out_impl, sizeof out_manual) != 0) {
printf("Domain MSB padding test failed\n");
return 1;
}
}
printf("All SHAKE-256 tests passed\n");
return 0;
}
+1
View File
@@ -0,0 +1 @@
All SHAKE-256 tests passed
+215
View File
@@ -0,0 +1,215 @@
#define TEST_NAME "xof_turboshake128"
#include "cmptest.h"
typedef struct {
const unsigned char *msg;
size_t msg_len;
const unsigned char *out;
size_t out_len;
} testvector;
static void
turboshake128_manual_with_domain(unsigned char *out, size_t outlen, const unsigned char *in,
size_t inlen, unsigned char domain)
{
unsigned char state[crypto_core_keccak1600_STATEBYTES];
size_t rate = crypto_xof_turboshake128_blockbytes();
size_t offset = 0;
size_t consumed = 0;
size_t chunk_size;
size_t extracted = 0;
unsigned char pad;
crypto_core_keccak1600_init(state);
while (consumed < inlen) {
if (offset == rate) {
crypto_core_keccak1600_permute_12(state);
offset = 0;
}
chunk_size = rate - offset;
if (chunk_size > inlen - consumed) {
chunk_size = inlen - consumed;
}
crypto_core_keccak1600_xor_bytes(state, &in[consumed], offset, chunk_size);
offset += chunk_size;
consumed += chunk_size;
}
if (offset == rate) {
crypto_core_keccak1600_permute_12(state);
offset = 0;
}
if (offset == rate - 1) {
pad = (unsigned char) (domain ^ 0x80);
crypto_core_keccak1600_xor_bytes(state, &pad, offset, 1);
} else {
crypto_core_keccak1600_xor_bytes(state, &domain, offset, 1);
pad = 0x80;
crypto_core_keccak1600_xor_bytes(state, &pad, rate - 1, 1);
}
crypto_core_keccak1600_permute_12(state);
offset = 0;
while (extracted < outlen) {
if (offset == rate) {
crypto_core_keccak1600_permute_12(state);
offset = 0;
}
chunk_size = rate - offset;
if (chunk_size > outlen - extracted) {
chunk_size = outlen - extracted;
}
crypto_core_keccak1600_extract_bytes(state, &out[extracted], offset, chunk_size);
offset += chunk_size;
extracted += chunk_size;
}
}
int
main(void)
{
/* Test vectors from Zig standard library (domain byte 0x1F) */
static const unsigned char msg_empty[] = "";
static const unsigned char msg_abc[] = { 0x61, 0x62, 0x63 };
static const unsigned char msg_fox[] = { 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b,
0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f,
0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f,
0x76, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c,
0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67 };
static const unsigned char msg_rate_block[168] = { 0 };
static const unsigned char out_empty_32[] = { 0x1e, 0x41, 0x5f, 0x1c, 0x59, 0x83, 0xaf, 0xf2,
0x16, 0x92, 0x17, 0x27, 0x7d, 0x17, 0xbb, 0x53,
0x8c, 0xd9, 0x45, 0xa3, 0x97, 0xdd, 0xec, 0x54,
0x1f, 0x1c, 0xe4, 0x1a, 0xf2, 0xc1, 0xb7, 0x4c };
static const unsigned char out_empty_64[] = {
0x1e, 0x41, 0x5f, 0x1c, 0x59, 0x83, 0xaf, 0xf2, 0x16, 0x92, 0x17, 0x27, 0x7d,
0x17, 0xbb, 0x53, 0x8c, 0xd9, 0x45, 0xa3, 0x97, 0xdd, 0xec, 0x54, 0x1f, 0x1c,
0xe4, 0x1a, 0xf2, 0xc1, 0xb7, 0x4c, 0x3e, 0x8c, 0xca, 0xe2, 0xa4, 0xda, 0xe5,
0x6c, 0x84, 0xa0, 0x4c, 0x23, 0x85, 0xc0, 0x3c, 0x15, 0xe8, 0x19, 0x3b, 0xdf,
0x58, 0x73, 0x73, 0x63, 0x32, 0x16, 0x91, 0xc0, 0x54, 0x62, 0xc8, 0xdf
};
static const unsigned char out_abc_32[] = { 0xdc, 0xf1, 0x64, 0x6d, 0xfe, 0x99, 0x3a, 0x8e,
0xb6, 0xb7, 0x82, 0xd1, 0xfa, 0xac, 0xa6, 0xd8,
0x24, 0x16, 0xa5, 0xdc, 0xf1, 0xde, 0x98, 0xee,
0x3c, 0x6d, 0xbc, 0x5e, 0x1d, 0xc6, 0x30, 0x18 };
static const unsigned char out_fox_32[] = { 0x76, 0xa1, 0x72, 0x0a, 0x48, 0x48, 0xab, 0x64,
0xe6, 0x7e, 0x56, 0x3f, 0x16, 0xb8, 0xc5, 0xaa,
0x49, 0x2b, 0x69, 0x8a, 0x4d, 0x93, 0x42, 0x97,
0x35, 0xfd, 0x02, 0x35, 0x46, 0x57, 0xfb, 0xf7 };
static const unsigned char out_fox_64[] = {
0x76, 0xa1, 0x72, 0x0a, 0x48, 0x48, 0xab, 0x64, 0xe6, 0x7e, 0x56, 0x3f, 0x16,
0xb8, 0xc5, 0xaa, 0x49, 0x2b, 0x69, 0x8a, 0x4d, 0x93, 0x42, 0x97, 0x35, 0xfd,
0x02, 0x35, 0x46, 0x57, 0xfb, 0xf7, 0xa0, 0x68, 0x9e, 0xc7, 0x7b, 0x4c, 0x79,
0x5f, 0xda, 0x9d, 0xaa, 0xb4, 0x10, 0xc6, 0x30, 0x92, 0xf5, 0x42, 0x00, 0x84,
0x6c, 0x34, 0x12, 0x0f, 0xf2, 0xb2, 0x53, 0xe9, 0xfd, 0x8d, 0x9f, 0xc4
};
static const unsigned char out_rate_block_32[] = { 0xdb, 0xa6, 0xe2, 0x67, 0xbd, 0xd5, 0x67,
0xdb, 0x0a, 0xd2, 0x63, 0x6e, 0x61, 0xf1,
0xae, 0x58, 0x9a, 0x81, 0xc1, 0xa9, 0xc1,
0x1f, 0x7f, 0x76, 0x93, 0x0a, 0x35, 0xea,
0x42, 0x47, 0x56, 0xd0 };
testvector vectors[] = { { msg_empty, 0, out_empty_32, 32 },
{ msg_empty, 0, out_empty_64, 64 },
{ msg_abc, 3, out_abc_32, 32 },
{ msg_fox, 43, out_fox_32, 32 },
{ msg_fox, 43, out_fox_64, 64 },
{ msg_rate_block, sizeof msg_rate_block, out_rate_block_32, 32 } };
unsigned char out[256];
crypto_xof_turboshake128_state state;
size_t i;
/* Test constants */
assert(crypto_xof_turboshake128_blockbytes() == 168);
assert(crypto_xof_turboshake128_statebytes() == 256);
assert(crypto_xof_turboshake128_domain_standard() == 0x1F);
/* Test one-shot API */
for (i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
crypto_xof_turboshake128(out, vectors[i].out_len, vectors[i].msg, vectors[i].msg_len);
if (memcmp(out, vectors[i].out, vectors[i].out_len) != 0) {
printf("Test vector %zu failed (one-shot)\n", i);
return 1;
}
}
/* Test streaming API */
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_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;
}
}
/* Test multiple squeeze calls */
crypto_xof_turboshake128_init(&state);
crypto_xof_turboshake128_update(&state, msg_abc, 3);
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");
return 1;
}
/* Test custom domain byte produces different output */
crypto_xof_turboshake128_init(&state);
crypto_xof_turboshake128_update(&state, msg_abc, 3);
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_squeeze(&state, out + 32, 32);
if (memcmp(out, out + 32, 32) == 0) {
printf("Custom domain byte test failed (outputs should differ)\n");
return 1;
}
/* 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_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 domain byte with MSB set when padding overlaps */
{
unsigned char msg[crypto_xof_turboshake128_BLOCKBYTES - 1];
unsigned char out_manual[32];
unsigned char out_impl[32];
const unsigned char domain = 0x99;
memset(msg, 0xAA, sizeof msg);
turboshake128_manual_with_domain(out_manual, sizeof out_manual, msg, sizeof msg, domain);
crypto_xof_turboshake128_init_with_domain(&state, domain);
crypto_xof_turboshake128_update(&state, msg, sizeof msg);
crypto_xof_turboshake128_squeeze(&state, out_impl, sizeof out_impl);
if (memcmp(out_manual, out_impl, sizeof out_manual) != 0) {
printf("Domain MSB padding test failed\n");
return 1;
}
}
printf("All TurboSHAKE-128 tests passed\n");
return 0;
}
+1
View File
@@ -0,0 +1 @@
All TurboSHAKE-128 tests passed
+215
View File
@@ -0,0 +1,215 @@
#define TEST_NAME "xof_turboshake256"
#include "cmptest.h"
typedef struct {
const unsigned char *msg;
size_t msg_len;
const unsigned char *out;
size_t out_len;
} testvector;
static void
turboshake256_manual_with_domain(unsigned char *out, size_t outlen, const unsigned char *in,
size_t inlen, unsigned char domain)
{
unsigned char state[crypto_core_keccak1600_STATEBYTES];
size_t rate = crypto_xof_turboshake256_blockbytes();
size_t offset = 0;
size_t consumed = 0;
size_t chunk_size;
size_t extracted = 0;
unsigned char pad;
crypto_core_keccak1600_init(state);
while (consumed < inlen) {
if (offset == rate) {
crypto_core_keccak1600_permute_12(state);
offset = 0;
}
chunk_size = rate - offset;
if (chunk_size > inlen - consumed) {
chunk_size = inlen - consumed;
}
crypto_core_keccak1600_xor_bytes(state, &in[consumed], offset, chunk_size);
offset += chunk_size;
consumed += chunk_size;
}
if (offset == rate) {
crypto_core_keccak1600_permute_12(state);
offset = 0;
}
if (offset == rate - 1) {
pad = (unsigned char) (domain ^ 0x80);
crypto_core_keccak1600_xor_bytes(state, &pad, offset, 1);
} else {
crypto_core_keccak1600_xor_bytes(state, &domain, offset, 1);
pad = 0x80;
crypto_core_keccak1600_xor_bytes(state, &pad, rate - 1, 1);
}
crypto_core_keccak1600_permute_12(state);
offset = 0;
while (extracted < outlen) {
if (offset == rate) {
crypto_core_keccak1600_permute_12(state);
offset = 0;
}
chunk_size = rate - offset;
if (chunk_size > outlen - extracted) {
chunk_size = outlen - extracted;
}
crypto_core_keccak1600_extract_bytes(state, &out[extracted], offset, chunk_size);
offset += chunk_size;
extracted += chunk_size;
}
}
int
main(void)
{
/* Test vectors from Zig standard library (domain byte 0x1F) */
static const unsigned char msg_empty[] = "";
static const unsigned char msg_abc[] = { 0x61, 0x62, 0x63 };
static const unsigned char msg_fox[] = { 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b,
0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f,
0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f,
0x76, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c,
0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67 };
static const unsigned char msg_rate_block[136] = { 0 };
static const unsigned char out_empty_32[] = { 0x36, 0x7a, 0x32, 0x9d, 0xaf, 0xea, 0x87, 0x1c,
0x78, 0x02, 0xec, 0x67, 0xf9, 0x05, 0xae, 0x13,
0xc5, 0x76, 0x95, 0xdc, 0x2c, 0x66, 0x63, 0xc6,
0x10, 0x35, 0xf5, 0x9a, 0x18, 0xf8, 0xe7, 0xdb };
static const unsigned char out_empty_64[] = {
0x36, 0x7a, 0x32, 0x9d, 0xaf, 0xea, 0x87, 0x1c, 0x78, 0x02, 0xec, 0x67, 0xf9,
0x05, 0xae, 0x13, 0xc5, 0x76, 0x95, 0xdc, 0x2c, 0x66, 0x63, 0xc6, 0x10, 0x35,
0xf5, 0x9a, 0x18, 0xf8, 0xe7, 0xdb, 0x11, 0xed, 0xc0, 0xe1, 0x2e, 0x91, 0xea,
0x60, 0xeb, 0x6b, 0x32, 0xdf, 0x06, 0xdd, 0x7f, 0x00, 0x2f, 0xba, 0xfa, 0xbb,
0x6e, 0x13, 0xec, 0x1c, 0xc2, 0x0d, 0x99, 0x55, 0x47, 0x60, 0x0d, 0xb0
};
static const unsigned char out_abc_32[] = { 0x63, 0x82, 0x4b, 0x14, 0x31, 0xa7, 0x37, 0x2e,
0x85, 0xed, 0xc0, 0x22, 0xc9, 0xd7, 0xaf, 0xdd,
0x02, 0x74, 0x72, 0xfc, 0xfa, 0x33, 0xc8, 0x87,
0xd6, 0xf5, 0xaa, 0xf8, 0xdc, 0x5d, 0x4d, 0xb6 };
static const unsigned char out_fox_32[] = { 0xb6, 0xe9, 0x1a, 0x41, 0x2c, 0x26, 0x2c, 0x79,
0x36, 0xb0, 0x69, 0xf6, 0x7b, 0xd2, 0x1c, 0x2f,
0x8e, 0xcc, 0x48, 0xbd, 0xa8, 0xdc, 0x6e, 0xeb,
0xfb, 0xaf, 0x6f, 0xca, 0xa8, 0x21, 0x91, 0xc3 };
static const unsigned char out_fox_64[] = {
0xb6, 0xe9, 0x1a, 0x41, 0x2c, 0x26, 0x2c, 0x79, 0x36, 0xb0, 0x69, 0xf6, 0x7b,
0xd2, 0x1c, 0x2f, 0x8e, 0xcc, 0x48, 0xbd, 0xa8, 0xdc, 0x6e, 0xeb, 0xfb, 0xaf,
0x6f, 0xca, 0xa8, 0x21, 0x91, 0xc3, 0x97, 0x44, 0x62, 0x70, 0x7a, 0xb2, 0xa5,
0xc5, 0xd7, 0x04, 0xb0, 0xe8, 0x74, 0x86, 0x0a, 0x2a, 0x3f, 0xdd, 0xb5, 0x88,
0xf5, 0x07, 0xc9, 0xb4, 0xf0, 0x41, 0x7e, 0x2b, 0x66, 0x31, 0x60, 0x90
};
static const unsigned char out_rate_block_32[] = { 0x91, 0xef, 0xfd, 0x08, 0xdd, 0x4c, 0xcc,
0xb6, 0x89, 0xc6, 0x26, 0xb4, 0x64, 0x93,
0x67, 0xad, 0x5a, 0x2e, 0xbf, 0xab, 0x61,
0x61, 0x17, 0x69, 0xa3, 0x74, 0x93, 0xfa,
0x70, 0x12, 0x28, 0xea };
testvector vectors[] = { { msg_empty, 0, out_empty_32, 32 },
{ msg_empty, 0, out_empty_64, 64 },
{ msg_abc, 3, out_abc_32, 32 },
{ msg_fox, 43, out_fox_32, 32 },
{ msg_fox, 43, out_fox_64, 64 },
{ msg_rate_block, sizeof msg_rate_block, out_rate_block_32, 32 } };
unsigned char out[256];
crypto_xof_turboshake256_state state;
size_t i;
/* Test constants */
assert(crypto_xof_turboshake256_blockbytes() == 136);
assert(crypto_xof_turboshake256_statebytes() == 256);
assert(crypto_xof_turboshake256_domain_standard() == 0x1F);
/* Test one-shot API */
for (i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
crypto_xof_turboshake256(out, vectors[i].out_len, vectors[i].msg, vectors[i].msg_len);
if (memcmp(out, vectors[i].out, vectors[i].out_len) != 0) {
printf("Test vector %zu failed (one-shot)\n", i);
return 1;
}
}
/* Test streaming API */
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_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;
}
}
/* Test multiple squeeze calls */
crypto_xof_turboshake256_init(&state);
crypto_xof_turboshake256_update(&state, msg_abc, 3);
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");
return 1;
}
/* Test custom domain byte produces different output */
crypto_xof_turboshake256_init(&state);
crypto_xof_turboshake256_update(&state, msg_abc, 3);
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_squeeze(&state, out + 32, 32);
if (memcmp(out, out + 32, 32) == 0) {
printf("Custom domain byte test failed (outputs should differ)\n");
return 1;
}
/* 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_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 domain byte with MSB set when padding overlaps */
{
unsigned char msg[crypto_xof_turboshake256_BLOCKBYTES - 1];
unsigned char out_manual[32];
unsigned char out_impl[32];
const unsigned char domain = 0x99;
memset(msg, 0xAA, sizeof msg);
turboshake256_manual_with_domain(out_manual, sizeof out_manual, msg, sizeof msg, domain);
crypto_xof_turboshake256_init_with_domain(&state, domain);
crypto_xof_turboshake256_update(&state, msg, sizeof msg);
crypto_xof_turboshake256_squeeze(&state, out_impl, sizeof out_impl);
if (memcmp(out_manual, out_impl, sizeof out_manual) != 0) {
printf("Domain MSB padding test failed\n");
return 1;
}
}
printf("All TurboSHAKE-256 tests passed\n");
return 0;
}
+1
View File
@@ -0,0 +1 @@
All TurboSHAKE-256 tests passed