################################################################################
# Signature implementation: Dilithium

################################################################################
# C Implementation
################################################################################
# Dilithium Common
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM)				       \
				+= ../ml-dsa/src/dilithium_api.o	       \
				   ../ml-dsa/src/dilithium_ntt.o	       \
				   ../ml-dsa/src/dilithium_poly.o	       \
				   ../ml-dsa/src/dilithium_rounding.o	       \
				   ../ml-dsa/src/dilithium_zetas.o	       \
				   leancrypto_kernel_dilithium.o

# Dilithium 87
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_87)				       \
				+= ../ml-dsa/src/dilithium_poly_type.o	       \
				   ../ml-dsa/src/dilithium_rounding_type.o     \
				   ../ml-dsa/src/dilithium_selftest.o	       \
				   ../ml-dsa/src/dilithium_signature_c.o       \
				   ../ml-dsa/src/dilithium_signature_helper.o

# Dilithium 65
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_65)				       \
				+= dilithium65/dilithium_poly_type.o	       \
				   dilithium65/dilithium_rounding_type.o       \
				   dilithium65/dilithium_selftest.o	       \
				   dilithium65/dilithium_signature_c.o         \
				   dilithium65/dilithium_signature_helper.o
CFLAGS_dilithium65/dilithium_poly_type.o		:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/dilithium_rounding_type.o		:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/dilithium_selftest.o			:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/dilithium_signature_c.o		:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/dilithium_signature_helper.o		:= -DLC_DILITHIUM_TYPE_65

# Dilithium 44
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_44)				       \
				+= dilithium44/dilithium_poly_type.o	       \
				   dilithium44/dilithium_rounding_type.o       \
				   dilithium44/dilithium_selftest.o	       \
				   dilithium44/dilithium_signature_c.o         \
				   dilithium44/dilithium_signature_helper.o
CFLAGS_dilithium44/dilithium_poly_type.o		:= -DLC_DILITHIUM_TYPE_44
CFLAGS_dilithium44/dilithium_rounding_type.o		:= -DLC_DILITHIUM_TYPE_44
CFLAGS_dilithium44/dilithium_selftest.o			:= -DLC_DILITHIUM_TYPE_44
CFLAGS_dilithium44/dilithium_signature_c.o		:= -DLC_DILITHIUM_TYPE_44
CFLAGS_dilithium44/dilithium_signature_helper.o		:= -DLC_DILITHIUM_TYPE_44

# RISCV64 has its own Dilithium 44 API
ifeq ($(and $(CONFIG_RISCV),$(CONFIG_64BIT)),)
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_44)				       \
				+= dilithium44/dilithium_signature_api_c.o
CFLAGS_dilithium44/dilithium_signature_api_c.o		:= -DLC_DILITHIUM_TYPE_44
endif

# Dilithium-87-ED25519 implementation
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_ED25519)			       \
				+= leancrypto_kernel_dilithium_ed25519.o

ifdef CONFIG_LEANCRYPTO_DILITHIUM_87
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_ED25519)			       \
				+= ../ml-dsa/src/dilithium_ed25519_signature.o
endif

# Dilithium-65-ED25519 implementation
ifdef CONFIG_LEANCRYPTO_DILITHIUM_65
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_ED25519)			       \
				+= dilithium65/dilithium_ed25519_signature.o
CFLAGS_dilithium65/dilithium_ed25519_signature.o	:= -DLC_DILITHIUM_TYPE_65
endif

# Dilithium-44-ED25519 implementation
ifdef CONFIG_LEANCRYPTO_DILITHIUM_44
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_ED25519)			       \
				+= dilithium44/dilithium_ed25519_signature.o
CFLAGS_dilithium44/dilithium_ed25519_signature.o	:= -DLC_DILITHIUM_TYPE_44
endif

# Dilithium-87-ED448 implementation
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_ED448)				       \
				+= leancrypto_kernel_dilithium_ed448.o

ifdef CONFIG_LEANCRYPTO_DILITHIUM_87
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_ED448)				       \
				+= ../ml-dsa/src/dilithium_ed448_signature.o
endif

# Dilithium-65-ED448 implementation
ifdef CONFIG_LEANCRYPTO_DILITHIUM_65
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_ED448)				       \
				+= dilithium65/dilithium_ed448_signature.o
CFLAGS_dilithium65/dilithium_ed448_signature.o	:= -DLC_DILITHIUM_TYPE_65
endif

# Dilithium-44-ED448 implementation
ifdef CONFIG_LEANCRYPTO_DILITHIUM_44
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_ED448)				       \
				+= dilithium44/dilithium_ed448_signature.o
CFLAGS_dilithium44/dilithium_ed448_signature.o	:= -DLC_DILITHIUM_TYPE_44
endif

ifdef CONFIG_X86_64

################################################################################
# AVX2 Implementation
################################################################################
# Dilithium Common
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM)				       \
			+= ../ml-dsa/src/avx2/dilithium_consts_avx2.o	       \

# Dilithium 87
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_87)				       \
			+= ../ml-dsa/src/avx2/dilithium_invntt_avx2.o	       \
			   ../ml-dsa/src/avx2/dilithium_ntt_avx2.o	       \
			   ../ml-dsa/src/avx2/dilithium_pointwise_avx2.o       \
			   ../ml-dsa/src/avx2/dilithium_poly_avx2.o	       \
			   ../ml-dsa/src/avx2/dilithium_polyvec_avx2.o	       \
			   ../ml-dsa/src/avx2/dilithium_rejsample_avx2.o       \
			   ../ml-dsa/src/avx2/dilithium_rounding_avx2.o	       \
			   ../ml-dsa/src/avx2/dilithium_signature_api_avx2.o   \
			   ../ml-dsa/src/avx2/dilithium_signature_avx2.o       \
			   ../ml-dsa/src/avx2/dilithium_shuffle_avx2.o

# Dilithium 65
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_65)				       \
			+= dilithium65/avx2/dilithium_invntt_avx2.o	       \
			   dilithium65/avx2/dilithium_ntt_avx2.o	       \
			   dilithium65/avx2/dilithium_pointwise_avx2.o	       \
			   dilithium65/avx2/dilithium_poly_avx2.o	       \
			   dilithium65/avx2/dilithium_polyvec_avx2.o	       \
			   dilithium65/avx2/dilithium_rejsample_avx2.o	       \
			   dilithium65/avx2/dilithium_rounding_avx2.o	       \
			   dilithium65/avx2/dilithium_signature_api_avx2.o     \
			   dilithium65/avx2/dilithium_signature_avx2.o	       \
			   dilithium65/avx2/dilithium_shuffle_avx2.o
AFLAGS_dilithium65/avx2/dilithium_invntt_avx2.o		:= -DLC_DILITHIUM_TYPE_65
AFLAGS_dilithium65/avx2/dilithium_ntt_avx2.o		:= -DLC_DILITHIUM_TYPE_65
AFLAGS_dilithium65/avx2/dilithium_pointwise_avx2.o	:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/avx2/dilithium_poly_avx2.o		:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/avx2/dilithium_polyvec_avx2.o	:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/avx2/dilithium_rejsample_avx2.o	:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/avx2/dilithium_rounding_avx2.o	:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/avx2/dilithium_signature_api_avx2.o	:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/avx2/dilithium_signature_avx2.o	:= -DLC_DILITHIUM_TYPE_65
AFLAGS_dilithium65/avx2/dilithium_shuffle_avx2.o	:= -DLC_DILITHIUM_TYPE_65

else ifdef CONFIG_ARM

################################################################################
# ARMv7 Implementation
################################################################################
# Dilithium Common
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM)				       \
			+= ../ml-dsa/src/armv7/dilithium_ntt_consts.o

# Dilithium 87
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_87)				       \
			+= ../ml-dsa/src/armv7/dilithium_ntt_armv7.o	       \
			   ../ml-dsa/src/armv7/dilithium_pointwise_smull_armv7.o\
			   ../ml-dsa/src/armv7/dilithium_poly_armv7.o	       \
			   ../ml-dsa/src/armv7/dilithium_poly.o		       \
			   ../ml-dsa/src/armv7/dilithium_signature_api_armv7.o\
			   ../ml-dsa/src/armv7/dilithium_signature_armv7.o

# Dilithium 65
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_65)				       \
			+= dilithium65/armv7/dilithium_ntt_armv7.o	       \
			   dilithium65/armv7/dilithium_pointwise_smull_armv7.o \
			   dilithium65/armv7/dilithium_poly_armv7.o	       \
			   dilithium65/armv7/dilithium_poly.o		       \
			   dilithium65/armv7/dilithium_signature_api_armv7.o   \
			   dilithium65/armv7/dilithium_signature_armv7.o

AFLAGS_dilithium65/armv7/dilithium_ntt_armv7.o		:= -DLC_DILITHIUM_TYPE_65
AFLAGS_dilithium65/armv7/dilithium_pointwise_smull_armv7.o:= -DLC_DILITHIUM_TYPE_65
AFLAGS_dilithium65/armv7/dilithium_poly_armv7.o		:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/armv7/dilithium_poly.o		:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/armv7/dilithium_signature_api_armv7.o:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/armv7/dilithium_signature_armv7.o	:= -DLC_DILITHIUM_TYPE_65

else ifdef CONFIG_ARM64

################################################################################
# ARMv8 Implementation
################################################################################
# Dilithium Common
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM)				       \
			+= ../ml-dsa/src/armv8/NTT_params.o

# Dilithium 87
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_87)				       \
			+= ../ml-dsa/src/armv8/dilithium_intt_armv8.o	       \
			   ../ml-dsa/src/armv8/dilithium_ntt_armv8.o	       \
			   ../ml-dsa/src/armv8/dilithium_poly_armv8.o 	       \
			   ../ml-dsa/src/armv8/dilithium_signature_api_armv8.o\
			   ../ml-dsa/src/armv8/dilithium_signature_armv8.o

# Dilithium 65
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_65)				       \
			+= dilithium65/armv8/dilithium_intt_armv8.o	       \
			   dilithium65/armv8/dilithium_ntt_armv8.o	       \
			   dilithium65/armv8/dilithium_poly_armv8.o	       \
			   dilithium65/armv8/dilithium_signature_api_armv8.o   \
			   dilithium65/armv8/dilithium_signature_armv8.o
AFLAGS_dilithium65/armv8/dilithium_intt_armv8.o		:= -DLC_DILITHIUM_TYPE_65
AFLAGS_dilithium65/armv8/dilithium_ntt_armv8.o		:= -DLC_DILITHIUM_TYPE_65
AFLAGS_dilithium65/armv8/dilithium_poly_armv8.o		:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/armv8/dilithium_signature_api_armv8.o:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/armv8/dilithium_signature_armv8.o	:= -DLC_DILITHIUM_TYPE_65

else ifneq ($(and $(CONFIG_RISCV),$(CONFIG_64BIT)),)
################################################################################
# RISCV64 assembler and RVV implementations
################################################################################
# Dilithium Common
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM)				       \
			+= ../ml-dsa/src/riscv64/dilithium_consts_rvv.o	       \
			   ../ml-dsa/src/riscv64/dilithium_zetas_riscv64.o

# Dilithium 87 RISCV64 ASM
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_87)				       \
			+= ../ml-dsa/src/riscv64/dilithium_signature_api_riscv64.o\
			   ../ml-dsa/src/riscv64/dilithium_signature_riscv64.o \
			   ../ml-dsa/src/riscv64/ntt_8l_dualissue_plant_rv64im.o
AFLAGS_../ml-dsa/src/riscv64/ntt_8l_dualissue_plant_rv64im.o := -march=rv64gc  \
							        -mcmodel=medany

# Dilithium 65 RISCV64 ASM
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_65)				       \
			+= dilithium65/riscv64/dilithium_signature_api_riscv64.o\
			   dilithium65/riscv64/dilithium_signature_riscv64.o   \
			   dilithium65/riscv64/ntt_8l_dualissue_plant_rv64im.o
CFLAGS_dilithium65/riscv64/dilithium_signature_api_riscv64.o	:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/riscv64/dilithium_signature_riscv64.o	:= -DLC_DILITHIUM_TYPE_65
AFLAGS_dilithium65/riscv64/ntt_8l_dualissue_plant_rv64im.o := -march=rv64gc   \
							      -mcmodel=medany \
							      -DLC_DILITHIUM_TYPE_65

# Dilithium 44 RISCV64 ASM
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_44)				       \
			+= dilithium44/riscv64/dilithium_signature_api_riscv64.o\
			   dilithium44/riscv64/dilithium_signature_riscv64.o   \
			   dilithium44/riscv64/ntt_8l_dualissue_plant_rv64im.o
CFLAGS_dilithium44/riscv64/dilithium_signature_api_riscv64.o	:= -DLC_DILITHIUM_TYPE_44
CFLAGS_dilithium44/riscv64/dilithium_signature_riscv64.o	:= -DLC_DILITHIUM_TYPE_44
AFLAGS_dilithium44/riscv64/ntt_8l_dualissue_plant_rv64im.o := -march=rv64gc   \
							      -mcmodel=medany \
							      -DLC_DILITHIUM_TYPE_44

# Dilithium 87 RISCV64 RVV
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_87)				       \
			+= dilithium87/riscv64_rvv/dilithium_signature_riscv64_rvv.o\
			   dilithium87/riscv64_rvv/ntt_rvv.o
CFLAGS_dilithium87/riscv64_rvv/dilithium_signature_riscv64_rvv.o :=	       \
			-march=rv64imadcv -mcmodel=medany		       \
			-DLC_DILITHIUM_RISCV64_RVV
AFLAGS_dilithium87/riscv64_rvv/ntt_rvv.o := -march=rv64imadcv -mcmodel=medany  \
					    -DLC_DILITHIUM_RISCV64_RVV

# Dilithium 65 RISCV64 RVV
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_65)				       \
			+= dilithium65/riscv64_rvv/dilithium_signature_riscv64_rvv.o\
			   dilithium65/riscv64_rvv/ntt_rvv.o
CFLAGS_dilithium65/riscv64_rvv/dilithium_signature_riscv64_rvv.o :=	       \
			-march=rv64imadcv -mcmodel=medany -DLC_DILITHIUM_TYPE_65\
			-DLC_DILITHIUM_RISCV64_RVV
AFLAGS_dilithium65/riscv64_rvv/ntt_rvv.o := -march=rv64imadcv -mcmodel=medany  \
					    -DLC_DILITHIUM_TYPE_65	       \
					    -DLC_DILITHIUM_RISCV64_RVV

# Dilithium 44 RISCV64 RVV
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_44)				       \
			+= dilithium44/riscv64_rvv/dilithium_signature_riscv64_rvv.o\
			   dilithium44/riscv64_rvv/ntt_rvv.o
CFLAGS_dilithium44/riscv64_rvv/dilithium_signature_riscv64_rvv.o :=	       \
			-march=rv64imadcv -mcmodel=medany -DLC_DILITHIUM_TYPE_44\
			-DLC_DILITHIUM_RISCV64_RVV
AFLAGS_dilithium44/riscv64_rvv/ntt_rvv.o := -march=rv64imadcv -mcmodel=medany  \
					    -DLC_DILITHIUM_TYPE_44	       \
					    -DLC_DILITHIUM_RISCV64_RVV


################################################################################
# Interfaces for any non-accelerated implementation
################################################################################
else

# Dilithium 87
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_87)				       \
			+= ../ml-dsa/src/dilithium_signature_api_c.o

# Dilithium 65
leancrypto-$(CONFIG_LEANCRYPTO_DILITHIUM_65)				       \
			+= dilithium65/dilithium_signature_api_c.o
CFLAGS_dilithium65/dilithium_signature_api_c.o		:= -DLC_DILITHIUM_TYPE_65

# Dilithium 44 is already covered by the C implementation definition

endif

################################################################################
# Dilithium Test Cases
################################################################################
ccflags-$(CONFIG_LEANCRYPTO_DILITHIUM)					       \
				+= -I$(src)/../ml-dsa/src
ifdef CONFIG_LEANCRYPTO_DILITHIUM
ccflags-y			+= -DCONFIG_LEANCRYPTO_DILITHIUM

ifdef CONFIG_LEANCRYPTO_DILITHIUM_87
ccflags-y				+= -DCONFIG_LEANCRYPTO_DILITHIUM_87
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_dilithium_87_tester.o
leancrypto_kernel_dilithium_87_tester-y += ../ml-dsa/tests/leancrypto_kernel_dilithium_87_tester.o

obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_tester_c.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_tester_common.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_invalid_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_tester_official.o

dilithium_tester_c-y		+= ../ml-dsa/tests/dilithium_tester.o	       \
				   ../ml-dsa/tests/dilithium_tester_c.o	       \
				   ../drng/src/selftest_rng.o

dilithium_tester_common-y	+= ../ml-dsa/tests/dilithium_tester.o	       \
				   ../ml-dsa/tests/dilithium_tester_common.o\
				   ../drng/src/selftest_rng.o

dilithium_invalid_tester-y	+= ../ml-dsa/tests/dilithium_invalid_tester.o

dilithium_tester_official-y	+= ../ml-dsa/tests/dilithium_tester_official.o

endif

ifdef CONFIG_LEANCRYPTO_DILITHIUM_65
ccflags-y				+= -DCONFIG_LEANCRYPTO_DILITHIUM_65
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_dilithium_65_tester.o
leancrypto_kernel_dilithium_65_tester-y += dilithium65/tests/leancrypto_kernel_dilithium_65_tester.o

obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_65_tester_c.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_65_tester_common.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_65_invalid_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_65_tester_official.o

dilithium_65_tester_c-y		+= dilithium65/tests/dilithium_tester.o	       \
				   dilithium65/tests/dilithium_tester_c.o      \
				   ../drng/src/selftest_rng.o

dilithium_65_tester_common-y	+= dilithium65/tests/dilithium_tester.o	       \
				   dilithium65/tests/dilithium_tester_common.o \
				   ../drng/src/selftest_rng.o

dilithium_65_invalid_tester-y	+= dilithium65/tests/dilithium_invalid_tester.o

dilithium_65_tester_official-y	+= dilithium65/tests/dilithium_tester_official.o

CFLAGS_dilithium65/tests/leancrypto_kernel_dilithium_65_tester.o := -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/tests/dilithium_tester.o		:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/tests/dilithium_tester_c.o		:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/tests/dilithium_tester_common.o	:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/tests/dilithium_invalid_tester.o	:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/tests/dilithium_tester_official.o	:= -DLC_DILITHIUM_TYPE_65
endif

ifdef CONFIG_LEANCRYPTO_DILITHIUM_44
ccflags-y				+= -DCONFIG_LEANCRYPTO_DILITHIUM_44
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_dilithium_44_tester.o
leancrypto_kernel_dilithium_44_tester-y += dilithium44/tests/leancrypto_kernel_dilithium_44_tester.o

obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_44_tester_c.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_44_tester_common.o
#obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_44_edge_case_tester_c.o
#obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_44_edge_case_tester_common.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_44_invalid_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_44_tester_official.o

dilithium_44_tester_c-y		+= dilithium44/tests/dilithium_tester.o	       \
				   dilithium44/tests/dilithium_tester_c.o      \
				   ../drng/src/selftest_rng.o

dilithium_44_tester_common-y	+= dilithium44/tests/dilithium_tester.o	       \
				   dilithium44/tests/dilithium_tester_common.o \
				   ../drng/src/selftest_rng.o

#dilithium_44_edge_case_tester_c-y+= dilithium44/tests/dilithium_edge_case_tester.o\
#				   dilithium44/tests/dilithium_edge_case_tester_c.o

#dilithium_44_edge_case_tester_common-y+= dilithium44/tests/dilithium_edge_case_tester.o\
#				   dilithium44/tests/dilithium_edge_case_tester_common.o

dilithium_44_invalid_tester-y	+= dilithium44/tests/dilithium_invalid_tester.o

dilithium_44_tester_official-y	+= dilithium44/tests/dilithium_tester_official.o

CFLAGS_dilithium44/tests/leancrypto_kernel_dilithium_44_tester.o := -DLC_DILITHIUM_TYPE_44
CFLAGS_dilithium44/tests/dilithium_tester.o		:= -DLC_DILITHIUM_TYPE_44
CFLAGS_dilithium44/tests/dilithium_tester_c.o		:= -DLC_DILITHIUM_TYPE_44
CFLAGS_dilithium44/tests/dilithium_tester_common.o	:= -DLC_DILITHIUM_TYPE_44
#CFLAGS_dilithium44/tests/dilithium_edge_case_tester.o	:= -DLC_DILITHIUM_TYPE_44
#CFLAGS_dilithium44/tests/dilithium_edge_case_tester_c.o	:= -DLC_DILITHIUM_TYPE_44
#CFLAGS_dilithium44/tests/dilithium_edge_case_tester_common.o:= -DLC_DILITHIUM_TYPE_44
CFLAGS_dilithium44/tests/dilithium_invalid_tester.o	:= -DLC_DILITHIUM_TYPE_44
CFLAGS_dilithium44/tests/dilithium_tester_official.o	:= -DLC_DILITHIUM_TYPE_44
endif

ifdef CONFIG_X86_64
ifdef CONFIG_LEANCRYPTO_DILITHIUM_87
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_tester_avx2.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_tester_iuf_avx2.o

dilithium_tester_avx2-y		+= ../ml-dsa/tests/dilithium_tester.o	       \
				   ../ml-dsa/tests/dilithium_tester_avx2.o     \
				   ../drng/src/selftest_rng.o
dilithium_tester_iuf_avx2-y	+= ../ml-dsa/tests/dilithium_tester.o	       \
				   ../ml-dsa/tests/dilithium_tester_iuf_avx2.o\
				   ../drng/src/selftest_rng.o
endif

ifdef CONFIG_LEANCRYPTO_DILITHIUM_65
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_65_tester_avx2.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_65_tester_iuf_avx2.o

dilithium_65_tester_avx2-y	+= dilithium65/tests/dilithium_tester.o	       \
				   dilithium65/tests/dilithium_tester_avx2.o   \
				   ../drng/src/selftest_rng.o
dilithium_65_tester_iuf_avx2-y	+= dilithium65/tests/dilithium_tester.o	       \
				   dilithium65/tests/dilithium_tester_iuf_avx2.o\
				   ../drng/src/selftest_rng.o
CFLAGS_dilithium65/tests/dilithium_tester.o		:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/tests/dilithium_tester_avx2.o	:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/tests/dilithium_tester_iuf_avx2.o	:= -DLC_DILITHIUM_TYPE_65
endif
endif

ifdef CONFIG_ARM64
ifdef CONFIG_LEANCRYPTO_DILITHIUM_87
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_tester_armv8.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_tester_iuf_armv8.o

dilithium_tester_armv8-y	+= ../ml-dsa/tests/dilithium_tester.o	       \
				   ../ml-dsa/tests/dilithium_tester_armv8.o    \
				   ../drng/src/selftest_rng.o
dilithium_tester_iuf_armv8-y	+= ../ml-dsa/tests/dilithium_tester.o	       \
				   ../ml-dsa/tests/dilithium_tester_iuf_armv8.o\
				   ../drng/src/selftest_rng.o
endif

ifdef CONFIG_LEANCRYPTO_DILITHIUM_87
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_65_tester_armv8.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_65_tester_iuf_armv8.o

dilithium_65_tester_armv8-y	+= dilithium65/tests/dilithium_tester.o	       \
				   dilithium65/tests/dilithium_tester_armv8.o  \
				   ../drng/src/selftest_rng.o
dilithium_65_tester_iuf_armv8-y	+= dilithium65/tests/dilithium_tester.o	       \
				   dilithium65/tests/dilithium_tester_iuf_armv8.o\
				   ../drng/src/selftest_rng.o
CFLAGS_dilithium65/tests/dilithium_tester.o		:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/tests/dilithium_tester_armv8.o	:= -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/tests/dilithium_tester_iuf_armv8.o	:= -DLC_DILITHIUM_TYPE_65
endif
endif

ifdef CONFIG_ARM
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_tester_armv7.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_tester_iuf_armv7.o

dilithium_tester_armv7-y	+= ../ml-dsa/tests/dilithium_tester.o	       \
				   ../ml-dsa/tests/dilithium_tester_armv7.o    \
				   ../drng/src/selftest_rng.o
dilithium_tester_iuf_armv7-y	+= ../ml-dsa/tests/dilithium_tester.o	       \
				   ../ml-dsa/tests/dilithium_tester_iuf_armv7.o\
				   ../drng/src/selftest_rng.o
endif

endif

ifdef CONFIG_LEANCRYPTO_DILITHIUM_ED25519
ccflags-y			+= -DCONFIG_LEANCRYPTO_DILITHIUM_ED25519

ifdef CONFIG_LEANCRYPTO_DILITHIUM_87
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_ed25519_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_dilithium_87_ed25519_tester.o
leancrypto_kernel_dilithium_87_ed25519_tester-y += ../ml-dsa/tests/leancrypto_kernel_dilithium_87_ed25519_tester.o

dilithium_ed25519_tester-y	+= ../ml-dsa/tests/dilithium_ed25519_tester.o  \
				   ../drng/src/selftest_rng.o
endif

ifdef CONFIG_LEANCRYPTO_DILITHIUM_65
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_65_ed25519_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_dilithium_65_ed25519_tester.o
leancrypto_kernel_dilithium_65_ed25519_tester-y += dilithium65/tests/leancrypto_kernel_dilithium_65_ed25519_tester.o

dilithium_65_ed25519_tester-y	+= dilithium65/tests/dilithium_ed25519_tester.o\
				   ../drng/src/selftest_rng.o
CFLAGS_dilithium65/tests/leancrypto_kernel_dilithium_65_ed25519_tester.o := -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/tests/dilithium_ed25519_tester.o	:= -DLC_DILITHIUM_TYPE_65
endif

ifdef CONFIG_LEANCRYPTO_DILITHIUM_44
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_44_ed25519_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_dilithium_44_ed25519_tester.o
leancrypto_kernel_dilithium_44_ed25519_tester-y += dilithium44/tests/leancrypto_kernel_dilithium_44_ed25519_tester.o

dilithium_44_ed25519_tester-y	+= dilithium44/tests/dilithium_ed25519_tester.o\
				   ../drng/src/selftest_rng.o
CFLAGS_dilithium44/tests/leancrypto_kernel_dilithium_44_ed25519_tester.o := -DLC_DILITHIUM_TYPE_44
CFLAGS_dilithium44/tests/dilithium_ed25519_tester.o	:= -DLC_DILITHIUM_TYPE_44
endif

endif

ifdef CONFIG_LEANCRYPTO_DILITHIUM_ED448
ccflags-y			+= -DCONFIG_LEANCRYPTO_DILITHIUM_ED448

ifdef CONFIG_LEANCRYPTO_DILITHIUM_87
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_ed448_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_dilithium_87_ed448_tester.o
leancrypto_kernel_dilithium_87_ed448_tester-y += ../ml-dsa/tests/leancrypto_kernel_dilithium_87_ed448_tester.o

dilithium_ed448_tester-y	+= ../ml-dsa/tests/dilithium_ed448_tester.o  \
				   ../drng/src/selftest_rng.o
endif

ifdef CONFIG_LEANCRYPTO_DILITHIUM_65
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_65_ed448_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_dilithium_65_ed448_tester.o
leancrypto_kernel_dilithium_65_ed448_tester-y += dilithium65/tests/leancrypto_kernel_dilithium_65_ed448_tester.o

dilithium_65_ed448_tester-y	+= dilithium65/tests/dilithium_ed448_tester.o\
				   ../drng/src/selftest_rng.o
CFLAGS_dilithium65/tests/leancrypto_kernel_dilithium_65_ed448_tester.o := -DLC_DILITHIUM_TYPE_65
CFLAGS_dilithium65/tests/dilithium_ed448_tester.o	:= -DLC_DILITHIUM_TYPE_65
endif

ifdef CONFIG_LEANCRYPTO_DILITHIUM_44
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= dilithium_44_ed448_tester.o
obj-$(CONFIG_LEANCRYPTO_TEST_MODULES)	+= leancrypto_kernel_dilithium_44_ed448_tester.o
leancrypto_kernel_dilithium_44_ed448_tester-y += dilithium44/tests/leancrypto_kernel_dilithium_44_ed448_tester.o

dilithium_44_ed448_tester-y	+= dilithium44/tests/dilithium_ed448_tester.o\
				   ../drng/src/selftest_rng.o
CFLAGS_dilithium44/tests/leancrypto_kernel_dilithium_44_ed448_tester.o := -DLC_DILITHIUM_TYPE_44
CFLAGS_dilithium44/tests/dilithium_ed448_tester.o	:= -DLC_DILITHIUM_TYPE_44
endif

endif
