mlkem test diagnostics and allocator updates
This commit is contained in:
@@ -2,17 +2,47 @@ TARGET = mlkem_test
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
CFLAGS += -I./mlkem_native
|
||||
CFLAGS += -DMLK_CONFIG_PARAMETER_SET=512
|
||||
CFLAGS += -DMLK_CONFIG_NAMESPACE_PREFIX=swmlkem
|
||||
CFLAGS += -DMLK_CONFIG_NO_RANDOMIZED_API
|
||||
CFLAGS += -DMLK_CONFIG_NO_ASM
|
||||
CFLAGS += -DMLK_CONFIG_FILE='"sw_mlkem_config.h"'
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
C_SRCS += ./mlkem_native/mlkem_native.c
|
||||
C_SRCS := ./dma.c ./main.c ./sw_mlkem_alloc.c
|
||||
|
||||
MLKEM_NATIVE_CFLAGS = \
|
||||
-DMLK_CONFIG_NO_RANDOMIZED_API \
|
||||
-DMLK_CONFIG_NO_SUPERCOP \
|
||||
-DMLK_CONFIG_NO_ASM \
|
||||
-DMLK_CONFIG_FILE='"sw_mlkem_config.h"'
|
||||
|
||||
MLKEM_NATIVE_OBJS = \
|
||||
obj/mlkem_native_512.o \
|
||||
obj/mlkem_native_768.o \
|
||||
obj/mlkem_native_1024.o
|
||||
|
||||
LINK_OBJS += $(MLKEM_NATIVE_OBJS)
|
||||
CLEAN_OBJS += $(MLKEM_NATIVE_OBJS)
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../bsp
|
||||
GCC_DIR=../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../toolchains/picolibc
|
||||
LA32RSOC_WINDOWS_HOME ?= ../../..
|
||||
include ../../bsp/common.mk
|
||||
|
||||
obj/mlkem_native_512.o: ./mlkem_native/mlkem_native.c
|
||||
mkdir -p obj
|
||||
$(LA32R_GCC) $(CFLAGS) $(INCLUDES) $(MLKEM_NATIVE_CFLAGS) \
|
||||
-DMLK_CONFIG_PARAMETER_SET=512 \
|
||||
-DMLK_CONFIG_NAMESPACE_PREFIX=swmlkem512 \
|
||||
-c -o $@ $<
|
||||
|
||||
obj/mlkem_native_768.o: ./mlkem_native/mlkem_native.c
|
||||
mkdir -p obj
|
||||
$(LA32R_GCC) $(CFLAGS) $(INCLUDES) $(MLKEM_NATIVE_CFLAGS) \
|
||||
-DMLK_CONFIG_PARAMETER_SET=768 \
|
||||
-DMLK_CONFIG_NAMESPACE_PREFIX=swmlkem768 \
|
||||
-c -o $@ $<
|
||||
|
||||
obj/mlkem_native_1024.o: ./mlkem_native/mlkem_native.c
|
||||
mkdir -p obj
|
||||
$(LA32R_GCC) $(CFLAGS) $(INCLUDES) $(MLKEM_NATIVE_CFLAGS) \
|
||||
-DMLK_CONFIG_PARAMETER_SET=1024 \
|
||||
-DMLK_CONFIG_NAMESPACE_PREFIX=swmlkem1024 \
|
||||
-c -o $@ $<
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
40
sdk/software/examples/mlkem_test/sw_mlkem_alloc.c
Normal file
40
sdk/software/examples/mlkem_test/sw_mlkem_alloc.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "sw_mlkem_alloc.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SW_MLKEM_ALLOC_ALIGN 32u
|
||||
#define SW_MLKEM_ALLOC_SIZE (64u * 1024u)
|
||||
|
||||
static uint8_t sw_mlkem_arena[SW_MLKEM_ALLOC_SIZE] __attribute__((aligned(SW_MLKEM_ALLOC_ALIGN)));
|
||||
static size_t sw_mlkem_arena_pos;
|
||||
static unsigned sw_mlkem_arena_active;
|
||||
|
||||
static size_t align_up(size_t n)
|
||||
{
|
||||
return (n + (SW_MLKEM_ALLOC_ALIGN - 1u)) & ~(SW_MLKEM_ALLOC_ALIGN - 1u);
|
||||
}
|
||||
|
||||
void *sw_mlkem_alloc(size_t size)
|
||||
{
|
||||
size_t pos = align_up(sw_mlkem_arena_pos);
|
||||
size_t need = align_up(size);
|
||||
|
||||
if (pos + need > SW_MLKEM_ALLOC_SIZE)
|
||||
return 0;
|
||||
|
||||
sw_mlkem_arena_pos = pos + need;
|
||||
sw_mlkem_arena_active++;
|
||||
return &sw_mlkem_arena[pos];
|
||||
}
|
||||
|
||||
void sw_mlkem_free(void *ptr, size_t size)
|
||||
{
|
||||
(void)ptr;
|
||||
(void)size;
|
||||
|
||||
if (sw_mlkem_arena_active != 0)
|
||||
sw_mlkem_arena_active--;
|
||||
|
||||
if (sw_mlkem_arena_active == 0)
|
||||
sw_mlkem_arena_pos = 0;
|
||||
}
|
||||
9
sdk/software/examples/mlkem_test/sw_mlkem_alloc.h
Normal file
9
sdk/software/examples/mlkem_test/sw_mlkem_alloc.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef SW_MLKEM_ALLOC_H
|
||||
#define SW_MLKEM_ALLOC_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *sw_mlkem_alloc(size_t size);
|
||||
void sw_mlkem_free(void *ptr, size_t size);
|
||||
|
||||
#endif
|
||||
@@ -11,11 +11,19 @@
|
||||
#include "mlkem_native_config.h"
|
||||
|
||||
#define MLK_CONFIG_CUSTOM_ZEROIZE
|
||||
#define MLK_CONFIG_CUSTOM_ALLOC_FREE
|
||||
|
||||
#if !defined(__ASSEMBLER__)
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "src/sys.h"
|
||||
#include "sw_mlkem_alloc.h"
|
||||
|
||||
#define MLK_CUSTOM_ALLOC(v, T, N) \
|
||||
T *(v) = (T *)sw_mlkem_alloc(sizeof(T) * (N))
|
||||
|
||||
#define MLK_CUSTOM_FREE(v, T, N) \
|
||||
sw_mlkem_free((void *)(v), sizeof(T) * (N))
|
||||
|
||||
static MLK_INLINE void mlk_zeroize(void *ptr, size_t len)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user