From ec61923efc5f3d0c15af07a1e18faa054153cab6 Mon Sep 17 00:00:00 2001 From: Franziskus Kiefer Date: Mon, 18 Dec 2023 14:06:02 +0100 Subject: [PATCH] some fixups --- CMakeLists.txt | 4 +-- libcrux/include/eurydice_glue.h | 36 +------------------ libcrux/include/libcrux_hacl_glue.h | 2 ++ libcrux/src/libcrux_hacl_glue.c | 55 ++++++++++++++--------------- tests/kyber.cc | 3 ++ 5 files changed, 35 insertions(+), 65 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 752dc8a3..caa2537d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -516,10 +516,10 @@ if(ENABLE_TESTS) add_dependencies(${TEST_NAME} hacl hacl_cpu_features) target_link_libraries(${TEST_NAME} PRIVATE gtest_main - hacl_static hacl_cpu_features nlohmann_json::nlohmann_json libcrux_static + hacl_static ) if(EXISTS ${PROJECT_SOURCE_DIR}/tests/${TEST_NAME}) @@ -622,10 +622,10 @@ if(ENABLE_BENCHMARKS) add_dependencies(${BENCH_NAME} hacl hacl_cpu_features) target_link_libraries(${BENCH_NAME} PRIVATE - hacl_static hacl_cpu_features benchmark::benchmark libcrux_static + hacl_static ) endforeach() endif() diff --git a/libcrux/include/eurydice_glue.h b/libcrux/include/eurydice_glue.h index 640be80f..83acbb7b 100644 --- a/libcrux/include/eurydice_glue.h +++ b/libcrux/include/eurydice_glue.h @@ -1,40 +1,6 @@ #pragma once -#include -#include -#include -#include -#include - -// SYSTEM DEFINITIONS (taken from krml...) - -#define KRML_HOST_EXIT exit -#define KRML_HOST_EPRINTF(...) fprintf(stderr, __VA_ARGS__) - -#define LowStar_Ignore_ignore(e, t) ((void)e) - -#if defined(__linux__) || defined(__CYGWIN__) || defined (__USE_SYSTEM_ENDIAN_H__) || defined(__GLIBC__) -# include - -/* ... for OSX */ -#elif defined(__APPLE__) -# include -# define htole64(x) OSSwapHostToLittleInt64(x) -# define le64toh(x) OSSwapLittleToHostInt64(x) -# define htobe64(x) OSSwapHostToBigInt64(x) -# define be64toh(x) OSSwapBigToHostInt64(x) - -# define htole16(x) OSSwapHostToLittleInt16(x) -# define le16toh(x) OSSwapLittleToHostInt16(x) -# define htobe16(x) OSSwapHostToBigInt16(x) -# define be16toh(x) OSSwapBigToHostInt16(x) - -# define htole32(x) OSSwapHostToLittleInt32(x) -# define le32toh(x) OSSwapLittleToHostInt32(x) -# define htobe32(x) OSSwapHostToBigInt32(x) -# define be32toh(x) OSSwapBigToHostInt32(x) -#endif - +#include "krmllib.h" // SLICES, ARRAYS, ETC. diff --git a/libcrux/include/libcrux_hacl_glue.h b/libcrux/include/libcrux_hacl_glue.h index 466e3602..37cad456 100644 --- a/libcrux/include/libcrux_hacl_glue.h +++ b/libcrux/include/libcrux_hacl_glue.h @@ -1,5 +1,7 @@ #pragma once +#include "eurydice_glue.h" + typedef struct __uint8_t_840size_t__uint8_t_840size_t__uint8_t_840size_t__uint8_t_840size_t__s { diff --git a/libcrux/src/libcrux_hacl_glue.c b/libcrux/src/libcrux_hacl_glue.c index 471b3aff..765b2061 100644 --- a/libcrux/src/libcrux_hacl_glue.c +++ b/libcrux/src/libcrux_hacl_glue.c @@ -1,6 +1,5 @@ - #include "libcrux_hacl_glue.h" -#include "Hacl_Hash_SHA3_Scalar.h" +#include "Hacl_Hash_SHA3.h" #include "libcrux_kyber.h" #ifdef HACL_CAN_COMPILE_VEC256 @@ -17,13 +16,13 @@ libcrux_platform_simd256_support(void) inline void libcrux_digest_shake256(size_t len, Eurydice_slice input, uint8_t* out) { - Hacl_Hash_SHA3_Scalar_shake256(input.len, input.ptr, (uint32_t)len, out); + Hacl_Hash_SHA3_shake256_hacl(input.len, input.ptr, (uint32_t)len, out); } inline void libcrux_digest_shake128(size_t len, Eurydice_slice input, uint8_t* out) { - Hacl_Hash_SHA3_Scalar_shake128(input.len, input.ptr, (uint32_t)len, out); + Hacl_Hash_SHA3_shake128_hacl(input.len, input.ptr, (uint32_t)len, out); } inline __uint8_t_840size_t__uint8_t_840size_t__uint8_t_840size_t__uint8_t_840size_t_ @@ -40,42 +39,42 @@ libcrux_digest_shake128x4(size_t len, }; #ifdef HACL_CAN_COMPILE_VEC256 if (libcrux_platform_simd256_support() == true) { - Hacl_SHA3_Vec256_shake128_vec256(input0.len, - input0.ptr, - input1.ptr, - input2.ptr, - input3.ptr, - (uint32_t)len, - out.fst, - out.snd, - out.thd, - out.f3); + Hacl_Hash_SHA3_Simd256_shake128(input0.len, + input0.ptr, + input1.ptr, + input2.ptr, + input3.ptr, + (uint32_t)len, + out.fst, + out.snd, + out.thd, + out.f3); } else { - Hacl_SHA3_shake128_hacl(input0.len, input0.ptr, (uint32_t)len, out.fst); - Hacl_SHA3_shake128_hacl(input1.len, input1.ptr, (uint32_t)len, out.snd); - Hacl_SHA3_shake128_hacl(input2.len, input2.ptr, (uint32_t)len, out.thd); - Hacl_SHA3_shake128_hacl(input3.len, input3.ptr, (uint32_t)len, out.f3); + Hacl_Hash_SHA3_shake128_hacl( + input0.len, input0.ptr, (uint32_t)len, out.fst); + Hacl_Hash_SHA3_shake128_hacl( + input1.len, input1.ptr, (uint32_t)len, out.snd); + Hacl_Hash_SHA3_shake128_hacl( + input2.len, input2.ptr, (uint32_t)len, out.thd); + Hacl_Hash_SHA3_shake128_hacl(input3.len, input3.ptr, (uint32_t)len, out.f3); } #else - Hacl_Hash_SHA3_Scalar_shake128( - input0.len, input0.ptr, (uint32_t)len, out.fst); - Hacl_Hash_SHA3_Scalar_shake128( - input1.len, input1.ptr, (uint32_t)len, out.snd); - Hacl_Hash_SHA3_Scalar_shake128( - input2.len, input2.ptr, (uint32_t)len, out.thd); - Hacl_Hash_SHA3_Scalar_shake128(input3.len, input3.ptr, (uint32_t)len, out.f3); - return out; + Hacl_Hash_SHA3_shake128_hacl(input0.len, input0.ptr, (uint32_t)len, out.fst); + Hacl_Hash_SHA3_shake128_hacl(input1.len, input1.ptr, (uint32_t)len, out.snd); + Hacl_Hash_SHA3_shake128_hacl(input2.len, input2.ptr, (uint32_t)len, out.thd); + Hacl_Hash_SHA3_shake128_hacl(input3.len, input3.ptr, (uint32_t)len, out.f3); #endif + return out; } inline void libcrux_digest_sha3_512(Eurydice_slice x0, uint8_t x1[64U]) { - Hacl_Hash_SHA3_Scalar_sha3_512((uint32_t)x0.len, x0.ptr, x1); + Hacl_Hash_SHA3_sha3_512(x1, x0.ptr, (uint32_t)x0.len); } inline void libcrux_digest_sha3_256(Eurydice_slice x0, uint8_t x1[32U]) { - Hacl_Hash_SHA3_Scalar_sha3_256((uint32_t)x0.len, x0.ptr, x1); + Hacl_Hash_SHA3_sha3_256(x1, x0.ptr, (uint32_t)x0.len); } diff --git a/tests/kyber.cc b/tests/kyber.cc index d355523d..26714288 100644 --- a/tests/kyber.cc +++ b/tests/kyber.cc @@ -103,6 +103,7 @@ uint8_t* compute_implicit_rejection_shared_secret(uint8_t* ciphertext, size_t ci Hacl_Hash_SHA3_shake256_hacl(32 + ciphertext_size, hashInput, 32, sharedSecret); + delete [] hashInput; return sharedSecret; } @@ -153,6 +154,7 @@ TEST(Kyber768Test, ModifiedCiphertextTest) uint8_t* implicitRejectionSharedSecret = compute_implicit_rejection_shared_secret(ciphertext, KYBER768_CIPHERTEXTBYTES, secretKey, KYBER768_SECRETKEYBYTES); EXPECT_EQ(0, memcmp(implicitRejectionSharedSecret, sharedSecret2, KYBER768_SHAREDSECRETBYTES)); + delete [] implicitRejectionSharedSecret; } TEST(Kyber768Test, ModifiedSecretKeyTest) @@ -182,6 +184,7 @@ TEST(Kyber768Test, ModifiedSecretKeyTest) uint8_t* implicitRejectionSharedSecret = compute_implicit_rejection_shared_secret(ciphertext, KYBER768_CIPHERTEXTBYTES, secretKey, KYBER768_SECRETKEYBYTES); EXPECT_EQ(0, memcmp(implicitRejectionSharedSecret, sharedSecret2, KYBER768_SHAREDSECRETBYTES)); + delete [] implicitRejectionSharedSecret; } TEST(Kyber768Test, NISTKnownAnswerTest)