Skip to content

Commit

Permalink
Simplify configurations in multilevel example
Browse files Browse the repository at this point in the history
The configurations in the multilevel-build example are the same
except for MLKEM_K, which can be modified by #define before inclusion
of the respective monobuild CU. This commit simplifies the
multilevel-monobuild example accordingly.

Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
  • Loading branch information
hanno-becker committed Feb 2, 2025
1 parent 10ee5b5 commit c12e6fb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 262 deletions.
15 changes: 9 additions & 6 deletions examples/monolithic_build_multilevel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ files. Moreover, it clears all `#define`s clauses set by mlkem-native at the end
inclusion in another compilation unit.

The manually written source file [mlkem_native_all.c](mlkem_native_all.c) includes
[mlkem_native_monobuild.c](mlkem_native_monobuild.c) three times, once for each of the three configuration files
[config_512.h](config_512.h), [config_768.h](config_768.h),
[config_1024.h](config_1024.h) for the different levels. For each inclusion, it sets `MLKEM_NATIVE_CONFIG_FILE`
[mlkem_native_monobuild.c](mlkem_native_monobuild.c) three times, each time using the fixed config
[multilevel_config.h](multilevel_config.h), but changing the security level (specified
by `MLKEM_K`) every time. For each inclusion, it sets `MLKEM_NATIVE_CONFIG_FILE`
appropriately first, and then includes the monobuild:
```C
/* Three instances of mlkem-native for all security levels */
Expand All @@ -21,19 +21,22 @@ appropriately first, and then includes the monobuild:
#define MLKEM_NATIVE_MULTILEVEL_BUILD_WITH_SHARED
#define MLKEM_NATIVE_MONOBUILD_KEEP_SHARED_HEADERS

#define MLKEM_NATIVE_CONFIG_FILE "config_512.h"
#define MLKEM_K 2
#define MLKEM_NATIVE_CONFIG_FILE "multilevel_config.h"
#include "mlkem_native_monobuild.c"
#undef MLKEM_NATIVE_CONFIG_FILE

/* Exclude level-independent code */
#undef MLKEM_NATIVE_MULTILEVEL_BUILD_WITH_SHARED
#define MLKEM_NATIVE_MULTILEVEL_BUILD_NO_SHARED

#define MLKEM_NATIVE_CONFIG_FILE "config_1024.h"
#define MLKEM_K 3
#define MLKEM_NATIVE_CONFIG_FILE "multilevel_config.h"
#include "mlkem_native_monobuild.c"
#undef MLKEM_NATIVE_CONFIG_FILE

#define MLKEM_NATIVE_CONFIG_FILE "config_768.h"
#define MLKEM_K 4
#define MLKEM_NATIVE_CONFIG_FILE "multilevel_config.h"
#undef MLKEM_NATIVE_MONOBUILD_KEEP_SHARED_HEADERS
#include "mlkem_native_monobuild.c"
#undef MLKEM_NATIVE_CONFIG_FILE
Expand Down
118 changes: 0 additions & 118 deletions examples/monolithic_build_multilevel/config_1024.h

This file was deleted.

135 changes: 0 additions & 135 deletions examples/monolithic_build_multilevel/config_512.h

This file was deleted.

9 changes: 6 additions & 3 deletions examples/monolithic_build_multilevel/mlkem_native_all.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
#define MLKEM_NATIVE_MULTILEVEL_BUILD_WITH_SHARED
#define MLKEM_NATIVE_MONOBUILD_KEEP_SHARED_HEADERS

#define MLKEM_NATIVE_CONFIG_FILE "config_512.h"
#define MLKEM_K 2
#define MLKEM_NATIVE_CONFIG_FILE "multilevel_config.h"
#include "mlkem_native_monobuild.c"
#undef MLKEM_NATIVE_CONFIG_FILE

/* Exclude level-independent code */
#undef MLKEM_NATIVE_MULTILEVEL_BUILD_WITH_SHARED
#define MLKEM_NATIVE_MULTILEVEL_BUILD_NO_SHARED

#define MLKEM_NATIVE_CONFIG_FILE "config_1024.h"
#define MLKEM_K 3
#define MLKEM_NATIVE_CONFIG_FILE "multilevel_config.h"
#include "mlkem_native_monobuild.c"
#undef MLKEM_NATIVE_CONFIG_FILE

#define MLKEM_NATIVE_CONFIG_FILE "config_768.h"
#define MLKEM_K 4
#define MLKEM_NATIVE_CONFIG_FILE "multilevel_config.h"
#undef MLKEM_NATIVE_MONOBUILD_KEEP_SHARED_HEADERS
#include "mlkem_native_monobuild.c"
#undef MLKEM_NATIVE_CONFIG_FILE

0 comments on commit c12e6fb

Please sign in to comment.