diff --git a/src/libsodium/crypto_xof/shake128/ref/shake128_ref.c b/src/libsodium/crypto_xof/shake128/ref/shake128_ref.c index a6d9d1d9..ac113725 100644 --- a/src/libsodium/crypto_xof/shake128/ref/shake128_ref.c +++ b/src/libsodium/crypto_xof/shake128/ref/shake128_ref.c @@ -2,11 +2,10 @@ #include #include "crypto_core_keccak1600.h" +#include "crypto_xof_shake128.h" #include "private/common.h" #include "shake128_ref.h" -#define SHAKE128_DOMAIN_BYTE_STANDARD 0x1F - int shake128_ref_init_with_domain(shake128_state_internal *state, unsigned char domain) { @@ -21,7 +20,7 @@ shake128_ref_init_with_domain(shake128_state_internal *state, unsigned char doma int shake128_ref_init(shake128_state_internal *state) { - return shake128_ref_init_with_domain(state, SHAKE128_DOMAIN_BYTE_STANDARD); + return shake128_ref_init_with_domain(state, crypto_xof_shake128_DOMAIN_STANDARD); } int diff --git a/src/libsodium/crypto_xof/shake256/ref/shake256_ref.c b/src/libsodium/crypto_xof/shake256/ref/shake256_ref.c index a3a8513d..1e1c1f64 100644 --- a/src/libsodium/crypto_xof/shake256/ref/shake256_ref.c +++ b/src/libsodium/crypto_xof/shake256/ref/shake256_ref.c @@ -2,11 +2,10 @@ #include #include "crypto_core_keccak1600.h" +#include "crypto_xof_shake256.h" #include "private/common.h" #include "shake256_ref.h" -#define SHAKE256_DOMAIN_BYTE_STANDARD 0x1F - int shake256_ref_init_with_domain(shake256_state_internal *state, unsigned char domain) { @@ -21,7 +20,7 @@ shake256_ref_init_with_domain(shake256_state_internal *state, unsigned char doma int shake256_ref_init(shake256_state_internal *state) { - return shake256_ref_init_with_domain(state, SHAKE256_DOMAIN_BYTE_STANDARD); + return shake256_ref_init_with_domain(state, crypto_xof_shake256_DOMAIN_STANDARD); } int diff --git a/src/libsodium/crypto_xof/turboshake128/ref/turboshake128_ref.c b/src/libsodium/crypto_xof/turboshake128/ref/turboshake128_ref.c index fa5f4dc5..3725456f 100644 --- a/src/libsodium/crypto_xof/turboshake128/ref/turboshake128_ref.c +++ b/src/libsodium/crypto_xof/turboshake128/ref/turboshake128_ref.c @@ -2,11 +2,10 @@ #include #include "crypto_core_keccak1600.h" +#include "crypto_xof_turboshake128.h" #include "private/common.h" #include "turboshake128_ref.h" -#define TURBOSHAKE128_DOMAIN_BYTE_STANDARD 0x01 - int turboshake128_ref_init_with_domain(turboshake128_state_internal *state, unsigned char domain) { @@ -21,7 +20,7 @@ turboshake128_ref_init_with_domain(turboshake128_state_internal *state, unsigned int turboshake128_ref_init(turboshake128_state_internal *state) { - return turboshake128_ref_init_with_domain(state, TURBOSHAKE128_DOMAIN_BYTE_STANDARD); + return turboshake128_ref_init_with_domain(state, crypto_xof_turboshake128_DOMAIN_STANDARD); } int diff --git a/src/libsodium/crypto_xof/turboshake256/ref/turboshake256_ref.c b/src/libsodium/crypto_xof/turboshake256/ref/turboshake256_ref.c index b47c28e0..a7aa178b 100644 --- a/src/libsodium/crypto_xof/turboshake256/ref/turboshake256_ref.c +++ b/src/libsodium/crypto_xof/turboshake256/ref/turboshake256_ref.c @@ -2,11 +2,10 @@ #include #include "crypto_core_keccak1600.h" +#include "crypto_xof_turboshake256.h" #include "private/common.h" #include "turboshake256_ref.h" -#define TURBOSHAKE256_DOMAIN_BYTE_STANDARD 0x01 - int turboshake256_ref_init_with_domain(turboshake256_state_internal *state, unsigned char domain) { @@ -21,7 +20,7 @@ turboshake256_ref_init_with_domain(turboshake256_state_internal *state, unsigned int turboshake256_ref_init(turboshake256_state_internal *state) { - return turboshake256_ref_init_with_domain(state, TURBOSHAKE256_DOMAIN_BYTE_STANDARD); + return turboshake256_ref_init_with_domain(state, crypto_xof_turboshake256_DOMAIN_STANDARD); } int diff --git a/src/libsodium/include/sodium/crypto_xof_turboshake128.h b/src/libsodium/include/sodium/crypto_xof_turboshake128.h index ccef3fca..f097bb73 100644 --- a/src/libsodium/include/sodium/crypto_xof_turboshake128.h +++ b/src/libsodium/include/sodium/crypto_xof_turboshake128.h @@ -16,7 +16,7 @@ size_t crypto_xof_turboshake128_blockbytes(void); SODIUM_EXPORT size_t crypto_xof_turboshake128_statebytes(void); -#define crypto_xof_turboshake128_DOMAIN_STANDARD 0x01U +#define crypto_xof_turboshake128_DOMAIN_STANDARD 0x1FU SODIUM_EXPORT unsigned char crypto_xof_turboshake128_domain_standard(void); diff --git a/src/libsodium/include/sodium/crypto_xof_turboshake256.h b/src/libsodium/include/sodium/crypto_xof_turboshake256.h index 4f49d9bc..40d6465a 100644 --- a/src/libsodium/include/sodium/crypto_xof_turboshake256.h +++ b/src/libsodium/include/sodium/crypto_xof_turboshake256.h @@ -16,7 +16,7 @@ size_t crypto_xof_turboshake256_blockbytes(void); SODIUM_EXPORT size_t crypto_xof_turboshake256_statebytes(void); -#define crypto_xof_turboshake256_DOMAIN_STANDARD 0x01U +#define crypto_xof_turboshake256_DOMAIN_STANDARD 0x1FU SODIUM_EXPORT unsigned char crypto_xof_turboshake256_domain_standard(void); diff --git a/test/default/xof_turboshake128.c b/test/default/xof_turboshake128.c index ba862ccc..3808e63f 100644 --- a/test/default/xof_turboshake128.c +++ b/test/default/xof_turboshake128.c @@ -12,7 +12,7 @@ typedef struct { int main(void) { - /* Test vectors from TurboSHAKE reference implementation */ + /* 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, @@ -21,35 +21,35 @@ main(void) 0x76, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67 }; - static const unsigned char out_empty_32[] = { 0x86, 0x8c, 0xbd, 0x53, 0xb0, 0x78, 0x20, 0x5a, - 0xbb, 0x85, 0x81, 0x5d, 0x94, 0x1f, 0x7d, 0x03, - 0x76, 0xbf, 0xf5, 0xb8, 0x88, 0x8a, 0x6a, 0x2d, - 0x03, 0x48, 0x3a, 0xfb, 0xaf, 0x83, 0x96, 0x7f }; + 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[] = { - 0x86, 0x8c, 0xbd, 0x53, 0xb0, 0x78, 0x20, 0x5a, 0xbb, 0x85, 0x81, 0x5d, 0x94, - 0x1f, 0x7d, 0x03, 0x76, 0xbf, 0xf5, 0xb8, 0x88, 0x8a, 0x6a, 0x2d, 0x03, 0x48, - 0x3a, 0xfb, 0xaf, 0x83, 0x96, 0x7f, 0x22, 0x6e, 0x2c, 0xad, 0x5e, 0x7b, 0x1e, - 0xc4, 0xca, 0x72, 0x23, 0x6f, 0x07, 0x64, 0x62, 0x19, 0x9f, 0xea, 0x48, 0xc9, - 0x34, 0x38, 0xad, 0x4c, 0x49, 0xc7, 0x67, 0xf9, 0x41, 0x7b, 0xe7, 0xc5 + 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[] = { 0x59, 0xcc, 0xfc, 0x22, 0xa3, 0xb8, 0x47, 0x42, - 0x58, 0x6b, 0x41, 0xf5, 0x1f, 0x8a, 0x94, 0x73, - 0x8d, 0xd0, 0x2b, 0xc7, 0x45, 0x51, 0xeb, 0x0e, - 0xf5, 0x0f, 0xc4, 0x09, 0x4e, 0xb0, 0xfc, 0x7b }; + 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[] = { 0x6f, 0x16, 0x24, 0x47, 0xdd, 0xd3, 0x30, 0xc8, - 0xee, 0x8b, 0x21, 0x89, 0x88, 0xca, 0x1b, 0xef, - 0x35, 0xd9, 0x02, 0xa5, 0xfd, 0x6b, 0xaa, 0xf3, - 0x44, 0x20, 0x48, 0x32, 0x26, 0xa1, 0x72, 0x4a }; + 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[] = { - 0x6f, 0x16, 0x24, 0x47, 0xdd, 0xd3, 0x30, 0xc8, 0xee, 0x8b, 0x21, 0x89, 0x88, - 0xca, 0x1b, 0xef, 0x35, 0xd9, 0x02, 0xa5, 0xfd, 0x6b, 0xaa, 0xf3, 0x44, 0x20, - 0x48, 0x32, 0x26, 0xa1, 0x72, 0x4a, 0xb9, 0x02, 0xc6, 0x85, 0x7e, 0xbd, 0x0b, - 0xa1, 0x76, 0x00, 0xdf, 0x9e, 0xe4, 0x9a, 0x06, 0x18, 0x03, 0x36, 0x92, 0x2d, - 0x9b, 0x61, 0x80, 0x7e, 0x8f, 0xc8, 0x03, 0xec, 0xb0, 0x1a, 0x81, 0xf9 + 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 }; testvector vectors[] = { { msg_empty, 0, out_empty_32, 32 }, @@ -65,7 +65,7 @@ main(void) /* Test constants */ assert(crypto_xof_turboshake128_blockbytes() == 168); assert(crypto_xof_turboshake128_statebytes() == 256); - assert(crypto_xof_turboshake128_domain_standard() == 0x01); + assert(crypto_xof_turboshake128_domain_standard() == 0x1F); /* Test one-shot API */ for (i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) { diff --git a/test/default/xof_turboshake256.c b/test/default/xof_turboshake256.c index bf7bc3f0..17b63928 100644 --- a/test/default/xof_turboshake256.c +++ b/test/default/xof_turboshake256.c @@ -12,7 +12,7 @@ typedef struct { int main(void) { - /* Test vectors from TurboSHAKE reference implementation */ + /* 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, @@ -21,35 +21,35 @@ main(void) 0x76, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67 }; - static const unsigned char out_empty_32[] = { 0xe3, 0xdd, 0x2d, 0xf0, 0x94, 0x3b, 0xde, 0x6d, - 0x82, 0xe3, 0x9e, 0xc3, 0x60, 0x59, 0xf3, 0x5c, - 0xd7, 0x67, 0x20, 0xe2, 0xdf, 0x38, 0xcc, 0x6b, - 0x10, 0xb6, 0x9f, 0xdd, 0xfc, 0xaa, 0x3a, 0x4a }; + 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[] = { - 0xe3, 0xdd, 0x2d, 0xf0, 0x94, 0x3b, 0xde, 0x6d, 0x82, 0xe3, 0x9e, 0xc3, 0x60, - 0x59, 0xf3, 0x5c, 0xd7, 0x67, 0x20, 0xe2, 0xdf, 0x38, 0xcc, 0x6b, 0x10, 0xb6, - 0x9f, 0xdd, 0xfc, 0xaa, 0x3a, 0x4a, 0x72, 0xfb, 0xbb, 0xe4, 0x2c, 0x00, 0xce, - 0xd7, 0xaa, 0x88, 0xe2, 0x6d, 0x46, 0x75, 0xdd, 0x6e, 0x2c, 0x43, 0xc4, 0x41, - 0x3c, 0x4e, 0xa4, 0xd4, 0x4b, 0xb1, 0x70, 0xf0, 0x3a, 0x98, 0x1c, 0xab + 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[] = { 0x88, 0xfb, 0x36, 0x9d, 0x5d, 0x85, 0x6b, 0x22, - 0xcc, 0xe4, 0xd6, 0xa2, 0x40, 0x56, 0x60, 0x0b, - 0xa7, 0x27, 0x44, 0xcd, 0xb3, 0x26, 0x37, 0x49, - 0x07, 0x91, 0xcc, 0xd9, 0x85, 0x3b, 0xc9, 0x14 }; + 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[] = { 0xe9, 0x17, 0xad, 0xfe, 0x65, 0x54, 0x6d, 0x28, - 0xa1, 0x64, 0x57, 0x61, 0x07, 0xe5, 0xd4, 0x77, - 0x4d, 0x46, 0x64, 0x42, 0xc5, 0xe8, 0x86, 0xf1, - 0xb8, 0xc9, 0xee, 0xab, 0x5d, 0x3f, 0xbf, 0xa8 }; + 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[] = { - 0xe9, 0x17, 0xad, 0xfe, 0x65, 0x54, 0x6d, 0x28, 0xa1, 0x64, 0x57, 0x61, 0x07, - 0xe5, 0xd4, 0x77, 0x4d, 0x46, 0x64, 0x42, 0xc5, 0xe8, 0x86, 0xf1, 0xb8, 0xc9, - 0xee, 0xab, 0x5d, 0x3f, 0xbf, 0xa8, 0x96, 0x53, 0xea, 0xd9, 0x8b, 0x2a, 0x52, - 0x05, 0x78, 0x38, 0x9b, 0x24, 0xeb, 0xab, 0x8f, 0xcf, 0xe9, 0x12, 0x3e, 0x71, - 0x42, 0x1a, 0x14, 0xfb, 0xe2, 0x4e, 0x13, 0xe6, 0x27, 0x31, 0x3a, 0xa1 + 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 }; testvector vectors[] = { { msg_empty, 0, out_empty_32, 32 }, @@ -65,7 +65,7 @@ main(void) /* Test constants */ assert(crypto_xof_turboshake256_blockbytes() == 136); assert(crypto_xof_turboshake256_statebytes() == 256); - assert(crypto_xof_turboshake256_domain_standard() == 0x01); + assert(crypto_xof_turboshake256_domain_standard() == 0x1F); /* Test one-shot API */ for (i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {