diff --git a/.clang-format b/.clang-format index cd8ae82c6..3b64539b6 100644 --- a/.clang-format +++ b/.clang-format @@ -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(); diff --git a/mldsa/mldsa_native.S b/mldsa/mldsa_native.S index 8428fc58a..4839f354e 100644 --- a/mldsa/mldsa_native.S +++ b/mldsa/mldsa_native.S @@ -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 */ diff --git a/mldsa/mldsa_native.c b/mldsa/mldsa_native.c index 9396a7efd..949835ac1 100644 --- a/mldsa/mldsa_native.c +++ b/mldsa/mldsa_native.c @@ -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 */ diff --git a/mldsa/src/common.h b/mldsa/src/common.h index 02a73a8e5..788062c96 100644 --- a/mldsa/src/common.h +++ b/mldsa/src/common.h @@ -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 ***********************************/ diff --git a/mldsa/src/packing.h b/mldsa/src/packing.h index 1fdec836d..f6dac306f 100644 --- a/mldsa/src/packing.h +++ b/mldsa/src/packing.h @@ -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__( diff --git a/mldsa/src/polyvec.h b/mldsa/src/polyvec.h index 71e902e90..8ef5cec0d 100644 --- a/mldsa/src/polyvec.h +++ b/mldsa/src/polyvec.h @@ -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))) @@ -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))) @@ -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__( diff --git a/mldsa/src/sign.c b/mldsa/src/sign.c index 2896cf2b6..3b06aa932 100644 --- a/mldsa/src/sign.c +++ b/mldsa/src/sign.c @@ -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; diff --git a/scripts/autogen b/scripts/autogen index e515a1a1f..3b5199046 100755 --- a/scripts/autogen +++ b/scripts/autogen @@ -30,6 +30,7 @@ _RE_C_CITE = re.compile(r"@\[(?P\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+)") @@ -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 + 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)