Skip to content
Merged
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
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,45 @@ jobs:
examples: false
stack: true
check_namespace: false
unit_valgrind:
name: Unit tests + valgrind (${{ matrix.target.name }}, ${{ matrix.cflags }})
strategy:
fail-fast: false
matrix:
external:
- ${{ github.repository_owner != 'pq-code-package' }}
target:
- runner: ubuntu-latest
name: x86_64
- runner: ubuntu-24.04-arm
name: aarch64
cflags: ['-O3', '-Os']
exclude:
- external: true
runs-on: ${{ matrix.target.runner }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Unit tests under valgrind
uses: ./.github/actions/functest
with:
gh_token: ${{ secrets.GITHUB_TOKEN }}
nix-shell: valgrind-varlat_gcc15
nix-cache: false
opt: opt
cflags: "${{ matrix.cflags }} -std=c11 -D_GNU_SOURCE -DMLK_CONFIG_FILE=\\\\\\\"../test/configs/custom_heap_alloc_config.h\\\\\\\""
func: false
kat: false
acvp: false
wycheproof: false
examples: false
stack: false
unit: true
alloc: false
rng_fail: false
check_namespace: false
# Disable AArch64 SHA3 extension: valgrind cannot emulate it
extra_env: "MK_COMPILER_SUPPORTS_SHA3=0"
exec_wrapper: "valgrind --error-exitcode=1"
config_variations:
name: Non-standard configurations
strategy:
Expand Down
23 changes: 19 additions & 4 deletions test/configs/configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,29 @@ configs:
defines:
MLK_CONFIG_CUSTOM_ALLOC_FREE:
content: |
/* In practice, one could just use aligned_alloc here. However, this
* requires aligning up the size to a multiple of the alignment, which
* weakens some of the memory-safety tests we run using this config. */
#define MLK_CONFIG_CUSTOM_ALLOC_FREE
#if !defined(__ASSEMBLER__)
#if defined(_WIN32)
#include <malloc.h>
#define MLK_CUSTOM_ALLOC(v, T, N) \
T *v = (T *)_aligned_malloc(sizeof(T) * (N), MLK_DEFAULT_ALIGN)
#define MLK_CUSTOM_FREE(v, T, N) _aligned_free(v)
#else
#include <stdlib.h>
#define MLK_CUSTOM_ALLOC(v, T, N) \
T* v = (T *)aligned_alloc(MLK_DEFAULT_ALIGN, \
MLK_ALIGN_UP(sizeof(T) * (N)))
static inline void *mlk_posix_memalign(size_t align, size_t sz)
{
void *ptr = NULL;
if (posix_memalign(&ptr, align, sz) != 0)
return NULL;
return ptr;
}
#define MLK_CUSTOM_ALLOC(v, T, N) \
T *v = (T *)mlk_posix_memalign(MLK_DEFAULT_ALIGN, sizeof(T) * (N))
#define MLK_CUSTOM_FREE(v, T, N) free(v)
#endif /* _WIN32 */
#endif /* !__ASSEMBLER__ */

- path: examples/basic_deterministic/mlkem_native/mlkem_native_config.h
Expand Down Expand Up @@ -449,4 +465,3 @@ configs:
#endif /* !__ASSEMBLER__ */
MLK_CONFIG_FILE:
comment: "/* No need to set this -- we _are_ already in a custom config */"

21 changes: 20 additions & 1 deletion test/configs/custom_heap_alloc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,31 @@
* code will handle this case and invoke MLK_CUSTOM_FREE.
*
*****************************************************************************/
/* In practice, one could just use aligned_alloc here. However, this
* requires aligning up the size to a multiple of the alignment, which
* weakens some of the memory-safety tests we run using this config. */
#define MLK_CONFIG_CUSTOM_ALLOC_FREE
#if !defined(__ASSEMBLER__)
#if defined(_WIN32)
#include <malloc.h>
#define MLK_CUSTOM_ALLOC(v, T, N) \
T *v = (T *)_aligned_malloc(sizeof(T) * (N), MLK_DEFAULT_ALIGN)
#define MLK_CUSTOM_FREE(v, T, N) _aligned_free(v)
#else /* _WIN32 */
#include <stdlib.h>
static inline void *mlk_posix_memalign(size_t align, size_t sz)
{
void *ptr = NULL;
if (posix_memalign(&ptr, align, sz) != 0)
{
return NULL;
}
return ptr;
}
#define MLK_CUSTOM_ALLOC(v, T, N) \
T *v = (T *)aligned_alloc(MLK_DEFAULT_ALIGN, MLK_ALIGN_UP(sizeof(T) * (N)))
T *v = (T *)mlk_posix_memalign(MLK_DEFAULT_ALIGN, sizeof(T) * (N))
#define MLK_CUSTOM_FREE(v, T, N) free(v)
#endif /* !_WIN32 */
#endif /* !__ASSEMBLER__ */


Expand Down
18 changes: 12 additions & 6 deletions test/mk/components.mk
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ MLKEM1024_OBJS = $(call MAKE_OBJS,$(MLKEM1024_DIR),$(SOURCES) $(FIPS202_SRCS))
$(MLKEM1024_OBJS): CFLAGS += -DMLK_CONFIG_PARAMETER_SET=1024

# Unit test object files - same sources but with MLK_STATIC_TESTABLE=
UNIT_CFLAGS = -DMLK_STATIC_TESTABLE= -Wno-missing-prototypes

MLKEM512_UNIT_OBJS = $(call MAKE_OBJS,$(MLKEM512_DIR)/unit,$(SOURCES) $(FIPS202_SRCS))
$(MLKEM512_UNIT_OBJS): CFLAGS += -DMLK_CONFIG_PARAMETER_SET=512 -DMLK_STATIC_TESTABLE= -Wno-missing-prototypes
$(MLKEM512_UNIT_OBJS): CFLAGS += -DMLK_CONFIG_PARAMETER_SET=512 $(UNIT_CFLAGS)
MLKEM768_UNIT_OBJS = $(call MAKE_OBJS,$(MLKEM768_DIR)/unit,$(SOURCES) $(FIPS202_SRCS))
$(MLKEM768_UNIT_OBJS): CFLAGS += -DMLK_CONFIG_PARAMETER_SET=768 -DMLK_STATIC_TESTABLE= -Wno-missing-prototypes
$(MLKEM768_UNIT_OBJS): CFLAGS += -DMLK_CONFIG_PARAMETER_SET=768 $(UNIT_CFLAGS)
MLKEM1024_UNIT_OBJS = $(call MAKE_OBJS,$(MLKEM1024_DIR)/unit,$(SOURCES) $(FIPS202_SRCS))
$(MLKEM1024_UNIT_OBJS): CFLAGS += -DMLK_CONFIG_PARAMETER_SET=1024 -DMLK_STATIC_TESTABLE= -Wno-missing-prototypes
$(MLKEM1024_UNIT_OBJS): CFLAGS += -DMLK_CONFIG_PARAMETER_SET=1024 $(UNIT_CFLAGS)

# Alloc test object files - same sources but with custom alloc config
MLKEM512_ALLOC_OBJS = $(call MAKE_OBJS,$(MLKEM512_DIR)/alloc,$(SOURCES) $(FIPS202_SRCS))
Expand Down Expand Up @@ -81,9 +83,13 @@ $(MLKEM512_DIR)/test/src/test_alloc.c.o: CFLAGS += -DMLK_CONFIG_FILE=\"../test/c
$(MLKEM768_DIR)/test/src/test_alloc.c.o: CFLAGS += -DMLK_CONFIG_FILE=\"../test/configs/test_alloc_config.h\"
$(MLKEM1024_DIR)/test/src/test_alloc.c.o: CFLAGS += -DMLK_CONFIG_FILE=\"../test/configs/test_alloc_config.h\"

$(MLKEM512_DIR)/bin/test_unit512: CFLAGS += -DMLK_STATIC_TESTABLE= -Wno-missing-prototypes
$(MLKEM768_DIR)/bin/test_unit768: CFLAGS += -DMLK_STATIC_TESTABLE= -Wno-missing-prototypes
$(MLKEM1024_DIR)/bin/test_unit1024: CFLAGS += -DMLK_STATIC_TESTABLE= -Wno-missing-prototypes
$(MLKEM512_DIR)/test/src/test_unit.c.o: CFLAGS += $(UNIT_CFLAGS)
$(MLKEM768_DIR)/test/src/test_unit.c.o: CFLAGS += $(UNIT_CFLAGS)
$(MLKEM1024_DIR)/test/src/test_unit.c.o: CFLAGS += $(UNIT_CFLAGS)

$(MLKEM512_DIR)/bin/test_unit512: CFLAGS += $(UNIT_CFLAGS)
$(MLKEM768_DIR)/bin/test_unit768: CFLAGS += $(UNIT_CFLAGS)
$(MLKEM1024_DIR)/bin/test_unit1024: CFLAGS += $(UNIT_CFLAGS)

# Unit library object files compiled with MLK_STATIC_TESTABLE=
$(MLKEM512_DIR)/unit_%: CFLAGS += -DMLK_STATIC_TESTABLE= -Wno-missing-prototypes
Expand Down
Loading
Loading