all repos — circe-vpn @ 4d3404231847d860083059474562e28a12afcf61

Circe VPN

contrib/config/circe_mldsa_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
/*
 * Circe configuration for mldsa-native.
 *
 * Selected instead of contrib/mldsa-native/mldsa/mldsa_native_config.h by
 * building with -DMLD_CONFIG_FILE="circe_mldsa_config.h" (see
 * contrib/meson.build).
 *
 * Circe only needs ML-DSA-44 with the randomized (randombytes) API.
 */

#ifndef MLD_CONFIG_H
#define MLD_CONFIG_H

/* ML-DSA-44. */
#define MLD_CONFIG_PARAMETER_SET 44

/* Namespace prefix for exported symbols (matches the upstream default for 44).
 */
#define MLD_CONFIG_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA44

/*
 * Randomized API.
 *
 * We deliberately leave MLD_CONFIG_NO_RANDOMIZED_API and
 * MLD_CONFIG_CUSTOM_RANDOMBYTES *unset*: mldsa-native keeps the randomized
 * signing API 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.
 *
 * MLD_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 mldsa_native.h.
 */
#if defined(MLD_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 mldsa-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 MLD_CONFIG_USE_NATIVE_BACKEND_ARITH
#define MLD_CONFIG_ARITH_BACKEND_FILE "native/meta.h"
#define MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202
#define MLD_CONFIG_FIPS202_BACKEND_FILE "fips202/native/auto.h"
#endif

/*
 * Freestanding build: no libc is linked, so route mldsa-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 MLD_CONFIG_CUSTOM_MEMCPY
#define MLD_CONFIG_CUSTOM_MEMSET
#define MLD_CONFIG_CUSTOM_ZEROIZE
#if !defined(__ASSEMBLER__)
#include "src/sys.h" /* for MLD_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 MLD_INLINE void *
mld_memcpy (void *dest, const void *src, size_t n)
{
  return circe_memcpy (dest, src, n);
}
static MLD_INLINE void *
mld_memset (void *s, int c, size_t n)
{
  return circe_memset (s, c, n);
}
static MLD_INLINE void
mld_zeroize (void *ptr, size_t len)
{
  circe_memset (ptr, 0, len);
}
#endif /* !__ASSEMBLER__ */

#endif /* MLD_BUILD_INTERNAL */

#endif /* MLD_CONFIG_H */