others/mbedtls/tf-psa-crypto/drivers/pqcp/mldsa-native/integration/liboqs/config_aarch64.h
raw symbols SCIP| 1 | /* |
| 2 | * Copyright (c) The mldsa-native project authors |
| 3 | * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT |
| 4 | */ |
| 5 | |
| 6 | /* References |
| 7 | * ========== |
| 8 | * |
| 9 | * - [FIPS140_3_IG] |
| 10 | * Implementation Guidance for FIPS 140-3 and the Cryptographic Module |
| 11 | * Validation Program |
| 12 | * National Institute of Standards and Technology |
| 13 | * https://csrc.nist.gov/projects/cryptographic-module-validation-program/fips-140-3-ig-announcements |
| 14 | */ |
| 15 | |
| 16 | #ifndef MLD_INTEGRATION_LIBOQS_CONFIG_AARCH64_H |
| 17 | #define MLD_INTEGRATION_LIBOQS_CONFIG_AARCH64_H |
| 18 | |
| 19 | /* Enable valgrind-based assertions in mldsa-native through macro |
| 20 | * from libOQS. */ |
| 21 | #if !defined(__ASSEMBLER__) |
| 22 | #include <oqs/common.h> |
| 23 | #if defined(OQS_ENABLE_TEST_CONSTANT_TIME) |
| 24 | #define MLD_CONFIG_CT_TESTING_ENABLED |
| 25 | #endif |
| 26 | #endif /* !__ASSEMBLER__ */ |
| 27 | |
| 28 | /* Use OQS's FIPS202 via glue headers */ |
| 29 | #define MLD_CONFIG_FIPS202_CUSTOM_HEADER \ |
| 30 | "../../integration/liboqs/fips202_glue.h" |
| 31 | #define MLD_CONFIG_FIPS202X4_CUSTOM_HEADER \ |
| 32 | "../../integration/liboqs/fips202x4_glue.h" |
| 33 | |
| 34 | /****************************************************************************** |
| 35 | * Name: MLD_CONFIG_PARAMETER_SET |
| 36 | * |
| 37 | * Description: Specifies the parameter set for ML-DSA |
| 38 | * - MLD_CONFIG_PARAMETER_SET=44 corresponds to ML-DSA-44 |
| 39 | * - MLD_CONFIG_PARAMETER_SET=65 corresponds to ML-DSA-65 |
| 40 | * - MLD_CONFIG_PARAMETER_SET=87 corresponds to ML-DSA-87 |
| 41 | * |
| 42 | * This can also be set using CFLAGS. |
| 43 | * |
| 44 | *****************************************************************************/ |
| 45 | #ifndef MLD_CONFIG_PARAMETER_SET |
| 46 | #define MLD_CONFIG_PARAMETER_SET \ |
| 47 | 44 /* Change this for different security strengths */ |
| 48 | #endif |
| 49 | |
| 50 | /****************************************************************************** |
| 51 | * Name: MLD_CONFIG_NAMESPACE_PREFIX |
| 52 | * |
| 53 | * Description: The prefix to use to namespace global symbols from mldsa/. |
| 54 | * For integration builds, this adds an architecture-specific |
| 55 | * suffix to distinguish different builds. |
| 56 | * |
| 57 | * This can also be set using CFLAGS. |
| 58 | * |
| 59 | *****************************************************************************/ |
| 60 | #if !defined(MLD_CONFIG_NAMESPACE_PREFIX) |
| 61 | #define MLD_CONFIG_NAMESPACE_PREFIX MLD_DEFAULT_NAMESPACE_PREFIX |
| 62 | #endif |
| 63 | |
| 64 | /****************************************************************************** |
| 65 | * Name: MLD_CONFIG_FILE |
| 66 | * |
| 67 | * Description: If defined, this is a header that will be included instead |
| 68 | * of this default configuration file mldsa/config.h. |
| 69 | * |
| 70 | * When you need to build mldsa-native in multiple configurations, |
| 71 | * using varying MLD_CONFIG_FILE can be more convenient |
| 72 | * then configuring everything through CFLAGS. |
| 73 | * |
| 74 | * To use, MLD_CONFIG_FILE _must_ be defined prior |
| 75 | * to the inclusion of any mldsa-native headers. For example, |
| 76 | * it can be set by passing `-DMLD_CONFIG_FILE="..."` |
| 77 | * on the command line. |
| 78 | * |
| 79 | *****************************************************************************/ |
| 80 | /* #define MLD_CONFIG_FILE "config.h" */ |
| 81 | |
| 82 | /****************************************************************************** |
| 83 | * Name: MLD_CONFIG_ARITH_BACKEND_FILE |
| 84 | * |
| 85 | * Description: The arithmetic backend to use. |
| 86 | * |
| 87 | * If MLD_CONFIG_USE_NATIVE_BACKEND_ARITH is unset, this option |
| 88 | * is ignored. |
| 89 | * |
| 90 | * If MLD_CONFIG_USE_NATIVE_BACKEND_ARITH is set, this option must |
| 91 | * either be undefined or the filename of an arithmetic backend. |
| 92 | * If unset, the default backend will be used. |
| 93 | * |
| 94 | * This can be set using CFLAGS. |
| 95 | * |
| 96 | *****************************************************************************/ |
| 97 | #define MLD_CONFIG_USE_NATIVE_BACKEND_ARITH |
| 98 | #define MLD_CONFIG_ARITH_BACKEND_FILE "native/meta.h" |
| 99 | |
| 100 | /****************************************************************************** |
| 101 | * Name: MLD_CONFIG_FIPS202_BACKEND_FILE |
| 102 | * |
| 103 | * Description: The FIPS-202 backend to use. |
| 104 | * |
| 105 | * If MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 is set, this option |
| 106 | * must either be undefined or the filename of a FIPS202 backend. |
| 107 | * If unset, the default backend will be used. |
| 108 | * |
| 109 | * This can be set using CFLAGS. |
| 110 | * |
| 111 | *****************************************************************************/ |
| 112 | /* |
| 113 | * #define MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 |
| 114 | * #define MLD_CONFIG_FIPS202_BACKEND_FILE "fips202/native/auto.h" |
| 115 | */ |
| 116 | |
| 117 | /****************************************************************************** |
| 118 | * Name: MLD_CONFIG_CUSTOM_ZEROIZE |
| 119 | * |
| 120 | * Description: In compliance with FIPS 204 Section 3.6.3, mldsa-native zeroizes |
| 121 | * intermediate stack buffers before returning from function calls. |
| 122 | * |
| 123 | * Set this option and define `mld_zeroize` if you want to |
| 124 | * use a custom method to zeroize intermediate stack buffers. |
| 125 | * The default implementation uses SecureZeroMemory on Windows |
| 126 | * and a memset + compiler barrier otherwise. If neither of those |
| 127 | * is available on the target platform, compilation will fail, |
| 128 | * and you will need to use MLD_CONFIG_CUSTOM_ZEROIZE to provide |
| 129 | * a custom implementation of `mld_zeroize()`. |
| 130 | * |
| 131 | * WARNING: |
| 132 | * The explicit stack zeroization conducted by mldsa-native |
| 133 | * reduces the likelihood of data leaking on the stack, but |
| 134 | * does not eliminate it! The C standard makes no guarantee about |
| 135 | * where a compiler allocates structures and whether/where it makes |
| 136 | * copies of them. Also, in addition to entire structures, there |
| 137 | * may also be potentially exploitable leakage of individual values |
| 138 | * on the stack. |
| 139 | * |
| 140 | * If you need bullet-proof zeroization of the stack, you need to |
| 141 | * consider additional measures instead of what this feature |
| 142 | * provides. In this case, you can set mld_zeroize to a |
| 143 | * no-op. |
| 144 | * |
| 145 | *****************************************************************************/ |
| 146 | /* #define MLD_CONFIG_CUSTOM_ZEROIZE |
| 147 | #if !defined(__ASSEMBLER__) |
| 148 | #include <stdint.h> |
| 149 | #include "sys.h" |
| 150 | static MLD_INLINE void mld_zeroize(void *ptr, size_t len) |
| 151 | { |
| 152 | ... your implementation ... |
| 153 | } |
| 154 | #endif |
| 155 | */ |
| 156 | |
| 157 | /****************************************************************************** |
| 158 | * Name: MLD_CONFIG_CUSTOM_RANDOMBYTES |
| 159 | * |
| 160 | * Description: mldsa-native does not provide a secure randombytes |
| 161 | * implementation. Such an implementation has to provided by the |
| 162 | * consumer. |
| 163 | * |
| 164 | * If this option is not set, mlkem-native expects a function |
| 165 | * int randombytes(uint8_t *out, size_t outlen). |
| 166 | * |
| 167 | * Set this option and define `mlk_randombytes` if you want to |
| 168 | * use a custom method to sample randombytes with a different name |
| 169 | * or signature. |
| 170 | * |
| 171 | *****************************************************************************/ |
| 172 | #define MLD_CONFIG_CUSTOM_RANDOMBYTES |
| 173 | #if !defined(__ASSEMBLER__) |
| 174 | #include <oqs/rand.h> |
| 175 | #include <stdint.h> |
| 176 | #include "../../mldsa/src/sys.h" |
| 177 | static MLD_INLINE int mld_randombytes(uint8_t *ptr, size_t len) |
| 178 | { |
| 179 | OQS_randombytes(ptr, len); |
| 180 | return 0; |
| 181 | } |
| 182 | #endif /* !__ASSEMBLER__ */ |
| 183 | |
| 184 | /****************************************************************************** |
| 185 | * Name: MLD_CONFIG_KEYGEN_PCT |
| 186 | * |
| 187 | * Description: Compliance with @[FIPS140_3_IG, p.87] requires a |
| 188 | * Pairwise Consistency Test (PCT) to be carried out on a freshly |
| 189 | * generated keypair before it can be exported. |
| 190 | * |
| 191 | * Set this option if such a check should be implemented. |
| 192 | * In this case, crypto_sign_keypair_internal and |
| 193 | * crypto_sign_keypair will return a non-zero error code if the |
| 194 | * PCT failed. |
| 195 | * |
| 196 | * NOTE: This feature will drastically lower the performance of |
| 197 | * key generation. |
| 198 | * |
| 199 | *****************************************************************************/ |
| 200 | /* #define MLD_CONFIG_KEYGEN_PCT */ |
| 201 | |
| 202 | /****************************************************************************** |
| 203 | * Name: MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST |
| 204 | * |
| 205 | * Description: If this option is set, the user must provide a runtime |
| 206 | * function `static inline int mld_break_pct() { ... }` to |
| 207 | * indicate whether the PCT should be made fail. |
| 208 | * |
| 209 | * This option only has an effect if MLD_CONFIG_KEYGEN_PCT is set. |
| 210 | * |
| 211 | *****************************************************************************/ |
| 212 | /* #define MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST |
| 213 | #if !defined(__ASSEMBLER__) |
| 214 | #include "sys.h" |
| 215 | static MLD_INLINE int mld_break_pct(void) |
| 216 | { |
| 217 | ... return 0/1 depending on whether PCT should be broken ... |
| 218 | } |
| 219 | #endif |
| 220 | */ |
| 221 | |
| 222 | /****************************************************************************** |
| 223 | * Name: MLD_CONFIG_NO_ASM |
| 224 | * |
| 225 | * Description: If this option is set, mldsa-native will be built without |
| 226 | * use of native code or inline assembly. |
| 227 | * |
| 228 | * By default, inline assembly is used to implement value barriers. |
| 229 | * Without inline assembly, mldsa-native will use a global volatile |
| 230 | * 'opt blocker' instead; see ct.h. |
| 231 | * |
| 232 | * Inline assembly is also used to implement a secure zeroization |
| 233 | * function on non-Windows platforms. If this option is set and |
| 234 | * the target platform is not Windows, you MUST set |
| 235 | * MLD_CONFIG_CUSTOM_ZEROIZE and provide a custom zeroization |
| 236 | * function. |
| 237 | * |
| 238 | * If this option is set, MLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 and |
| 239 | * and MLD_CONFIG_USE_NATIVE_BACKEND_ARITH will be ignored, and no |
| 240 | * native backends will be used. |
| 241 | * |
| 242 | *****************************************************************************/ |
| 243 | /* #define MLD_CONFIG_NO_ASM */ |
| 244 | |
| 245 | /****************************************************************************** |
| 246 | * Name: MLD_CONFIG_NO_ASM_VALUE_BARRIER |
| 247 | * |
| 248 | * Description: If this option is set, mldsa-native will be built without |
| 249 | * use of native code or inline assembly for value barriers. |
| 250 | * |
| 251 | * By default, inline assembly (if available) is used to implement |
| 252 | * value barriers. |
| 253 | * Without inline assembly, mldsa-native will use a global volatile |
| 254 | * 'opt blocker' instead; see ct.h. |
| 255 | * |
| 256 | *****************************************************************************/ |
| 257 | /* #define MLD_CONFIG_NO_ASM_VALUE_BARRIER */ |
| 258 | |
| 259 | /****************************************************************************** |
| 260 | * Name: MLD_CONFIG_EXTERNAL_API_QUALIFIER |
| 261 | * |
| 262 | * Description: If set, this option provides an additional function |
| 263 | * qualifier to be added to declarations of mldsa-native's |
| 264 | * public API. |
| 265 | * |
| 266 | * The primary use case for this option are single-CU builds |
| 267 | * where the public API exposed by mldsa-native is wrapped by |
| 268 | * another API in the consuming application. In this case, |
| 269 | * even mldsa-native's public API can be marked `static`. |
| 270 | * |
| 271 | *****************************************************************************/ |
| 272 | #if !defined(__ASSEMBLER__) |
| 273 | #include <oqs/common.h> |
| 274 | #define MLD_CONFIG_EXTERNAL_API_QUALIFIER OQS_API |
| 275 | #endif |
| 276 | |
| 277 | /****************************************************************************** |
| 278 | * Name: MLD_CONFIG_SERIAL_FIPS202_ONLY |
| 279 | * |
| 280 | * Description: Set this to use a FIPS202 implementation with global state |
| 281 | * that supports only one active Keccak computation at a time |
| 282 | * (e.g. some hardware accelerators). |
| 283 | * |
| 284 | * If this option is set, ML-DSA will use FIPS202 operations |
| 285 | * serially, ensuring that only one SHAKE context is active |
| 286 | * at any given time. |
| 287 | * |
| 288 | * This allows offloading Keccak computations to a hardware |
| 289 | * accelerator that holds only a single Keccak state locally, |
| 290 | * rather than requiring support for multiple concurrent |
| 291 | * Keccak states. |
| 292 | * |
| 293 | * NOTE: Depending on the target CPU, this may reduce |
| 294 | * performance when using software FIPS202 implementations. |
| 295 | * Only enable this when you have to. |
| 296 | * |
| 297 | *****************************************************************************/ |
| 298 | /* #define MLD_CONFIG_SERIAL_FIPS202_ONLY */ |
| 299 | |
| 300 | /************************* Config internals ********************************/ |
| 301 | |
| 302 | /* Default namespace |
| 303 | * |
| 304 | * Don't change this. If you need a different namespace, re-define |
| 305 | * MLD_CONFIG_NAMESPACE_PREFIX above instead, and remove the following. |
| 306 | * |
| 307 | * The default MLDSA namespace for aarch64 integration is |
| 308 | * |
| 309 | * PQCP_MLDSA_NATIVE_MLDSA<LEVEL>_AARCH64_ |
| 310 | * |
| 311 | * e.g., PQCP_MLDSA_NATIVE_MLDSA44_AARCH64_ |
| 312 | */ |
| 313 | |
| 314 | #if MLD_CONFIG_PARAMETER_SET == 44 |
| 315 | #define MLD_DEFAULT_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA44_AARCH64 |
| 316 | #elif MLD_CONFIG_PARAMETER_SET == 65 |
| 317 | #define MLD_DEFAULT_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA65_AARCH64 |
| 318 | #elif MLD_CONFIG_PARAMETER_SET == 87 |
| 319 | #define MLD_DEFAULT_NAMESPACE_PREFIX PQCP_MLDSA_NATIVE_MLDSA87_AARCH64 |
| 320 | #endif |
| 321 | |
| 322 | #endif /* !MLD_INTEGRATION_LIBOQS_CONFIG_AARCH64_H */ |