|
129 | 129 | #endif |
130 | 130 |
|
131 | 131 | #if defined(MLD_CONFIG_NO_RANDOMIZED_API) && defined(MLD_CONFIG_KEYGEN_PCT) |
132 | | -#error Bad configuration: MLD_CONFIG_NO_RANDOMIZED_API is incompatible with MLD_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_sign_signature() |
| 132 | +#error Bad configuration: MLD_CONFIG_NO_RANDOMIZED_API is incompatible with MLD_CONFIG_KEYGEN_PCT as the current PCT implementation requires signature() |
133 | 133 | #endif |
134 | 134 |
|
135 | 135 | #if defined(MLD_CONFIG_NO_SIGN_API) && defined(MLD_CONFIG_KEYGEN_PCT) |
136 | | -#error Bad configuration: MLD_CONFIG_NO_SIGN_API is incompatible with MLD_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_sign_signature() |
| 136 | +#error Bad configuration: MLD_CONFIG_NO_SIGN_API is incompatible with MLD_CONFIG_KEYGEN_PCT as the current PCT implementation requires signature() |
137 | 137 | #endif |
138 | 138 |
|
139 | 139 | #if defined(MLD_CONFIG_NO_VERIFY_API) && defined(MLD_CONFIG_KEYGEN_PCT) |
140 | | -#error Bad configuration: MLD_CONFIG_NO_VERIFY_API is incompatible with MLD_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_sign_verify() |
| 140 | +#error Bad configuration: MLD_CONFIG_NO_VERIFY_API is incompatible with MLD_CONFIG_KEYGEN_PCT as the current PCT implementation requires verify() |
141 | 141 | #endif |
142 | 142 |
|
143 | 143 | #if defined(MLD_CONFIG_USE_NATIVE_BACKEND_ARITH) |
|
202 | 202 | #error Bad configuration: MLD_CONFIG_CUSTOM_ALLOC_FREE must be set together with MLD_CUSTOM_ALLOC and MLD_CUSTOM_FREE |
203 | 203 | #endif |
204 | 204 |
|
205 | | -/* |
206 | | - * If the integration wants to provide a context parameter for use in |
207 | | - * platform-specific hooks, then it should define this parameter. |
208 | | - * |
209 | | - * The MLD_CONTEXT_PARAMETERS_n macros are intended to be used with macros |
210 | | - * defining the function names and expand to either pass or discard the context |
211 | | - * argument as required by the current build. If there is no context parameter |
212 | | - * requested then these are removed from the prototypes and from all calls. |
213 | | - */ |
214 | | -#ifdef MLD_CONFIG_CONTEXT_PARAMETER |
215 | | -#define MLD_CONTEXT_PARAMETERS_0(context) (context) |
216 | | -#define MLD_CONTEXT_PARAMETERS_1(arg0, context) (arg0, context) |
217 | | -#define MLD_CONTEXT_PARAMETERS_2(arg0, arg1, context) (arg0, arg1, context) |
218 | | -#define MLD_CONTEXT_PARAMETERS_3(arg0, arg1, arg2, context) \ |
219 | | - (arg0, arg1, arg2, context) |
220 | | -#define MLD_CONTEXT_PARAMETERS_4(arg0, arg1, arg2, arg3, context) \ |
221 | | - (arg0, arg1, arg2, arg3, context) |
222 | | -#define MLD_CONTEXT_PARAMETERS_5(arg0, arg1, arg2, arg3, arg4, context) \ |
223 | | - (arg0, arg1, arg2, arg3, arg4, context) |
224 | | -#define MLD_CONTEXT_PARAMETERS_6(arg0, arg1, arg2, arg3, arg4, arg5, context) \ |
225 | | - (arg0, arg1, arg2, arg3, arg4, arg5, context) |
226 | | -#define MLD_CONTEXT_PARAMETERS_7(arg0, arg1, arg2, arg3, arg4, arg5, arg6, \ |
227 | | - context) \ |
228 | | - (arg0, arg1, arg2, arg3, arg4, arg5, arg6, context) |
229 | | -#define MLD_CONTEXT_PARAMETERS_8(arg0, arg1, arg2, arg3, arg4, arg5, arg6, \ |
230 | | - arg7, context) \ |
231 | | - (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, context) |
232 | | -#define MLD_CONTEXT_PARAMETERS_9(arg0, arg1, arg2, arg3, arg4, arg5, arg6, \ |
233 | | - arg7, arg8, context) \ |
234 | | - (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, context) |
235 | | -#else /* MLD_CONFIG_CONTEXT_PARAMETER */ |
236 | | -#define MLD_CONTEXT_PARAMETERS_0(context) () |
237 | | -#define MLD_CONTEXT_PARAMETERS_1(arg0, context) (arg0) |
238 | | -#define MLD_CONTEXT_PARAMETERS_2(arg0, arg1, context) (arg0, arg1) |
239 | | -#define MLD_CONTEXT_PARAMETERS_3(arg0, arg1, arg2, context) (arg0, arg1, arg2) |
240 | | -#define MLD_CONTEXT_PARAMETERS_4(arg0, arg1, arg2, arg3, context) \ |
241 | | - (arg0, arg1, arg2, arg3) |
242 | | -#define MLD_CONTEXT_PARAMETERS_5(arg0, arg1, arg2, arg3, arg4, context) \ |
243 | | - (arg0, arg1, arg2, arg3, arg4) |
244 | | -#define MLD_CONTEXT_PARAMETERS_6(arg0, arg1, arg2, arg3, arg4, arg5, context) \ |
245 | | - (arg0, arg1, arg2, arg3, arg4, arg5) |
246 | | -#define MLD_CONTEXT_PARAMETERS_7(arg0, arg1, arg2, arg3, arg4, arg5, arg6, \ |
247 | | - context) \ |
248 | | - (arg0, arg1, arg2, arg3, arg4, arg5, arg6) |
249 | | -#define MLD_CONTEXT_PARAMETERS_8(arg0, arg1, arg2, arg3, arg4, arg5, arg6, \ |
250 | | - arg7, context) \ |
251 | | - (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) |
252 | | -#define MLD_CONTEXT_PARAMETERS_9(arg0, arg1, arg2, arg3, arg4, arg5, arg6, \ |
253 | | - arg7, arg8, context) \ |
254 | | - (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) |
255 | | -#endif /* !MLD_CONFIG_CONTEXT_PARAMETER */ |
256 | | - |
257 | | -#if defined(MLD_CONFIG_CONTEXT_PARAMETER_TYPE) != \ |
258 | | - defined(MLD_CONFIG_CONTEXT_PARAMETER) |
259 | | -#error MLD_CONFIG_CONTEXT_PARAMETER_TYPE must be defined if and only if MLD_CONFIG_CONTEXT_PARAMETER is defined |
260 | | -#endif |
| 205 | +/* Context-parameter machinery (MLD_CONTEXT_PARAMETERS_n and related config |
| 206 | + * checks). Kept in a separate, level-generic header for readability; included |
| 207 | + * here so it is available to the allocation macros below and to all consumers |
| 208 | + * of common.h. */ |
| 209 | +#include "context.h" |
261 | 210 |
|
262 | 211 | #if !defined(MLD_CONFIG_CUSTOM_ALLOC_FREE) |
263 | 212 | /* Default: stack allocation */ |
264 | 213 |
|
| 214 | +/* This is a declaration macro, not an expression macro: T is a type and v is |
| 215 | + * a declarator, neither of which can be wrapped in parentheses. The |
| 216 | + * bugprone-macro-parentheses diagnostic is therefore a false positive here. */ |
265 | 217 | #define MLD_ALLOC(v, T, N, context) \ |
266 | 218 | MLD_ALIGN T mld_alloc_##v[N]; \ |
267 | | - T *v = mld_alloc_##v |
| 219 | + T *v = mld_alloc_##v /* NOLINT(bugprone-macro-parentheses) */ |
268 | 220 |
|
269 | | -/* TODO: This leads to a circular dependency between common and ct.h |
270 | | - * It just works out before we're at the end of the file, but it's still |
271 | | - * prone to issues in the future. */ |
272 | | -#include "ct.h" |
| 221 | +/* The MLD_FREE macro body references mld_zeroize(), which is declared in |
| 222 | + * ct.h. We deliberately do NOT include ct.h here: doing so would create a |
| 223 | + * circular dependency (ct.h includes common.h), and common.h itself never |
| 224 | + * calls mld_zeroize() -- only the macro expansion does. Each translation |
| 225 | + * unit that uses MLD_FREE therefore includes ct.h directly. */ |
273 | 226 | #define MLD_FREE(v, T, N, context) \ |
274 | 227 | do \ |
275 | 228 | { \ |
| 229 | + MLD_CONTEXT_UNUSED(context); \ |
276 | 230 | mld_zeroize(mld_alloc_##v, sizeof(mld_alloc_##v)); \ |
277 | 231 | (v) = NULL; \ |
278 | 232 | } while (0) |
|
305 | 259 | /****************************** Error codes ***********************************/ |
306 | 260 |
|
307 | 261 | /* Generic failure condition */ |
308 | | -#define MLD_ERR_FAIL -1 |
| 262 | +#define MLD_ERR_FAIL (-1) |
309 | 263 | /* An allocation failed. This can only happen if MLD_CONFIG_CUSTOM_ALLOC_FREE |
310 | 264 | * is defined and the provided MLD_CUSTOM_ALLOC can fail. */ |
311 | | -#define MLD_ERR_OUT_OF_MEMORY -2 |
| 265 | +#define MLD_ERR_OUT_OF_MEMORY (-2) |
312 | 266 | /* An rng failure occured. Might be due to insufficient entropy or |
313 | 267 | * system misconfiguration. */ |
314 | | -#define MLD_ERR_RNG_FAIL -3 |
| 268 | +#define MLD_ERR_RNG_FAIL (-3) |
315 | 269 | /* The signing rejection-sampling loop exceeded |
316 | 270 | * MLD_CONFIG_MAX_SIGNING_ATTEMPTS iterations without producing a valid |
317 | 271 | * signature. With a FIPS 204 Appendix C compliant bound (>= 814) this |
318 | 272 | * has probability < 2^-256. */ |
319 | | -#define MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED -4 |
| 273 | +#define MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED (-4) |
| 274 | +/* Signing was paused before completing, at the request of a caller-provided |
| 275 | + * MLD_CONFIG_SIGN_HOOK_ATTEMPT hook (see mldsa_native_config.h). The caller |
| 276 | + * resumes by re-invoking signing with the same inputs; the attempt hook, |
| 277 | + * together with MLD_CONFIG_SIGN_HOOK_RESUME, decides where to continue. */ |
| 278 | +#define MLD_ERR_SIGNING_PAUSED (-5) |
320 | 279 |
|
321 | 280 | /* Disjunction over the full set of MLD_ERR_XXX failure codes. |
322 | 281 | * |
323 | 282 | * Intended for use in top-level `ensures` clauses that admit every |
324 | 283 | * possible error. Narrower contracts should enumerate only the |
325 | 284 | * specific errors they can actually return. */ |
326 | | -#define MLD_ANY_ERROR(err) \ |
327 | | - ((err) == MLD_ERR_FAIL || (err) == MLD_ERR_OUT_OF_MEMORY || \ |
328 | | - (err) == MLD_ERR_RNG_FAIL || (err) == MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED) |
| 285 | +#define MLD_ANY_ERROR(err) \ |
| 286 | + ((err) == MLD_ERR_FAIL || (err) == MLD_ERR_OUT_OF_MEMORY || \ |
| 287 | + (err) == MLD_ERR_RNG_FAIL || (err) == MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED || \ |
| 288 | + (err) == MLD_ERR_SIGNING_PAUSED) |
329 | 289 |
|
330 | 290 |
|
331 | 291 | #endif /* !__ASSEMBLER__ */ |
|
0 commit comments