Skip to content

Commit f2a71bd

Browse files
committed
ML-DSA x86_64: import full assembly backend from mldsa-native
Result of running importer.sh against mldsa-native 1dbd70f78583fab6fbfc46287702d6a09d5ec5e6. Imports the complete x86_64 assembly backend: adds verified .S implementations for poly_chknorm, poly_decompose_{32,88}, poly_use_hint_{32,88}, polyz_unpack_{17,19}, rej_uniform, and rej_uniform_eta{2,4} (previously AVX2 C intrinsics, excluded from import), plus the upstream meta.h and rej_uniform_table.c. The remainder is the corresponding mldsa-native C-source refresh. Generated by importer.sh; do not edit by hand.
1 parent e7d1077 commit f2a71bd

62 files changed

Lines changed: 4873 additions & 907 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crypto/fipsmodule/ml_dsa/META.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: mldsa-native
22
source: pq-code-package/mldsa-native.git
3-
branch: 08d40f9403a9ca80f160118bc63e96bf36627866
4-
commit: 08d40f9403a9ca80f160118bc63e96bf36627866
5-
imported-at: 2026-06-12T17:04:44+0000
3+
branch: 1dbd70f78583fab6fbfc46287702d6a09d5ec5e6
4+
commit: 1dbd70f78583fab6fbfc46287702d6a09d5ec5e6
5+
imported-at: 2026-07-17T20:21:14+0000

crypto/fipsmodule/ml_dsa/mldsa/.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ Macros:
2727
- __loop__(x)={} do
2828
# Make this artifically long to force line break
2929
- MLD_INTERNAL_API=void abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvwabcdefg();
30+
- MLD_SYSV_ABI=void abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvwabcdefg();

crypto/fipsmodule/ml_dsa/mldsa/cbmc.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,28 @@
99
/***************************************************
1010
* Basic replacements for __CPROVER_XXX contracts
1111
***************************************************/
12+
/*
13+
* The `__contract__` / `__loop__` annotation macros use a
14+
* leading-double-underscore spelling in line with other CBMC macros.
15+
* clang-tidy flags these as reserved identifiers; we suppress the diagnostic
16+
* at each definition site (NOLINT) rather than disabling the check globally,
17+
* so it stays active for the rest of the tree.
18+
*/
1219
#ifndef CBMC
1320

14-
#define __contract__(x)
15-
#define __loop__(x)
21+
/* clang-format off */
22+
#define __contract__(x) /* NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp) */
23+
#define __loop__(x) /* NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp) */
24+
/* clang-format on */
1625
#define cassert(x)
1726

1827
#else /* !CBMC */
1928

2029

21-
#define __contract__(x) x
22-
#define __loop__(x) x
30+
/* clang-format off */
31+
#define __contract__(x) x /* NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp) */
32+
#define __loop__(x) x /* NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp) */
33+
/* clang-format on */
2334

2435
/* Conditionally expand to __VA_ARGS__ depending on MLD_CONFIG_REDUCE_RAM. */
2536
#if defined(MLD_CONFIG_REDUCE_RAM)

crypto/fipsmodule/ml_dsa/mldsa/common.h

Lines changed: 31 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@
129129
#endif
130130

131131
#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()
133133
#endif
134134

135135
#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()
137137
#endif
138138

139139
#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()
141141
#endif
142142

143143
#if defined(MLD_CONFIG_USE_NATIVE_BACKEND_ARITH)
@@ -202,77 +202,31 @@
202202
#error Bad configuration: MLD_CONFIG_CUSTOM_ALLOC_FREE must be set together with MLD_CUSTOM_ALLOC and MLD_CUSTOM_FREE
203203
#endif
204204

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"
261210

262211
#if !defined(MLD_CONFIG_CUSTOM_ALLOC_FREE)
263212
/* Default: stack allocation */
264213

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. */
265217
#define MLD_ALLOC(v, T, N, context) \
266218
MLD_ALIGN T mld_alloc_##v[N]; \
267-
T *v = mld_alloc_##v
219+
T *v = mld_alloc_##v /* NOLINT(bugprone-macro-parentheses) */
268220

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. */
273226
#define MLD_FREE(v, T, N, context) \
274227
do \
275228
{ \
229+
MLD_CONTEXT_UNUSED(context); \
276230
mld_zeroize(mld_alloc_##v, sizeof(mld_alloc_##v)); \
277231
(v) = NULL; \
278232
} while (0)
@@ -305,27 +259,33 @@
305259
/****************************** Error codes ***********************************/
306260

307261
/* Generic failure condition */
308-
#define MLD_ERR_FAIL -1
262+
#define MLD_ERR_FAIL (-1)
309263
/* An allocation failed. This can only happen if MLD_CONFIG_CUSTOM_ALLOC_FREE
310264
* 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)
312266
/* An rng failure occured. Might be due to insufficient entropy or
313267
* system misconfiguration. */
314-
#define MLD_ERR_RNG_FAIL -3
268+
#define MLD_ERR_RNG_FAIL (-3)
315269
/* The signing rejection-sampling loop exceeded
316270
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS iterations without producing a valid
317271
* signature. With a FIPS 204 Appendix C compliant bound (>= 814) this
318272
* 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)
320279

321280
/* Disjunction over the full set of MLD_ERR_XXX failure codes.
322281
*
323282
* Intended for use in top-level `ensures` clauses that admit every
324283
* possible error. Narrower contracts should enumerate only the
325284
* 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)
329289

330290

331291
#endif /* !__ASSEMBLER__ */
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* Copyright (c) The mldsa-native project authors
3+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4+
*/
5+
#ifndef MLD_CONTEXT_H
6+
#define MLD_CONTEXT_H
7+
8+
/* This header is included by common.h once the configuration has been pulled
9+
* in; it is not meant to be included directly. */
10+
#if !defined(__ASSEMBLER__)
11+
12+
#include <stdint.h>
13+
#include "cbmc.h"
14+
#include "sys.h"
15+
16+
/*
17+
* If the integration wants to provide a context parameter for use in
18+
* platform-specific hooks, then it should define this parameter.
19+
*
20+
* The MLD_CONTEXT_PARAMETERS_n macros are intended to be used with macros
21+
* defining the function names and expand to either pass or discard the context
22+
* argument as required by the current build. If there is no context parameter
23+
* requested then these are removed from the prototypes and from all calls.
24+
*/
25+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
26+
#define MLD_CONTEXT_PARAMETERS_0(context) (context)
27+
#define MLD_CONTEXT_PARAMETERS_1(arg0, context) (arg0, context)
28+
#define MLD_CONTEXT_PARAMETERS_2(arg0, arg1, context) (arg0, arg1, context)
29+
#define MLD_CONTEXT_PARAMETERS_3(arg0, arg1, arg2, context) \
30+
(arg0, arg1, arg2, context)
31+
#define MLD_CONTEXT_PARAMETERS_4(arg0, arg1, arg2, arg3, context) \
32+
(arg0, arg1, arg2, arg3, context)
33+
#define MLD_CONTEXT_PARAMETERS_5(arg0, arg1, arg2, arg3, arg4, context) \
34+
(arg0, arg1, arg2, arg3, arg4, context)
35+
#define MLD_CONTEXT_PARAMETERS_6(arg0, arg1, arg2, arg3, arg4, arg5, context) \
36+
(arg0, arg1, arg2, arg3, arg4, arg5, context)
37+
#define MLD_CONTEXT_PARAMETERS_7(arg0, arg1, arg2, arg3, arg4, arg5, arg6, \
38+
context) \
39+
(arg0, arg1, arg2, arg3, arg4, arg5, arg6, context)
40+
#define MLD_CONTEXT_PARAMETERS_8(arg0, arg1, arg2, arg3, arg4, arg5, arg6, \
41+
arg7, context) \
42+
(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, context)
43+
#define MLD_CONTEXT_PARAMETERS_9(arg0, arg1, arg2, arg3, arg4, arg5, arg6, \
44+
arg7, arg8, context) \
45+
(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, context)
46+
#else /* MLD_CONFIG_CONTEXT_PARAMETER */
47+
#define MLD_CONTEXT_PARAMETERS_0(context) ()
48+
#define MLD_CONTEXT_PARAMETERS_1(arg0, context) (arg0)
49+
#define MLD_CONTEXT_PARAMETERS_2(arg0, arg1, context) (arg0, arg1)
50+
#define MLD_CONTEXT_PARAMETERS_3(arg0, arg1, arg2, context) (arg0, arg1, arg2)
51+
#define MLD_CONTEXT_PARAMETERS_4(arg0, arg1, arg2, arg3, context) \
52+
(arg0, arg1, arg2, arg3)
53+
#define MLD_CONTEXT_PARAMETERS_5(arg0, arg1, arg2, arg3, arg4, context) \
54+
(arg0, arg1, arg2, arg3, arg4)
55+
#define MLD_CONTEXT_PARAMETERS_6(arg0, arg1, arg2, arg3, arg4, arg5, context) \
56+
(arg0, arg1, arg2, arg3, arg4, arg5)
57+
#define MLD_CONTEXT_PARAMETERS_7(arg0, arg1, arg2, arg3, arg4, arg5, arg6, \
58+
context) \
59+
(arg0, arg1, arg2, arg3, arg4, arg5, arg6)
60+
#define MLD_CONTEXT_PARAMETERS_8(arg0, arg1, arg2, arg3, arg4, arg5, arg6, \
61+
arg7, context) \
62+
(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
63+
#define MLD_CONTEXT_PARAMETERS_9(arg0, arg1, arg2, arg3, arg4, arg5, arg6, \
64+
arg7, arg8, context) \
65+
(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
66+
#endif /* !MLD_CONFIG_CONTEXT_PARAMETER */
67+
68+
/* Consume a context parameter carried only for the integration's benefit,
69+
* avoiding -Wunused-parameter; expands to nothing when no context is
70+
* configured. */
71+
#if defined(MLD_CONFIG_CONTEXT_PARAMETER)
72+
#define MLD_CONTEXT_UNUSED(context) ((void)(context))
73+
#else
74+
#define MLD_CONTEXT_UNUSED(context) ((void)0)
75+
#endif
76+
77+
#if defined(MLD_CONFIG_CONTEXT_PARAMETER_TYPE) != \
78+
defined(MLD_CONFIG_CONTEXT_PARAMETER)
79+
#error MLD_CONFIG_CONTEXT_PARAMETER_TYPE must be defined if and only if MLD_CONFIG_CONTEXT_PARAMETER is defined
80+
#endif
81+
82+
/* The signing hooks tie into the rejection-sampling loop. A pausing attempt
83+
* hook only reproduces the uninterrupted signature if the randomness is fixed
84+
* across calls, and thus requires the deterministic API.
85+
* For now we impose that requirement on all three hooks uniformly: enabling any
86+
* of them requires MLD_CONFIG_NO_RANDOMIZED_API. This also rules out
87+
* MLD_CONFIG_KEYGEN_PCT (whose PCT needs the randomized signature(), see
88+
* common.h).
89+
*
90+
* A logging-only use (attempt always returns 0; resume/finish merely observe)
91+
* would be safe with the randomized API too, but the restriction is applied
92+
* uniformly for now. */
93+
#if (defined(MLD_CONFIG_SIGN_HOOK_RESUME) || \
94+
defined(MLD_CONFIG_SIGN_HOOK_ATTEMPT) || \
95+
defined(MLD_CONFIG_SIGN_HOOK_FINISH)) && \
96+
!defined(MLD_CONFIG_NO_RANDOMIZED_API)
97+
#error Signing hooks (MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH) require MLD_CONFIG_NO_RANDOMIZED_API
98+
#endif /* (MLD_CONFIG_SIGN_HOOK_RESUME || MLD_CONFIG_SIGN_HOOK_ATTEMPT || \
99+
MLD_CONFIG_SIGN_HOOK_FINISH) && !MLD_CONFIG_NO_RANDOMIZED_API */
100+
101+
/* Signing hooks (MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH; documented
102+
* in mldsa_native_config.h). The following macros route the call sites to
103+
* mld_sign_hook_*, appending or dropping the context argument; each unset hook
104+
* uses the dummy below. */
105+
#define mld_sign_resume mld_sign_hook_resume MLD_CONTEXT_PARAMETERS_0
106+
#define mld_sign_attempt mld_sign_hook_attempt MLD_CONTEXT_PARAMETERS_1
107+
#define mld_sign_finish mld_sign_hook_finish MLD_CONTEXT_PARAMETERS_1
108+
109+
/* We don't use mld_sign_resume here because MLD_CONTEXT_PARAMETERS_0 is
110+
* unsuitable for function declarations: it misses `void` as the placeholder
111+
* argument. */
112+
#if !defined(MLD_CONFIG_SIGN_HOOK_RESUME)
113+
MLD_MUST_CHECK_RETURN_VALUE
114+
static MLD_INLINE uint16_t mld_sign_hook_resume(
115+
#if defined(MLD_CONFIG_CONTEXT_PARAMETER)
116+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
117+
#else
118+
void
119+
#endif
120+
)
121+
__contract__(assigns() ensures(1))
122+
{
123+
MLD_CONTEXT_UNUSED(context);
124+
return 0;
125+
}
126+
#endif /* !MLD_CONFIG_SIGN_HOOK_RESUME */
127+
128+
#if !defined(MLD_CONFIG_SIGN_HOOK_ATTEMPT)
129+
MLD_MUST_CHECK_RETURN_VALUE
130+
static MLD_INLINE int mld_sign_attempt(
131+
uint16_t attempt, MLD_CONFIG_CONTEXT_PARAMETER_TYPE context)
132+
__contract__(assigns() ensures(1))
133+
{
134+
((void)attempt);
135+
MLD_CONTEXT_UNUSED(context);
136+
return 0;
137+
}
138+
#endif /* !MLD_CONFIG_SIGN_HOOK_ATTEMPT */
139+
140+
#if !defined(MLD_CONFIG_SIGN_HOOK_FINISH)
141+
static MLD_INLINE void mld_sign_finish(
142+
uint16_t attempt, MLD_CONFIG_CONTEXT_PARAMETER_TYPE context)
143+
__contract__(assigns() ensures(1))
144+
{
145+
((void)attempt);
146+
MLD_CONTEXT_UNUSED(context);
147+
}
148+
#endif /* !MLD_CONFIG_SIGN_HOOK_FINISH */
149+
150+
#endif /* !__ASSEMBLER__ */
151+
152+
#endif /* !MLD_CONTEXT_H */

crypto/fipsmodule/ml_dsa/mldsa/ct.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ static MLD_INLINE uint32_t mld_ct_cmask_nonzero_u32(uint32_t x)
230230
__contract__(ensures(return_value == ((x == 0) ? 0 : 0xFFFFFFFF)))
231231
{
232232
int64_t tmp = mld_value_barrier_i64(-((int64_t)x));
233+
/*
234+
* PORTABILITY: Right-shift on a signed integer is
235+
* implementation-defined for negative left argument.
236+
* Here, we assume it's sign-preserving "arithmetic" shift right.
237+
* See (C99 6.5.7 (5))
238+
*/
233239
tmp >>= 32;
234240
return mld_cast_int64_to_uint32(tmp);
235241
}
@@ -259,6 +265,12 @@ __contract__(
259265
)
260266
{
261267
int64_t tmp = mld_value_barrier_i64((int64_t)x);
268+
/*
269+
* PORTABILITY: Right-shift on a signed integer is
270+
* implementation-defined for negative left argument.
271+
* Here, we assume it's sign-preserving "arithmetic" shift right.
272+
* See (C99 6.5.7 (5))
273+
*/
262274
tmp >>= 31;
263275
return mld_cast_int64_to_uint32(tmp);
264276
}

0 commit comments

Comments
 (0)