From 71809b1502f2f87078e148449fda373fc7e39929 Mon Sep 17 00:00:00 2001 From: Andrew Hopkins Date: Fri, 3 Jan 2025 14:08:40 -0800 Subject: [PATCH] Update ML-KEM's internal header files to use unique include guards (#2078) ### Description of changes: Inspired by the issues in https://github.com/aws/aws-lc/pull/2072 this PR update's ML-KEM's include guards to use unique names to avoid any future issues. ### Call-outs: Future PRs could also prefix more of the functions. ### Testing: Existing tests will cover any issues. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license. --- crypto/fipsmodule/ml_kem/README.md | 1 + crypto/fipsmodule/ml_kem/ml_kem_ref/cbd.h | 4 ++-- crypto/fipsmodule/ml_kem/ml_kem_ref/indcpa.h | 4 ++-- crypto/fipsmodule/ml_kem/ml_kem_ref/ntt.h | 4 ++-- crypto/fipsmodule/ml_kem/ml_kem_ref/params.h | 4 ++-- crypto/fipsmodule/ml_kem/ml_kem_ref/poly.h | 4 ++-- crypto/fipsmodule/ml_kem/ml_kem_ref/polyvec.h | 4 ++-- crypto/fipsmodule/ml_kem/ml_kem_ref/reduce.h | 4 ++-- crypto/fipsmodule/ml_kem/ml_kem_ref/symmetric.h | 4 ++-- crypto/fipsmodule/ml_kem/ml_kem_ref/verify.h | 4 ++-- 10 files changed, 19 insertions(+), 18 deletions(-) diff --git a/crypto/fipsmodule/ml_kem/README.md b/crypto/fipsmodule/ml_kem/README.md index 69dc369d80..5ad7b64b5d 100644 --- a/crypto/fipsmodule/ml_kem/README.md +++ b/crypto/fipsmodule/ml_kem/README.md @@ -12,5 +12,6 @@ that initialize a given structure with values corresponding to a parameter set. - `symmetric-shake.c`: unnecessary include of fips202.h is removed. - `api.h`: `pqcrystals` prefix substituted with `ml_kem` (to be able to build alongside `crypto/kyber`). - `poly.c`: the `poly_frommsg` function was modified to address the constant-time issue described [here](https://github.com/pq-crystals/kyber/commit/9b8d30698a3e7449aeb34e62339d4176f11e3c6c). +- All internal header files were updated with unique `ML_KEM_*` include guards. **Testing.** The KATs were obtained from an independent implementation of ML-KEM written in SPARK Ada subset: https://github.com/awslabs/LibMLKEM. diff --git a/crypto/fipsmodule/ml_kem/ml_kem_ref/cbd.h b/crypto/fipsmodule/ml_kem/ml_kem_ref/cbd.h index 5305193688..0ed2facc27 100644 --- a/crypto/fipsmodule/ml_kem/ml_kem_ref/cbd.h +++ b/crypto/fipsmodule/ml_kem/ml_kem_ref/cbd.h @@ -1,5 +1,5 @@ -#ifndef CBD_H -#define CBD_H +#ifndef ML_KEM_CBD_H +#define ML_KEM_CBD_H #include #include "params.h" diff --git a/crypto/fipsmodule/ml_kem/ml_kem_ref/indcpa.h b/crypto/fipsmodule/ml_kem/ml_kem_ref/indcpa.h index 5687075697..d13fc48faf 100644 --- a/crypto/fipsmodule/ml_kem/ml_kem_ref/indcpa.h +++ b/crypto/fipsmodule/ml_kem/ml_kem_ref/indcpa.h @@ -1,5 +1,5 @@ -#ifndef INDCPA_H -#define INDCPA_H +#ifndef ML_KEM_INDCPA_H +#define ML_KEM_INDCPA_H #include #include "params.h" diff --git a/crypto/fipsmodule/ml_kem/ml_kem_ref/ntt.h b/crypto/fipsmodule/ml_kem/ml_kem_ref/ntt.h index 227ea74f08..04636ad0c5 100644 --- a/crypto/fipsmodule/ml_kem/ml_kem_ref/ntt.h +++ b/crypto/fipsmodule/ml_kem/ml_kem_ref/ntt.h @@ -1,5 +1,5 @@ -#ifndef NTT_H -#define NTT_H +#ifndef ML_KEM_NTT_H +#define ML_KEM_NTT_H #include #include "params.h" diff --git a/crypto/fipsmodule/ml_kem/ml_kem_ref/params.h b/crypto/fipsmodule/ml_kem/ml_kem_ref/params.h index 374b9bc2a1..fd796614f4 100644 --- a/crypto/fipsmodule/ml_kem/ml_kem_ref/params.h +++ b/crypto/fipsmodule/ml_kem/ml_kem_ref/params.h @@ -1,5 +1,5 @@ -#ifndef PARAMS_H -#define PARAMS_H +#ifndef ML_KEM_PARAMS_H +#define ML_KEM_PARAMS_H #include diff --git a/crypto/fipsmodule/ml_kem/ml_kem_ref/poly.h b/crypto/fipsmodule/ml_kem/ml_kem_ref/poly.h index a7f8a3ae4f..df9b1fab14 100644 --- a/crypto/fipsmodule/ml_kem/ml_kem_ref/poly.h +++ b/crypto/fipsmodule/ml_kem/ml_kem_ref/poly.h @@ -1,5 +1,5 @@ -#ifndef POLY_H -#define POLY_H +#ifndef ML_KEM_POLY_H +#define ML_KEM_POLY_H #include #include "params.h" diff --git a/crypto/fipsmodule/ml_kem/ml_kem_ref/polyvec.h b/crypto/fipsmodule/ml_kem/ml_kem_ref/polyvec.h index 04b6081260..a7b57cafc6 100644 --- a/crypto/fipsmodule/ml_kem/ml_kem_ref/polyvec.h +++ b/crypto/fipsmodule/ml_kem/ml_kem_ref/polyvec.h @@ -1,5 +1,5 @@ -#ifndef POLYVEC_H -#define POLYVEC_H +#ifndef ML_KEM_POLYVEC_H +#define ML_KEM_POLYVEC_H #include #include "params.h" diff --git a/crypto/fipsmodule/ml_kem/ml_kem_ref/reduce.h b/crypto/fipsmodule/ml_kem/ml_kem_ref/reduce.h index c1bc1e4c7b..d4b6603ed6 100644 --- a/crypto/fipsmodule/ml_kem/ml_kem_ref/reduce.h +++ b/crypto/fipsmodule/ml_kem/ml_kem_ref/reduce.h @@ -1,5 +1,5 @@ -#ifndef REDUCE_H -#define REDUCE_H +#ifndef ML_KEM_REDUCE_H +#define ML_KEM_REDUCE_H #include #include "params.h" diff --git a/crypto/fipsmodule/ml_kem/ml_kem_ref/symmetric.h b/crypto/fipsmodule/ml_kem/ml_kem_ref/symmetric.h index 0f5678e51a..93d8b63a6f 100644 --- a/crypto/fipsmodule/ml_kem/ml_kem_ref/symmetric.h +++ b/crypto/fipsmodule/ml_kem/ml_kem_ref/symmetric.h @@ -1,5 +1,5 @@ -#ifndef SYMMETRIC_H -#define SYMMETRIC_H +#ifndef ML_KEM_SYMMETRIC_H +#define ML_KEM_SYMMETRIC_H #include #include diff --git a/crypto/fipsmodule/ml_kem/ml_kem_ref/verify.h b/crypto/fipsmodule/ml_kem/ml_kem_ref/verify.h index f95ac1b84e..1ae4196fb4 100644 --- a/crypto/fipsmodule/ml_kem/ml_kem_ref/verify.h +++ b/crypto/fipsmodule/ml_kem/ml_kem_ref/verify.h @@ -1,5 +1,5 @@ -#ifndef VERIFY_H -#define VERIFY_H +#ifndef ML_KEM_VERIFY_H +#define ML_KEM_VERIFY_H #include #include