contrib/config/circe_mlkem_config.h (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
/*
* 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 <string.h> 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 <stddef.h>
#include <stdint.h>
/* 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 */
|