################################################################################
# KEM implementation: Kyber

ccflags-$(CONFIG_LEANCRYPTO_KEM_KYBER) += -I$(src)/../ml-kem/src
################################################################################
# C Implementation
################################################################################
# Kyber Common
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= ../ml-kem/src/kyber_api.o		       \
				   ../ml-kem/src/kyber_cbd.o		       \
				   ../ml-kem/src/kyber_zetas.o

# Kyber 1024
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_1024)				       \
				+= ../ml-kem/src/kyber_ies.o		       \
				   ../ml-kem/src/kyber_indcpa.o		       \
				   ../ml-kem/src/kyber_kem.o		       \
				   ../ml-kem/src/kyber_kem_c.o		       \
				   ../ml-kem/src/kyber_kex.o		       \
				   ../ml-kem/src/kyber_poly.o		       \
				   ../ml-kem/src/kyber_polyvec.o	       \
				   ../ml-kem/src/kyber_selftest.o	       \
				   ../ml-kem/src/kyber_selftest_kdf.o	       \
				   leancrypto_kernel_kyber.o

# Kyber 768
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_768)				       \
				+= kyber768/kyber_ies.o			       \
				   kyber768/kyber_indcpa.o		       \
				   kyber768/kyber_kem.o			       \
				   kyber768/kyber_kem_c.o		       \
				   kyber768/kyber_kex.o			       \
				   kyber768/kyber_poly.o		       \
				   kyber768/kyber_polyvec.o		       \
				   kyber768/kyber_selftest.o		       \
				   kyber768/kyber_selftest_kdf.o	       \
				   kyber768/leancrypto_kernel_kyber.o

CFLAGS_kyber768/kyber_ies.o			:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/kyber_indcpa.o			:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/kyber_kem.o			:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/kyber_kem_c.o			:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/kyber_kex.o			:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/kyber_poly.o			:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/kyber_polyvec.o			:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/kyber_selftest.o		:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/kyber_selftest_kdf.o		:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/leancrypto_kernel_kyber.o	:= -DLC_KYBER_TYPE_768

# Kyber 512
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_512)				       \
				+= kyber512/kyber_ies.o			       \
				   kyber512/kyber_indcpa.o		       \
				   kyber512/kyber_kem.o			       \
				   kyber512/kyber_kem_c.o		       \
				   kyber512/kyber_kex.o			       \
				   kyber512/kyber_poly.o		       \
				   kyber512/kyber_polyvec.o		       \
				   kyber512/kyber_selftest.o		       \
				   kyber512/kyber_selftest_kdf.o	       \
				   kyber512/leancrypto_kernel_kyber.o

CFLAGS_kyber512/kyber_ies.o			:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/kyber_indcpa.o			:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/kyber_kem.o			:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/kyber_kem_c.o			:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/kyber_kex.o			:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/kyber_poly.o			:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/kyber_polyvec.o			:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/kyber_selftest.o		:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/kyber_selftest_kdf.o		:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/leancrypto_kernel_kyber.o	:= -DLC_KYBER_TYPE_512

ifndef CONFIG_ARM
ifeq ($(and $(CONFIG_RISCV),$(CONFIG_64BIT)),)
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= ../ml-kem/src/kyber_ntt.o
endif
endif

ifeq ($(and $(CONFIG_RISCV),$(CONFIG_64BIT)),)
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= kyber512/kyber_kem_api_c.o
CFLAGS_kyber512/kyber_kem_api_c.o		:= -DLC_KYBER_TYPE_512
endif

################################################################################
# Hybrid Implementation
################################################################################
# Kyber 1024 KEM-X25519 implementation
ifdef CONFIG_LEANCRYPTO_KEM_KYBER_1024
leancrypto-$(CONFIG_LEANCRYPTO_KEM_X25519)				       \
				+= ../ml-kem/src/kyber_x25519_ies.o	       \
				   ../ml-kem/src/kyber_x25519_kem.o	       \
				   ../ml-kem/src/kyber_x25519_kex.o	       \
				   leancrypto_kernel_kyber_x25519.o
endif

# Kyber 768 KEM-X25519 implementation
ifdef CONFIG_LEANCRYPTO_KEM_KYBER_768
leancrypto-$(CONFIG_LEANCRYPTO_KEM_X25519)				       \
				+= kyber768/kyber_x25519_ies.o		       \
				   kyber768/kyber_x25519_kem.o		       \
				   kyber768/kyber_x25519_kex.o		       \
				   kyber768/leancrypto_kernel_kyber_x25519.o
CFLAGS_kyber768/kyber_x25519_ies.o		:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/kyber_x25519_kem.o		:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/kyber_x25519_kex.o		:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/leancrypto_kernel_kyber_x25519.o:= -DLC_KYBER_TYPE_768
endif

# Kyber 512 KEM-X25519 implementation
ifdef CONFIG_LEANCRYPTO_KEM_KYBER_512
leancrypto-$(CONFIG_LEANCRYPTO_KEM_X25519)				       \
				+= kyber512/kyber_x25519_ies.o		       \
				   kyber512/kyber_x25519_kem.o		       \
				   kyber512/kyber_x25519_kex.o		       \
				   kyber512/leancrypto_kernel_kyber_x25519.o
CFLAGS_kyber512/kyber_x25519_ies.o		:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/kyber_x25519_kem.o		:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/kyber_x25519_kex.o		:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/leancrypto_kernel_kyber_x25519.o:= -DLC_KYBER_TYPE_512
endif

# Kyber 1024 KEM-X448 implementation
ifdef CONFIG_LEANCRYPTO_KEM_KYBER_1024
leancrypto-$(CONFIG_LEANCRYPTO_KEM_X448)				       \
				+= ../ml-kem/src/kyber_x448_ies.o	       \
				   ../ml-kem/src/kyber_x448_kem.o	       \
				   ../ml-kem/src/kyber_x448_kex.o	       \
				   leancrypto_kernel_kyber_x448.o
endif

# Kyber 768 KEM-X448 implementation
ifdef CONFIG_LEANCRYPTO_KEM_KYBER_768
leancrypto-$(CONFIG_LEANCRYPTO_KEM_X448)				       \
				+= kyber768/kyber_x448_ies.o		       \
				   kyber768/kyber_x448_kem.o		       \
				   kyber768/kyber_x448_kex.o		       \
				   kyber768/leancrypto_kernel_kyber_x448.o
CFLAGS_kyber768/kyber_x448_ies.o		:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/kyber_x448_kem.o		:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/kyber_x448_kex.o		:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/leancrypto_kernel_kyber_x448.o:= -DLC_KYBER_TYPE_768
endif

# Kyber 512 KEM-X448 implementation
ifdef CONFIG_LEANCRYPTO_KEM_KYBER_512
leancrypto-$(CONFIG_LEANCRYPTO_KEM_X448)				       \
				+= kyber512/kyber_x448_ies.o		       \
				   kyber512/kyber_x448_kem.o		       \
				   kyber512/kyber_x448_kex.o		       \
				   kyber512/leancrypto_kernel_kyber_x448.o
CFLAGS_kyber512/kyber_x448_ies.o		:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/kyber_x448_kem.o		:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/kyber_x448_kex.o		:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/leancrypto_kernel_kyber_x448.o:= -DLC_KYBER_TYPE_512
endif

################################################################################
# AVX2 Implementation
################################################################################
ifdef CONFIG_X86_64
# Kyber Common
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= ../ml-kem/src/avx2/kyber_cbd_avx2.o	       \
				   ../ml-kem/src/avx2/kyber_consts_avx2.o

# Kyber 1024
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_1024)				       \
				+= ../ml-kem/src/avx2/kyber_basemul_avx2.o     \
				   ../ml-kem/src/avx2/kyber_fq_avx2.o	       \
				   ../ml-kem/src/avx2/kyber_indcpa_avx2.o      \
				   ../ml-kem/src/avx2/kyber_invntt_avx2.o      \
				   ../ml-kem/src/avx2/kyber_kem_api_avx2.o     \
				   ../ml-kem/src/avx2/kyber_kem_avx2.o	       \
				   ../ml-kem/src/avx2/kyber_ntt_avx2.o	       \
				   ../ml-kem/src/avx2/kyber_poly_avx2.o	       \
				   ../ml-kem/src/avx2/kyber_rejsample_avx2.o   \
				   ../ml-kem/src/avx2/kyber_shuffle_avx2.o

# Kyber 768
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_768)				       \
				+= kyber768/avx2/kyber_basemul_avx2.o	       \
				   kyber768/avx2/kyber_fq_avx2.o	       \
				   kyber768/avx2/kyber_indcpa_avx2.o	       \
				   kyber768/avx2/kyber_invntt_avx2.o	       \
				   kyber768/avx2/kyber_kem_api_avx2.o	       \
				   kyber768/avx2/kyber_kem_avx2.o	       \
				   kyber768/avx2/kyber_ntt_avx2.o	       \
				   kyber768/avx2/kyber_poly_avx2.o	       \
				   kyber768/avx2/kyber_rejsample_avx2.o	       \
				   kyber768/avx2/kyber_shuffle_avx2.o
AFLAGS_kyber768/avx2/kyber_basemul_avx2.o	:= -DLC_KYBER_TYPE_768
AFLAGS_kyber768/avx2/kyber_fq_avx2.o		:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/avx2/kyber_indcpa_avx2.o	:= -DLC_KYBER_TYPE_768
AFLAGS_kyber768/avx2/kyber_invntt_avx2.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/avx2/kyber_kem_api_avx2.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/avx2/kyber_kem_avx2.o		:= -DLC_KYBER_TYPE_768
AFLAGS_kyber768/avx2/kyber_ntt_avx2.o		:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/avx2/kyber_poly_avx2.o		:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/avx2/kyber_rejsample_avx2.o	:= -DLC_KYBER_TYPE_768
AFLAGS_kyber768/avx2/kyber_shuffle_avx2.o	:= -DLC_KYBER_TYPE_768


################################################################################
# ARMv7 Implementation
################################################################################
else ifdef CONFIG_ARM
asflags-$(CONFIG_LEANCRYPTO_KEM_KYBER)					       \
				+= -I$(src)/../ml-kem/src/armv7

# Kyber Common
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= ../ml-kem/src/armv7/kyber_consts_armv7.o    \
				   ../ml-kem/src/armv7/kyber_fastinvntt_armv7.o\
				   ../ml-kem/src/armv7/kyber_fastntt_armv7.o   \
				   ../ml-kem/src/armv7/kyber_ntt_armv7.o

# Kyber 1024
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_1024)				       \
				+= ../ml-kem/src/kyber_kem_api_c.o	       \
				   ../ml-kem/src/armv7/kyber_poly_armv7.o

# Kyber 768
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_768)				       \
				+= kyber768/kyber_kem_api_c.o		       \
				   kyber768/armv7/kyber_poly_armv7.o
CFLAGS_kyber768/kyber_kem_api_c.o		:= -DLC_KYBER_TYPE_768
AFLAGS_kyber768/armv7/kyber_poly_armv7.o	:= -DLC_KYBER_TYPE_768

# Kyber 512 - kyber_kem_api_c.c is already compiled as part of C
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_512)				       \
				+= kyber512/armv7/kyber_poly_armv7.o
AFLAGS_kyber512/armv7/kyber_poly_armv7.o	:= -DLC_KYBER_TYPE_512


################################################################################
# ARMv8 Implementation
################################################################################
else ifdef CONFIG_ARM64
asflags-$(CONFIG_LEANCRYPTO_KEM_KYBER)					       \
				+= -I$(src)/../ml-kem/src/armv8

# Kyber Common
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= ../ml-kem/src/armv8/kyber_ntt_armv8.o

# Kyber 1024
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_1024)				       \
				+= ../ml-kem/src/armv8/kyber_add_armv8.o       \
				   ../ml-kem/src/armv8/kyber_basemul_armv8.o   \
				   ../ml-kem/src/armv8/kyber_cbd_armv8.o       \
				   ../ml-kem/src/armv8/kyber_indcpa_armv8.o    \
				   ../ml-kem/src/armv8/kyber_inv_ntt_armv8.o   \
				   ../ml-kem/src/armv8/kyber_kem_api_armv8.o   \
				   ../ml-kem/src/armv8/kyber_kem_armv8.o       \
				   ../ml-kem/src/armv8/kyber_ntt_armv8_asm.o   \
				   ../ml-kem/src/armv8/kyber_poly_armv8_asm.o  \
				   ../ml-kem/src/armv8/kyber_reduce_armv8.o

# Kyber 768
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_768)				       \
				+= kyber768/armv8/kyber_add_armv8.o	       \
				   kyber768/armv8/kyber_basemul_armv8.o	       \
				   kyber768/armv8/kyber_cbd_armv8.o	       \
				   kyber768/armv8/kyber_indcpa_armv8.o	       \
				   kyber768/armv8/kyber_inv_ntt_armv8.o	       \
				   kyber768/armv8/kyber_kem_api_armv8.o	       \
				   kyber768/armv8/kyber_kem_armv8.o	       \
				   kyber768/armv8/kyber_ntt_armv8_asm.o	       \
				   kyber768/armv8/kyber_poly_armv8_asm.o       \
				   kyber768/armv8/kyber_reduce_armv8.o
AFLAGS_kyber768/armv8/kyber_add_armv8.o		:= -DLC_KYBER_TYPE_768
AFLAGS_kyber768/armv8/kyber_basemul_armv8.o	:= -DLC_KYBER_TYPE_768
AFLAGS_kyber768/armv8/kyber_cbd_armv8.o		:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/armv8/kyber_indcpa_armv8.o	:= -DLC_KYBER_TYPE_768
AFLAGS_kyber768/armv8/kyber_inv_ntt_armv8.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/armv8/kyber_kem_api_armv8.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/armv8/kyber_kem_armv8.o		:= -DLC_KYBER_TYPE_768
AFLAGS_kyber768/armv8/kyber_ntt_armv8_asm.o	:= -DLC_KYBER_TYPE_768
AFLAGS_kyber768/armv8/kyber_poly_armv8_asm.o	:= -DLC_KYBER_TYPE_768
AFLAGS_kyber768/armv8/kyber_reduce_armv8.o	:= -DLC_KYBER_TYPE_768


################################################################################
# RISCV64 assembler and RVV implementations
################################################################################
else ifneq ($(and $(CONFIG_RISCV),$(CONFIG_64BIT)),)
asflags-$(CONFIG_LEANCRYPTO_KEM_KYBER)					       \
				+= -I$(src)/../ml-kem/src/riscv64
ccflags-$(CONFIG_LEANCRYPTO_KEM_KYBER)					       \
				+= -DLC_KYBER_RISCV_RVV_VLEN128		       \
				   -DLC_KYBER_RISCV_RVV_VLEN256

#--- RISCV64 assembler ---------------------------------------------------------
# Kyber Common
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= ../ml-kem/src/riscv64/kyber_zetas_riscv.o   \
				   ../ml-kem/src/riscv64/ntt_dualissue_plant_rv64im.o

# Kyber 1024
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_1024)				       \
				+= ../ml-kem/src/riscv64/kyber_kem_api_riscv.o

# Kyber 768
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_768)				       \
				+= kyber768/riscv64_rvv/kyber_kem_api_riscv.o
CFLAGS_kyber768/riscv64_rvv/kyber_kem_api_riscv.o	:= -DLC_KYBER_TYPE_768

leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_512)				       \
				+= kyber512/riscv64_rvv/kyber_kem_api_riscv.o
CFLAGS_kyber512/riscv64_rvv/kyber_kem_api_riscv.o	:= -DLC_KYBER_TYPE_512

#--- RISCV64 RVV Common --------------------------------------------------------
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= ../ml-kem/src/riscv64/kyber_rvv_vlen_selector.o\
				   ../ml-kem/src/riscv64/ntt_rvv_vlen128.o     \
				   ../ml-kem/src/riscv64/ntt_rvv_vlen256.o     \
				   ../ml-kem/src/riscv64/riscv_rvv_selector_test.o\
				   ../ml-kem/src/riscv64/kyber_consts_rvv_vlen128.o\
				   ../ml-kem/src/riscv64/kyber_consts_rvv_vlen256.o
CFLAGS_../ml-kem/src/riscv64/kyber_rvv_vlen_selector.o :=		       \
	-march=rv64imadcv -mcmodel=medany
AFLAGS_../ml-kem/src/riscv64/ntt_rvv_vlen128.o :=			       \
	-march=rv64imadcv -mcmodel=medany
AFLAGS_../ml-kem/src/riscv64/ntt_rvv_vlen256.o :=			       \
	-march=rv64imadcv -mcmodel=medany
AFLAGS_../ml-kem/src/riscv64/riscv_rvv_selector_test.o :=		       \
	-march=rv64imadcv -mcmodel=medany
CFLAGS_../ml-kem/src/riscv64/kyber_consts_rvv_vlen128.o :=		       \
	-march=rv64imadcv -mcmodel=medany
CFLAGS_../ml-kem/src/riscv64/kyber_consts_rvv_vlen256.o :=		       \
	-march=rv64imadcv -mcmodel=medany

#--- RISCV64 RVV VLEN128 -------------------------------------------------------
# Kyber 1024
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= ../ml-kem/src/riscv64/kyber_indcpa_rvv_vlen128.o\
				   ../ml-kem/src/riscv64/kyber_kem_rvv_vlen128.o
CFLAGS_../ml-kem/src/riscv64/kyber_indcpa_rvv_vlen128.o :=		       \
	-march=rv64imadcv -mcmodel=medany
CFLAGS_../ml-kem/src/riscv64/kyber_kem_rvv_vlen128.o :=			       \
	-march=rv64imadcv -mcmodel=medany

# Kyber 768
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= kyber768/riscv64_rvv/kyber_indcpa_rvv_vlen128.o\
				   kyber768/riscv64_rvv/kyber_kem_rvv_vlen128.o
CFLAGS_kyber768/riscv64_rvv/kyber_indcpa_rvv_vlen128.o :=		       \
	-march=rv64imadcv -mcmodel=medany -DLC_KYBER_TYPE_768
CFLAGS_kyber768/riscv64_rvv/kyber_kem_rvv_vlen128.o :=			       \
	-march=rv64imadcv -mcmodel=medany -DLC_KYBER_TYPE_768

# Kyber 512
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= kyber512/riscv64_rvv/kyber_indcpa_rvv_vlen128.o\
				   kyber512/riscv64_rvv/kyber_kem_rvv_vlen128.o
CFLAGS_kyber512/riscv64_rvv/kyber_indcpa_rvv_vlen128.o :=		       \
	-march=rv64imadcv -mcmodel=medany -DLC_KYBER_TYPE_512
CFLAGS_kyber512/riscv64_rvv/kyber_kem_rvv_vlen128.o :=			       \
	-march=rv64imadcv -mcmodel=medany -DLC_KYBER_TYPE_512

#--- RISCV64 RVV VLEN256 -------------------------------------------------------
# Kyber 1024
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= ../ml-kem/src/riscv64/kyber_indcpa_rvv_vlen256.o\
				   ../ml-kem/src/riscv64/kyber_kem_rvv_vlen256.o
CFLAGS_../ml-kem/src/riscv64/kyber_indcpa_rvv_vlen256.o :=		       \
	-march=rv64imadcv -mcmodel=medany
CFLAGS_../ml-kem/src/riscv64/kyber_kem_rvv_vlen256.o :=			       \
	-march=rv64imadcv -mcmodel=medany

# Kyber 768
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= kyber768/riscv64_rvv/kyber_indcpa_rvv_vlen256.o\
				   kyber768/riscv64_rvv/kyber_kem_rvv_vlen256.o
CFLAGS_kyber768/riscv64_rvv/kyber_indcpa_rvv_vlen256.o :=		       \
	-march=rv64imadcv -mcmodel=medany -DLC_KYBER_TYPE_768
CFLAGS_kyber768/riscv64_rvv/kyber_kem_rvv_vlen256.o :=			       \
	-march=rv64imadcv -mcmodel=medany -DLC_KYBER_TYPE_768

# Kyber 512
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER)				       \
				+= kyber512/riscv64_rvv/kyber_indcpa_rvv_vlen256.o\
				   kyber512/riscv64_rvv/kyber_kem_rvv_vlen256.o
CFLAGS_kyber512/riscv64_rvv/kyber_indcpa_rvv_vlen256.o :=		       \
	-march=rv64imadcv -mcmodel=medany -DLC_KYBER_TYPE_512
CFLAGS_kyber512/riscv64_rvv/kyber_kem_rvv_vlen256.o :=			       \
	-march=rv64imadcv -mcmodel=medany -DLC_KYBER_TYPE_512

################################################################################
# Interfaces for any non-accelerated implementation
################################################################################
else
# Kyber 1024
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_1024)				       \
				+= ../ml-kem/src/kyber_kem_api_c.o

# Kyber 768
leancrypto-$(CONFIG_LEANCRYPTO_KEM_KYBER_768)				       \
				+= kyber768/kyber_kem_api_c.o
CFLAGS_kyber768/kyber_kem_api_c.o		:= -DLC_KYBER_TYPE_768

# Kyber 512 is already covered by the C implementation definition
endif


################################################################################
# Testing Code
################################################################################
ifdef CONFIG_LEANCRYPTO_KEM_KYBER
ccflags-y			+= -DCONFIG_LEANCRYPTO_KEM

# Kyber 1024
ifdef CONFIG_LEANCRYPTO_KEM_KYBER_1024
ccflags-y				+= -DCONFIG_LEANCRYPTO_KEM_KYBER_1024
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_kyber_1024_tester.o
leancrypto_kernel_kyber_1024_tester-y	+= ../ml-kem/tests/leancrypto_kernel_kyber_1024_tester.o
ifdef CONFIG_LEANCRYPTO_KEM_X25519
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_kyber_1024_x25519_tester.o
leancrypto_kernel_kyber_1024_x25519_tester-y += ../ml-kem/tests/leancrypto_kernel_kyber_1024_x25519_tester.o
endif
ifdef CONFIG_LEANCRYPTO_KEM_X448
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_kyber_1024_x448_tester.o
leancrypto_kernel_kyber_1024_x448_tester-y += ../ml-kem/tests/leancrypto_kernel_kyber_1024_x448_tester.o
endif

obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_kem_tester_c.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_kem_tester_common.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_kem_kdf_tester_c.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_kem_kdf_tester_common.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_kex_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_ies_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_invalid_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_modulus_tester.o

kyber_kem_tester_c-y		+= ../ml-kem/tests/kyber_kem_tester.o	       \
				   ../ml-kem/tests/kyber_kem_tester_c.o	       \
				   ../drng/src/selftest_rng.o
kyber_kem_kdf_tester_c-y	+= ../ml-kem/tests/kyber_kem_tester.o	       \
				   ../ml-kem/tests/kyber_kem_kdf_tester_c.o    \
				   ../drng/src/selftest_rng.o
kyber_kem_tester_common-y	+= ../ml-kem/tests/kyber_kem_tester.o	       \
				   ../ml-kem/tests/kyber_kem_tester_common.o   \
				   ../drng/src/selftest_rng.o
kyber_kem_kdf_tester_common-y	+= ../ml-kem/tests/kyber_kem_tester.o	       \
				   ../ml-kem/tests/kyber_kem_kdf_tester_common.o\
				   ../drng/src/selftest_rng.o
kyber_kex_tester-y  		+= ../ml-kem/tests/kyber_kex_tester.o
kyber_ies_tester-y  		+= ../ml-kem/tests/kyber_ies_tester.o	       \
				   ../drng/src/selftest_rng.o
kyber_invalid_tester-y  	+= ../ml-kem/tests/kyber_invalid_tester.o
kyber_modulus_tester-y  	+= ../ml-kem/tests/kyber_modulus_tester.o
endif

# Kyber 768
ifdef CONFIG_LEANCRYPTO_KEM_KYBER_768
ccflags-y				+= -DCONFIG_LEANCRYPTO_KEM_KYBER_768
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_kyber_768_tester.o
leancrypto_kernel_kyber_768_tester-y	+= kyber768/tests/leancrypto_kernel_kyber_768_tester.o
ifdef CONFIG_LEANCRYPTO_KEM_X25519
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_kyber_768_x25519_tester.o
leancrypto_kernel_kyber_768_x25519_tester-y += kyber768/tests/leancrypto_kernel_kyber_768_x25519_tester.o
endif
ifdef CONFIG_LEANCRYPTO_KEM_X448
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_kyber_768_x448_tester.o
leancrypto_kernel_kyber_768_x448_tester-y += kyber768/tests/leancrypto_kernel_kyber_768_x448_tester.o
endif

obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_768_kem_tester_c.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_768_kem_tester_common.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_768_kem_kdf_tester_c.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_768_kem_kdf_tester_common.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_768_kex_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_768_ies_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_768_invalid_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_768_modulus_tester.o

kyber_768_kem_tester_c-y	+= kyber768/tests/kyber_kem_tester.o	       \
				   kyber768/tests/kyber_kem_tester_c.o	       \
				   ../drng/src/selftest_rng.o
kyber_768_kem_kdf_tester_c-y	+= kyber768/tests/kyber_kem_tester.o	       \
				   kyber768/tests/kyber_kem_kdf_tester_c.o     \
				   ../drng/src/selftest_rng.o
kyber_768_kem_tester_common-y	+= kyber768/tests/kyber_kem_tester.o	       \
				   kyber768/tests/kyber_kem_tester_common.o    \
				   ../drng/src/selftest_rng.o
kyber_768_kem_kdf_tester_common-y+= kyber768/tests/kyber_kem_tester.o	       \
				   kyber768/tests/kyber_kem_kdf_tester_common.o\
				   ../drng/src/selftest_rng.o
kyber_768_kex_tester-y 		+= kyber768/tests/kyber_kex_tester.o
kyber_768_ies_tester-y  	+= kyber768/tests/kyber_ies_tester.o	       \
				   ../drng/src/selftest_rng.o
kyber_768_invalid_tester-y  	+= kyber768/tests/kyber_invalid_tester.o
kyber_768_modulus_tester-y  	+= kyber768/tests/kyber_modulus_tester.o

CFLAGS_leancrypto_kernel_kyber_768_tester.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/tests/kyber_kem_tester.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/tests/kyber_kem_tester_c.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/tests/kyber_kem_kdf_tester_c.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/tests/kyber_kem_tester_common.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/tests/kyber_kem_kdf_tester_common.o:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/tests/kyber_kex_tester.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/tests/kyber_ies_tester.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/tests/kyber_invalid_tester.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/tests/kyber_modulus_tester.o	:= -DLC_KYBER_TYPE_768

endif

# Kyber 512
ifdef CONFIG_LEANCRYPTO_KEM_KYBER_512
ccflags-y				+= -DCONFIG_LEANCRYPTO_KEM_KYBER_512
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_kyber_512_tester.o
leancrypto_kernel_kyber_512_tester-y	+= kyber512/tests/leancrypto_kernel_kyber_512_tester.o
ifdef CONFIG_LEANCRYPTO_KEM_X25519
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_kyber_512_x25519_tester.o
leancrypto_kernel_kyber_512_x25519_tester-y += kyber512/tests/leancrypto_kernel_kyber_512_x25519_tester.o
endif
ifdef CONFIG_LEANCRYPTO_KEM_X448
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_kyber_512_x448_tester.o
leancrypto_kernel_kyber_512_x448_tester-y += kyber512/tests/leancrypto_kernel_kyber_512_x448_tester.o
endif

obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_512_kem_tester_c.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_512_kem_tester_common.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_512_kem_kdf_tester_c.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_512_kem_kdf_tester_common.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_512_kex_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_512_ies_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_512_invalid_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_512_modulus_tester.o

kyber_512_kem_tester_c-y	+= kyber512/tests/kyber_kem_tester.o	       \
				   kyber512/tests/kyber_kem_tester_c.o	       \
				   ../drng/src/selftest_rng.o
kyber_512_kem_kdf_tester_c-y	+= kyber512/tests/kyber_kem_tester.o	       \
				   kyber512/tests/kyber_kem_kdf_tester_c.o     \
				   ../drng/src/selftest_rng.o
kyber_512_kem_tester_common-y	+= kyber512/tests/kyber_kem_tester.o	       \
				   kyber512/tests/kyber_kem_tester_common.o    \
				   ../drng/src/selftest_rng.o
kyber_512_kem_kdf_tester_common-y+= kyber512/tests/kyber_kem_tester.o	       \
				   kyber512/tests/kyber_kem_kdf_tester_common.o\
				   ../drng/src/selftest_rng.o
kyber_512_kex_tester-y 		+= kyber512/tests/kyber_kex_tester.o
kyber_512_ies_tester-y  	+= kyber512/tests/kyber_ies_tester.o	       \
				   ../drng/src/selftest_rng.o
kyber_512_invalid_tester-y  	+= kyber512/tests/kyber_invalid_tester.o
kyber_512_modulus_tester-y  	+= kyber512/tests/kyber_modulus_tester.o

CFLAGS_leancrypto_kernel_kyber_512_tester.o	:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/tests/kyber_kem_tester.o	:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/tests/kyber_kem_tester_c.o	:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/tests/kyber_kem_kdf_tester_c.o	:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/tests/kyber_kem_tester_common.o	:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/tests/kyber_kem_kdf_tester_common.o:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/tests/kyber_kex_tester.o	:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/tests/kyber_ies_tester.o	:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/tests/kyber_invalid_tester.o	:= -DLC_KYBER_TYPE_512
CFLAGS_kyber512/tests/kyber_modulus_tester.o	:= -DLC_KYBER_TYPE_512
endif

endif

ifdef CONFIG_LEANCRYPTO_KEM_X25519
ccflags-y			+= -DCONFIG_LEANCRYPTO_KEM_X25519

ifdef CONFIG_LEANCRYPTO_KEM_KYBER_1024
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_ies_x25519_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_kem_x25519_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_kex_x25519_tester.o

kyber_ies_x25519_tester-y	+= ../ml-kem/tests/kyber_ies_x25519_tester.o   \
				   ../drng/src/selftest_rng.o
kyber_kem_x25519_tester-y	+= ../ml-kem/tests/kyber_kem_x25519_tester.o   \
				   ../drng/src/selftest_rng.o
kyber_kex_x25519_tester-y	+= ../ml-kem/tests/kyber_kex_x25519_tester.o   \
				   ../drng/src/selftest_rng.o
endif
endif

ifdef CONFIG_LEANCRYPTO_KEM_X448
ccflags-y				+= -DCONFIG_LEANCRYPTO_KEM_X448

ifdef CONFIG_LEANCRYPTO_KEM_KYBER_1024
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_ies_x448_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_kem_x448_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_kex_x448_tester.o

kyber_ies_x448_tester-y	+= ../ml-kem/tests/kyber_ies_x448_tester.o   \
				   ../drng/src/selftest_rng.o
kyber_kem_x448_tester-y	+= ../ml-kem/tests/kyber_kem_x448_tester.o   \
				   ../drng/src/selftest_rng.o
kyber_kex_x448_tester-y	+= ../ml-kem/tests/kyber_kex_x448_tester.o   \
				   ../drng/src/selftest_rng.o
endif
endif

ifdef CONFIG_X86_64
ifdef CONFIG_LEANCRYPTO_KEM_KYBER_1024
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_kem_tester_avx2.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_kem_kdf_tester_avx2.o

kyber_kem_tester_avx2-y		+= ../ml-kem/tests/kyber_kem_tester.o	       \
				   ../ml-kem/tests/kyber_kem_tester_avx2.o     \
				   ../drng/src/selftest_rng.o
kyber_kem_kdf_tester_avx2-y	+= ../ml-kem/tests/kyber_kem_tester.o	       \
				   ../ml-kem/tests/kyber_kem_kdf_tester_avx2.o \
				   ../drng/src/selftest_rng.o
endif

ifdef CONFIG_LEANCRYPTO_KEM_KYBER_768
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_768_kem_tester_avx2.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_768_kem_kdf_tester_avx2.o

kyber_768_kem_tester_avx2-y	+= kyber768/tests/kyber_kem_tester.o	       \
				   kyber768/tests/kyber_kem_tester_avx2.o      \
				   ../drng/src/selftest_rng.o
kyber_768_kem_kdf_tester_avx2-y	+= kyber768/tests/kyber_kem_tester.o	       \
				   kyber768/tests/kyber_kem_kdf_tester_avx2.o  \
				   ../drng/src/selftest_rng.o

CFLAGS_kyber768/tests/kyber_kem_tester.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/tests/kyber_kem_tester_avx2.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/tests/kyber_kem_kdf_tester_avx2.o:= -DLC_KYBER_TYPE_768

endif

else ifdef CONFIG_ARM64
ifdef CONFIG_LEANCRYPTO_KEM_KYBER_1024
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_kem_tester_armv8.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_kem_kdf_tester_armv8.o

kyber_kem_tester_armv8-y	+= ../ml-kem/tests/kyber_kem_tester.o	       \
				   ../ml-kem/tests/kyber_kem_tester_armv8.o    \
				   ../drng/src/selftest_rng.o
kyber_kem_kdf_tester_armv8-y	+= ../ml-kem/tests/kyber_kem_tester.o	       \
				   ../ml-kem/tests/kyber_kem_kdf_tester_armv8.o\
				   ../drng/src/selftest_rng.o
endif

ifdef CONFIG_LEANCRYPTO_KEM_KYBER_768
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_768_kem_tester_armv8.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= kyber_768_kem_kdf_tester_armv8.o

kyber_768_kem_tester_armv8-y	+= kyber768/tests/kyber_kem_tester.o	       \
				   kyber768/tests/kyber_kem_tester_armv8.o     \
				   ../drng/src/selftest_rng.o
kyber_768_kem_kdf_tester_armv8-y+= kyber768/tests/kyber_kem_tester.o	       \
				   kyber768/tests/kyber_kem_kdf_tester_armv8.o \
				   ../drng/src/selftest_rng.o

CFLAGS_kyber768/tests/kyber_kem_tester.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/tests/kyber_kem_tester_armv8.o	:= -DLC_KYBER_TYPE_768
CFLAGS_kyber768/tests/kyber_kem_kdf_tester_armv8.o:= -DLC_KYBER_TYPE_768

endif
endif
