Skip to content

Commit

Permalink
some fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
franziskuskiefer committed Dec 18, 2023
1 parent 7a7bfbb commit ec61923
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 65 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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()
Expand Down
36 changes: 1 addition & 35 deletions libcrux/include/eurydice_glue.h
Original file line number Diff line number Diff line change
@@ -1,40 +1,6 @@
#pragma once

#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>

// 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 <endian.h>

/* ... for OSX */
#elif defined(__APPLE__)
# include <libkern/OSByteOrder.h>
# 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.

Expand Down
2 changes: 2 additions & 0 deletions libcrux/include/libcrux_hacl_glue.h
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
55 changes: 27 additions & 28 deletions libcrux/src/libcrux_hacl_glue.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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_
Expand All @@ -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);
}
3 changes: 3 additions & 0 deletions tests/kyber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ec61923

Please sign in to comment.