Skip to content

Commit

Permalink
Monolithic build: Automatically namespace statics
Browse files Browse the repository at this point in the history
Signed-off-by: Hanno Becker <[email protected]>
  • Loading branch information
hanno-becker committed Jan 4, 2025
1 parent ceb2fef commit 016af58
Show file tree
Hide file tree
Showing 6 changed files with 324 additions and 46 deletions.
7 changes: 7 additions & 0 deletions examples/monolithic_build/mlkem_native_all.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
* mlkem-native
*/


/* Namespace all statics */
#include "mlkem_native_namespace_statics.i"

#include "mlkem/cbd.c"
#include "mlkem/debug/debug.c"
#include "mlkem/fips202/fips202.c"
Expand All @@ -37,3 +41,6 @@

/* Undo all definitions from *.c or *.h files */
#include "mlkem_native_cleanup.i"

/* Un-Namespace all statics */
#include "mlkem_native_unnamespace_statics.i"
76 changes: 38 additions & 38 deletions examples/monolithic_build/mlkem_native_cleanup.i
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,6 @@
#undef asm
#endif

/* mlkem/namespace.h:22 */
#if defined(___MLKEM_DEFAULT_NAMESPACE)
#undef ___MLKEM_DEFAULT_NAMESPACE
#endif

/* mlkem/native/x86_64/src/consts.c:23 */
#if defined(MONTSQHI)
#undef MONTSQHI
Expand Down Expand Up @@ -526,6 +521,11 @@
#undef poly_tomont
#endif

/* mlkem/namespace.h:25 */
#if defined(__MLKEM_DEFAULT_NAMESPACE)
#undef __MLKEM_DEFAULT_NAMESPACE
#endif

/* mlkem/debug/debug.h:219 */
#if defined(STATIC_ASSERT)
#undef STATIC_ASSERT
Expand Down Expand Up @@ -751,11 +751,6 @@
#undef poly_mulcache_compute
#endif

/* mlkem/namespace.h:35 */
#if defined(MLKEM_NATIVE_FIPS202_BACKEND_NAME)
#undef MLKEM_NATIVE_FIPS202_BACKEND_NAME
#endif

/* mlkem/params.h:50 */
#if defined(MLKEM_SECRETKEYBYTES)
#undef MLKEM_SECRETKEYBYTES
Expand Down Expand Up @@ -901,11 +896,6 @@
#undef polyvec_frombytes
#endif

/* mlkem/namespace.h:13 */
#if defined(MLKEM_PARAM_NAME)
#undef MLKEM_PARAM_NAME
#endif

/* mlkem/native/x86_64/src/arith_native_x86_64.h:5 */
#if defined(MLKEM_X86_64_NATIVE_H)
#undef MLKEM_X86_64_NATIVE_H
Expand Down Expand Up @@ -1181,16 +1171,16 @@
#undef _16XFLO
#endif

/* mlkem/namespace.h:40 */
#if defined(___FIPS202_DEFAULT_NAMESPACE)
#undef ___FIPS202_DEFAULT_NAMESPACE
#endif

/* mlkem/native/x86_64/src/arith_native_x86_64.h:53 */
#if defined(nttfrombytes_avx2)
#undef nttfrombytes_avx2
#endif

/* mlkem/namespace.h:23 */
#if defined(__MLKEM_DEFAULT_NAMESPACE)
#undef __MLKEM_DEFAULT_NAMESPACE
#endif

/* mlkem/params.h:37 */
#if defined(MLKEM_POLYVECCOMPRESSEDBYTES_DU)
#undef MLKEM_POLYVECCOMPRESSEDBYTES_DU
Expand Down Expand Up @@ -1306,6 +1296,11 @@
#undef nttunpack_avx2
#endif

/* mlkem/namespace.h:32 */
#if defined(MLKEM_DEFAULT_NAMESPACE)
#undef MLKEM_DEFAULT_NAMESPACE
#endif

/* mlkem/fips202/fips202x4.h:5 */
#if defined(FIPS_202X4_H)
#undef FIPS_202X4_H
Expand Down Expand Up @@ -1511,6 +1506,11 @@
#undef MLKEM_INDCPA_PUBLICKEYBYTES
#endif

/* mlkem/namespace.h:19 */
#if defined(MLKEM_PARAM_NAME)
#undef MLKEM_PARAM_NAME
#endif

/* mlkem/cbmc.h:51 */
#if defined(return_value)
#undef return_value
Expand Down Expand Up @@ -1691,6 +1691,11 @@
#undef FullUnrolling
#endif

/* mlkem/namespace.h:41 */
#if defined(__FIPS202_DEFAULT_NAMESPACE)
#undef __FIPS202_DEFAULT_NAMESPACE
#endif

/* mlkem/verify.h:56 */
#if defined(ct_opt_blocker_u64)
#undef ct_opt_blocker_u64
Expand Down Expand Up @@ -1826,11 +1831,6 @@
#undef KeccakP1600times4_statesAlignment
#endif

/* mlkem/namespace.h:38 */
#if defined(___FIPS202_DEFAULT_NAMESPACE)
#undef ___FIPS202_DEFAULT_NAMESPACE
#endif

/* mlkem/native/aarch64/src/arith_native_aarch64.h:15 */
#if defined(aarch64_invntt_zetas_layer56)
#undef aarch64_invntt_zetas_layer56
Expand Down Expand Up @@ -1896,9 +1896,9 @@
#undef poly_decompress_du
#endif

/* mlkem/namespace.h:30 */
#if defined(MLKEM_DEFAULT_NAMESPACE)
#undef MLKEM_DEFAULT_NAMESPACE
/* mlkem/namespace.h:24 */
#if defined(___MLKEM_DEFAULT_NAMESPACE)
#undef ___MLKEM_DEFAULT_NAMESPACE
#endif

/* mlkem/native/aarch64/src/arith_native_aarch64.h:12 */
Expand All @@ -1916,6 +1916,11 @@
#undef MLKEM_USE_NATIVE_POLY_REDUCE
#endif

/* mlkem/namespace.h:48 */
#if defined(FIPS202_DEFAULT_NAMESPACE)
#undef FIPS202_DEFAULT_NAMESPACE
#endif

/* mlkem/native/aarch64/src/opt_impl.h:23 */
#if defined(MLKEM_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED)
#undef MLKEM_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED
Expand Down Expand Up @@ -2306,11 +2311,6 @@
#undef indcpa_keypair_derand
#endif

/* mlkem/namespace.h:39 */
#if defined(__FIPS202_DEFAULT_NAMESPACE)
#undef __FIPS202_DEFAULT_NAMESPACE
#endif

/* mlkem/cbmc.h:86 */
#if defined(forall)
#undef forall
Expand Down Expand Up @@ -2411,11 +2411,6 @@
#undef MLKEM_POLYCOMPRESSEDBYTES_DU
#endif

/* mlkem/namespace.h:46 */
#if defined(FIPS202_DEFAULT_NAMESPACE)
#undef FIPS202_DEFAULT_NAMESPACE
#endif

/* mlkem/native/aarch64/src/clean_impl.h:10 */
#if defined(MLKEM_NATIVE_ARITH_PROFILE_IMPL_H)
#undef MLKEM_NATIVE_ARITH_PROFILE_IMPL_H
Expand All @@ -2431,6 +2426,11 @@
#undef CBMC_CONCAT
#endif

/* mlkem/namespace.h:37 */
#if defined(MLKEM_NATIVE_FIPS202_BACKEND_NAME)
#undef MLKEM_NATIVE_FIPS202_BACKEND_NAME
#endif

/* mlkem/native/aarch64/src/arith_native_aarch64.h:5 */
#if defined(MLKEM_AARCH64_NATIVE_H)
#undef MLKEM_AARCH64_NATIVE_H
Expand Down
68 changes: 68 additions & 0 deletions examples/monolithic_build/mlkem_native_namespace_statics.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2024 The mlkem-native project authors
* SPDX-License-Identifier: Apache-2.0
*/

/*
* WARNING: This file is auto-generated from scripts/autogenerate_files.py
* Do not modify it directly.
*/

/*
* Namespacing of statics
*/


/* Namespace all static definitions from *.c or *.h files */
#define cbd2 MLKEM_NAMESPACE(cbd2)
#define scalar_compress_d5 MLKEM_NAMESPACE(scalar_compress_d5)
#define ct_memcmp MLKEM_NAMESPACE(ct_memcmp)
#define montgomery_reduce MLKEM_NAMESPACE(montgomery_reduce)
#define shake256x4_squeezeblocks MLKEM_NAMESPACE(shake256x4_squeezeblocks)
#define scalar_compress_d11 MLKEM_NAMESPACE(scalar_compress_d11)
#define ct_cmov_zero MLKEM_NAMESPACE(ct_cmov_zero)
#define shake256x4_absorb_once MLKEM_NAMESPACE(shake256x4_absorb_once)
#define keccak_absorb_once MLKEM_NAMESPACE(keccak_absorb_once)
#define rej_uniform_scalar MLKEM_NAMESPACE(rej_uniform_scalar)
#define ct_cmask_nonzero_u16 MLKEM_NAMESPACE(ct_cmask_nonzero_u16)
#define KeccakF_RoundConstants MLKEM_NAMESPACE(KeccakF_RoundConstants)
#define ct_cmask_neg_i16 MLKEM_NAMESPACE(ct_cmask_neg_i16)
#define poly_permute_bitrev_to_custom \
MLKEM_NAMESPACE(poly_permute_bitrev_to_custom)
#define invntt_layer MLKEM_NAMESPACE(invntt_layer)
#define cast_uint16_to_int16 MLKEM_NAMESPACE(cast_uint16_to_int16)
#define keccak_squeezeblocks_x4 MLKEM_NAMESPACE(keccak_squeezeblocks_x4)
#define fqmul MLKEM_NAMESPACE(fqmul)
#define ct_sel_uint8 MLKEM_NAMESPACE(ct_sel_uint8)
#define value_barrier_u32 MLKEM_NAMESPACE(value_barrier_u32)
#define scalar_decompress_d5 MLKEM_NAMESPACE(scalar_decompress_d5)
#define keccak_squeeze_once MLKEM_NAMESPACE(keccak_squeeze_once)
#define unpack_sk MLKEM_NAMESPACE(unpack_sk)
#define check_sk MLKEM_NAMESPACE(check_sk)
#define ntt_layer MLKEM_NAMESPACE(ntt_layer)
#define unpack_ciphertext MLKEM_NAMESPACE(unpack_ciphertext)
#define scalar_signed_to_unsigned_q MLKEM_NAMESPACE(scalar_signed_to_unsigned_q)
#define value_barrier_i32 MLKEM_NAMESPACE(value_barrier_i32)
#define pack_ciphertext MLKEM_NAMESPACE(pack_ciphertext)
#define montgomery_reduce_generic MLKEM_NAMESPACE(montgomery_reduce_generic)
#define gen_matrix_entry_x4 MLKEM_NAMESPACE(gen_matrix_entry_x4)
#define keccak_absorb_once_x4 MLKEM_NAMESPACE(keccak_absorb_once_x4)
#define gen_matrix_entry MLKEM_NAMESPACE(gen_matrix_entry)
#define ntt_butterfly_block MLKEM_NAMESPACE(ntt_butterfly_block)
#define matvec_mul MLKEM_NAMESPACE(matvec_mul)
#define scalar_decompress_d4 MLKEM_NAMESPACE(scalar_decompress_d4)
#define barrett_reduce MLKEM_NAMESPACE(barrett_reduce)
#define value_barrier_u8 MLKEM_NAMESPACE(value_barrier_u8)
#define pack_pk MLKEM_NAMESPACE(pack_pk)
#define pack_sk MLKEM_NAMESPACE(pack_sk)
#define unpack_pk MLKEM_NAMESPACE(unpack_pk)
#define ct_cmask_nonzero_u8 MLKEM_NAMESPACE(ct_cmask_nonzero_u8)
#define keccak_squeezeblocks MLKEM_NAMESPACE(keccak_squeezeblocks)
#define scalar_decompress_d10 MLKEM_NAMESPACE(scalar_decompress_d10)
#define ct_sel_int16 MLKEM_NAMESPACE(ct_sel_int16)
#define load32_littleendian MLKEM_NAMESPACE(load32_littleendian)
#define scalar_compress_d10 MLKEM_NAMESPACE(scalar_compress_d10)
#define scalar_compress_d4 MLKEM_NAMESPACE(scalar_compress_d4)
#define scalar_decompress_d11 MLKEM_NAMESPACE(scalar_decompress_d11)
#define scalar_compress_d1 MLKEM_NAMESPACE(scalar_compress_d1)
#define check_pk MLKEM_NAMESPACE(check_pk)
67 changes: 67 additions & 0 deletions examples/monolithic_build/mlkem_native_unnamespace_statics.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2024 The mlkem-native project authors
* SPDX-License-Identifier: Apache-2.0
*/

/*
* WARNING: This file is auto-generated from scripts/autogenerate_files.py
* Do not modify it directly.
*/

/*
* Undo all namespacing of statics
*/


/* Unnamespace all static definitions from *.c or *.h files */
#undef cbd2
#undef scalar_compress_d5
#undef ct_memcmp
#undef montgomery_reduce
#undef shake256x4_squeezeblocks
#undef scalar_compress_d11
#undef ct_cmov_zero
#undef shake256x4_absorb_once
#undef keccak_absorb_once
#undef rej_uniform_scalar
#undef ct_cmask_nonzero_u16
#undef KeccakF_RoundConstants
#undef ct_cmask_neg_i16
#undef poly_permute_bitrev_to_custom
#undef invntt_layer
#undef cast_uint16_to_int16
#undef keccak_squeezeblocks_x4
#undef fqmul
#undef ct_sel_uint8
#undef value_barrier_u32
#undef scalar_decompress_d5
#undef keccak_squeeze_once
#undef unpack_sk
#undef check_sk
#undef ntt_layer
#undef unpack_ciphertext
#undef scalar_signed_to_unsigned_q
#undef value_barrier_i32
#undef pack_ciphertext
#undef montgomery_reduce_generic
#undef gen_matrix_entry_x4
#undef keccak_absorb_once_x4
#undef gen_matrix_entry
#undef ntt_butterfly_block
#undef matvec_mul
#undef scalar_decompress_d4
#undef barrett_reduce
#undef value_barrier_u8
#undef pack_pk
#undef pack_sk
#undef unpack_pk
#undef ct_cmask_nonzero_u8
#undef keccak_squeezeblocks
#undef scalar_decompress_d10
#undef ct_sel_int16
#undef load32_littleendian
#undef scalar_compress_d10
#undef scalar_compress_d4
#undef scalar_decompress_d11
#undef scalar_compress_d1
#undef check_pk
2 changes: 2 additions & 0 deletions mlkem/namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#define MLKEM_NATIVE_ARITH_BACKEND_NAME C
#endif

#include "config.h"

/* Don't change parameters below this line */
#if (MLKEM_K == 2)
#define MLKEM_PARAM_NAME MLKEM512
Expand Down
Loading

0 comments on commit 016af58

Please sign in to comment.