/* * Circe configuration for mlkem-native. * * Selected instead of contrib/mlkem-native/mlkem/mlkem_native_config.h by * building with -DMLK_CONFIG_FILE="circe_mlkem_config.h" (see * contrib/meson.build). * * Circe only needs ML-KEM-768 with the randomized (randombytes) API. */ #ifndef MLK_CONFIG_H #define MLK_CONFIG_H /* ML-KEM-768. */ #define MLK_CONFIG_PARAMETER_SET 768 /* Namespace prefix for exported symbols (matches the upstream default for * 768). */ #define MLK_CONFIG_NAMESPACE_PREFIX PQCP_MLKEM_NATIVE_MLKEM768 /* * Randomized API. * * We deliberately leave MLK_CONFIG_NO_RANDOMIZED_API and * MLK_CONFIG_CUSTOM_RANDOMBYTES *unset*: mlkem-native keeps * crypto_kem_keypair() and crypto_kem_enc() and expects the consumer to * provide * * int randombytes(uint8_t *out, size_t outlen); // 0 on success * * No deterministic/derand-only build. */ /* * Implementation-only options. * * MLK_BUILD_INTERNAL is defined by the library's src/common.h before this file * is included, so these only affect the library build, not consumers that * merely include mlkem_native.h. */ #if defined(MLK_BUILD_INTERNAL) /* * Use the optimized native backends on AArch64 and x86-64, and the portable C * backends everywhere else. The architecture is detected from the compiler's * predefined macros, matching mlkem-native's own src/sys.h; the actual backend * (NEON / AVX2, and the SHA3/Keccak accelerator) is then selected * automatically from the -march flags passed by contrib/meson.build. */ #if defined(__aarch64__) || defined(__x86_64__) #define MLK_CONFIG_USE_NATIVE_BACKEND_ARITH #define MLK_CONFIG_ARITH_BACKEND_FILE "native/meta.h" #define MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202 #define MLK_CONFIG_FIPS202_BACKEND_FILE "fips202/native/auto.h" #endif /* * Freestanding build: no libc is linked, so route mlkem-native's memcpy / * memset / stack-zeroization through Circe's portable implementations in * common/memory.c. This drops the library's includes and leaves no * unresolved libc symbols. */ #define MLK_CONFIG_CUSTOM_MEMCPY #define MLK_CONFIG_CUSTOM_MEMSET #define MLK_CONFIG_CUSTOM_ZEROIZE #if !defined(__ASSEMBLER__) #include "src/sys.h" /* for MLK_INLINE */ #include #include /* Defined in common/memory.c */ void *circe_memcpy (void *restrict dest, const void *restrict src, size_t n); void *circe_memset (void *dest, int value, size_t count); static MLK_INLINE void * mlk_memcpy (void *dest, const void *src, size_t n) { return circe_memcpy (dest, src, n); } static MLK_INLINE void * mlk_memset (void *s, int c, size_t n) { return circe_memset (s, c, n); } static MLK_INLINE void mlk_zeroize (void *ptr, size_t len) { circe_memset (ptr, 0, len); } #endif /* !__ASSEMBLER__ */ #endif /* MLK_BUILD_INTERNAL */ #endif /* MLK_CONFIG_H */