Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Macros:
- __contract__(x)={ void a; void b; void c; void d; void e; void f; } void abcdefghijklmnopqrstuvw()
- __loop__(x)={} do
# Make this artifically long to force line break
- MLK_INTERNAL_API=void abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvwabcdefg();
- MLD_INTERNAL_API=void abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvwabcdefg();
2 changes: 1 addition & 1 deletion mldsa/mldsa_native.S
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
#undef MLD_NAMESPACE_KL
#undef MLD_NAMESPACE_PREFIX
#undef MLD_NAMESPACE_PREFIX_KL
#undef MLK_UNION_OR_STRUCT
#undef MLD_UNION_OR_STRUCT
#undef mld_memcpy
#undef mld_memset
/* mldsa/src/packing.h */
Expand Down
2 changes: 1 addition & 1 deletion mldsa/mldsa_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
#undef MLD_NAMESPACE_KL
#undef MLD_NAMESPACE_PREFIX
#undef MLD_NAMESPACE_PREFIX_KL
#undef MLK_UNION_OR_STRUCT
#undef MLD_UNION_OR_STRUCT
#undef mld_memcpy
#undef mld_memset
/* mldsa/src/packing.h */
Expand Down
4 changes: 2 additions & 2 deletions mldsa/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@
* is resolved
*/
#if defined(MLD_CONFIG_REDUCE_RAM)
#define MLK_UNION_OR_STRUCT union
#define MLD_UNION_OR_STRUCT union
#else
#define MLK_UNION_OR_STRUCT struct
#define MLD_UNION_OR_STRUCT struct
#endif

/****************************** Error codes ***********************************/
Expand Down
2 changes: 1 addition & 1 deletion mldsa/src/packing.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ __contract__(
*
* Returns 1 in case of malformed signature; otherwise 0.
**************************************************/
MLD_MUST_CHECK_RETURN_VALUE
MLD_INTERNAL_API
MLD_MUST_CHECK_RETURN_VALUE
int mld_unpack_sig(uint8_t c[MLDSA_CTILDEBYTES], mld_polyvecl *z,
mld_polyveck *h, const uint8_t sig[MLDSA_CRYPTO_BYTES])
__contract__(
Expand Down
6 changes: 3 additions & 3 deletions mldsa/src/polyvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ __contract__(
* Returns 0 if norm of all polynomials is strictly smaller than B <=
* (MLDSA_Q-1)/8 and 0xFFFFFFFF otherwise.
**************************************************/
MLD_MUST_CHECK_RETURN_VALUE
MLD_INTERNAL_API
MLD_MUST_CHECK_RETURN_VALUE
uint32_t mld_polyvecl_chknorm(const mld_polyvecl *v, int32_t B)
__contract__(
requires(memory_no_alias(v, sizeof(mld_polyvecl)))
Expand Down Expand Up @@ -429,8 +429,8 @@ __contract__(
* Returns 0 if norm of all polynomials are strictly smaller than B <=
*(MLDSA_Q-1)/8 and 0xFFFFFFFF otherwise.
**************************************************/
MLD_MUST_CHECK_RETURN_VALUE
MLD_INTERNAL_API
MLD_MUST_CHECK_RETURN_VALUE
uint32_t mld_polyveck_chknorm(const mld_polyveck *v, int32_t B)
__contract__(
requires(memory_no_alias(v, sizeof(mld_polyveck)))
Expand Down Expand Up @@ -519,8 +519,8 @@ __contract__(
*
* Returns number of 1 bits.
**************************************************/
MLD_MUST_CHECK_RETURN_VALUE
MLD_INTERNAL_API
MLD_MUST_CHECK_RETURN_VALUE
unsigned int mld_polyveck_make_hint(mld_polyveck *h, const mld_polyveck *v0,
const mld_polyveck *v1)
__contract__(
Expand Down
2 changes: 1 addition & 1 deletion mldsa/src/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ __contract__(
int ret;
/* TODO: Remove the following workaround for
* https://github.com/diffblue/cbmc/issues/8813 */
typedef MLK_UNION_OR_STRUCT
typedef MLD_UNION_OR_STRUCT
{
mld_polyvecl y;
mld_polyveck h;
Expand Down
12 changes: 12 additions & 0 deletions scripts/autogen
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ _RE_C_CITE = re.compile(r"@\[(?P<id>\w+)")
_RE_BYTECODE_START = re.compile(r"=== bytecode start: mldsa/([^/\s]+?)\.o")
_RE_FUNC_SYMBOL = re.compile(r"MLD_ASM_FN_SYMBOL\((.*)\)")
_RE_MACRO_CHECK = re.compile(r"[^_]((?:MLD_|MLDSA_)\w+)(.*)$", re.M)
_RE_MLKEM_MACRO_CHECK = re.compile(r"[^_]((?:MLK_|MLKEM_)\w+)(.*)$", re.M)
_RE_DEFINE = re.compile(r"^\s*#define\s+(\w+)")
_RE_ARGS_COMMENT = re.compile(r"(.*?)(\s*//.*)?$")
_RE_MACRO_DEF = re.compile(r"^\s*\.macro\s+(\w+)")
Expand Down Expand Up @@ -1796,6 +1797,17 @@ def check_macro_typos_in_file(filename, macro_check):
status_update("check-macros", filename)
content = read_file(filename)

# Separate check for wrongly ported MLK/MLKEM macros
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you run this check first? Otherwise, if you wrongly port #define MLK_FOO ... but use MLD_FOO in the code, you'll get the error "Undefined macro MLD_FOO" from the first check, but it would be clearer to get the second error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @hanno-becker, thank you for your help.
You are correct. Thank you for pointing this issue out. I have adjusted the order based on your suggestion and verified it with selftests.

for m in _RE_MLKEM_MACRO_CHECK.finditer(content):
txt = m.group(1)
rest = m.group(2)
line_no = content[: m.start()].count("\n") + 1
if filename != "scripts/autogen":
raise Exception(
f"Likely typo {txt} in {filename}:{line_no}? wrongly ported MLK_XXX / MLKEM_XXX macros from mlkem-native."
)

# Check MLD/MLDSA macros
for m in _RE_MACRO_CHECK.finditer(content):
txt = m.group(1)
rest = m.group(2)
Expand Down
Loading