Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Armv7m: Add Dilithium test #43

Merged
merged 1 commit into from
Jan 7, 2025
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
include tests/chunk/chunk.mk
include tests/crt/crt.mk
include tests/ct/ct.mk
include tests/dilithium-armv7m/dilithium-armv7m.mk
include tests/flt-fft/flt-fft.mk
include tests/fx-fft/fx-fft.mk
include tests/helloworld/helloworld.mk
Expand Down
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/basemul_257_dilithium.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/basemul_257_dilithium_opt_m7.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/caddq_dilithium.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/caddq_dilithium_opt_m7.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/fnt_257_dilithium.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/fnt_257_dilithium_opt_m7.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/ifnt_257_dilithium.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/ifnt_257_dilithium_opt_m7.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/intt_769_dilithium.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/intt_769_dilithium_opt_m7.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/intt_dilithium_123_456_78.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/ntt_769_dilithium.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/ntt_769_dilithium_opt_m7.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/ntt_dilithium.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/ntt_dilithium_opt_m7.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/pointwise_769_dilithium.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/reduce32_dilithium.s
1 change: 1 addition & 0 deletions asm/manual/dilithium-armv7m/reduce32_dilithium_opt_m7.s
45 changes: 45 additions & 0 deletions tests/dilithium-armv7m/dilithium-armv7m.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Test name - needs to match the directory name
TESTS += dilithium-armv7m

# All further variables must be prefixed with the capitalized test name

# Platforms this test should run on (matching the directory name in envs/)
DILITHIUM_ARMV7M_PLATFORMS += m7-an500
DILITHIUM_ARMV7M_PLATFORMS += nucleo-f767zi
DILITHIUM_ARMV7M_PLATFORMS += stm32f4discovery

# C sources required for this test
DILITHIUM_ARMV7M_SOURCES += main.c
DILITHIUM_ARMV7M_SOURCES += ref.c

# Assembly sources required for this test
DILITHIUM_ARMV7M_ASM_DIR = ../../asm/manual/dilithium-armv7m
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/basemul_257_asymmetric_dilithium.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/basemul_257_dilithium.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/caddq_dilithium.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/fnt_257_dilithium.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/ifnt_257_dilithium.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/intt_769_dilithium.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/ntt_769_dilithium.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/ntt_dilithium.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/intt_dilithium_123_456_78.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/pointwise_769_asymmetric_dilithium.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/pointwise_769_dilithium.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/pointwise_acc_montgomery_dilithium.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/pointwise_montgomery_dilithium.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/reduce32_dilithium.s

DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/basemul_257_asymmetric_dilithium_opt_m7.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/basemul_257_dilithium_opt_m7.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/caddq_dilithium_opt_m7.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/fnt_257_dilithium_opt_m7.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/ifnt_257_dilithium_opt_m7.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/intt_769_dilithium_opt_m7.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/ntt_769_dilithium_opt_m7.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/ntt_dilithium_opt_m7.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/intt_dilithium_123_456_78_opt_m7.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/pointwise_769_asymmetric_dilithium_opt_m7.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/pointwise_769_dilithium_opt_m7.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/pointwise_acc_montgomery_dilithium_opt_m7.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/pointwise_montgomery_dilithium_opt_m7.s
DILITHIUM_ARMV7M_ASMS += $(DILITHIUM_ARMV7M_ASM_DIR)/reduce32_dilithium_opt_m7.s
62 changes: 62 additions & 0 deletions tests/dilithium-armv7m/fnt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef FNT_H
#define FNT_H

#include <stdint.h>

#define FNT_Q 257
#define FNT_Q_PRIME (16711935) // -q^-1 mod 2**32

static const int32_t twiddles_ntt_257_streamlined[] __attribute__((aligned(8))) = {-60, -35, -46, -42, 99, 89, -118, 27, -82, 108, -71, 54, 93, -41, 115, 68, 117, 73, -84, -59, -79, 21, -78, 37, -55, -109, 101, 74, -110, 39, 17, -70, -92, -50, -29, 57, -116, 83, 43, 75, -85, -91, 86, -107, 87, 15, -23, -111, -100, -58, 114, 25, -97, -10, 126, -40, 63, -20, -5, -80, -120, 44, -67, -72, -124, -31, 18, -106, 103, 90, -102, 45, -51, -77, 53, -121, -81, -11, 113, 9, -62, 36, -65, -12, -3, -48, 127, -24, -6, -96, 34, 88, 123, -49, -13, 61, -52, 112, -7, -66, -28, -33, -14, 125, -56, 30, 95, -22, -98, -26, 122, -104, -38, -94, 105, -119, -76, 69, -47, 19};
static const int32_t twiddles_intt_257_streamlined[] __attribute__((aligned(8))) = { -19, 47, -69, 76, 119, -105, 94, 38, 104, -122, 26, 98, 22, -95, -30, 56, -125, 14, 33, 28, 66, 7, -112, 52, -61, 13, 49, -123, -88, -34, 96, 6, 24, -127, 48, 3, 12, 65, -36, 62, -9, -113, 11, 81, 121, -53, 77, 51, -45, 102, -90, -103, 106, -18, 31, 124, 72, 67, -44, 120, 80, 5, 20, -63, 40, -126, 10, 97, -25, -114, 58, 100, 111, 23, -15, -87, 107, -86, 91, 85, -75, -43, -83, 116, -57, 29, 50, 92, 70, -17, -39, 110, -74, -101, 109, 55, -37, 78, -21, 79, 59, 84, -73, -117, -68, -115, 41, -93, -54, 71, -108, 82, -27, 118, -89, -99, 42, 46, 35, 60};
static const int32_t twiddles_basemul_257[] __attribute__((aligned(8))) = {27, -82, 108, -71, 54, 93, -41, 115, -78, 37, -55, -109, 101, 74, -110, 39, 83, 43, 75, -85, -91, 86, -107, 87, -97, -10, 126, -40, 63, -20, -5, -80, -106, 103, 90, -102, 45, -51, -77, 53, -65, -12, -3, -48, 127, -24, -6, -96, 112, -7, -66, -28, -33, -14, 125, -56, -38, -94, 105, -119, -76, 69, -47, 19};


// inputs in [-2, 2]; outputs in [-128, +128]
void __asm_fnt_257(int32_t *p, const int32_t twiddles[112], int32_t qprime, int32_t q);

void __asm_point_mul_257_16(int16_t p_prime[128], const int32_t p[256], int32_t qprime, int32_t q, const int32_t twiddles[64]);
void __asm_asymmetric_mul_257_16(int32_t c[256], const int32_t a[256], const int32_t b[256], const int16_t b_prime[128]);

// inputs in [-32768, 32768] outputs in [-128, +128]
void __asm_ifnt_257(int32_t *p, const int32_t twiddles[112], int32_t qprime, int32_t q);

void fnt_ntt(int32_t *a) {
__asm_fnt_257(a, twiddles_ntt_257_streamlined, FNT_Q_PRIME, FNT_Q);
}
void fnt_invntt_tomont(int32_t *a) {
__asm_ifnt_257(a, twiddles_intt_257_streamlined, FNT_Q_PRIME, FNT_Q);
}

void fnt_point_mul(int16_t * b_prime, int32_t *b){
__asm_point_mul_257_16(b_prime, b, FNT_Q_PRIME, FNT_Q, twiddles_basemul_257);
}
void fnt_asymmetric_mul(int32_t *c, int32_t *a, int32_t *b, int16_t *b_prime) {
__asm_asymmetric_mul_257_16(c, a, b, b_prime);
}

void __asm_fnt_257_opt_m7(int32_t *p, const int32_t twiddles[112], int32_t qprime, int32_t q);

void __asm_point_mul_257_16_opt_m7(int16_t p_prime[128], const int32_t p[256], int32_t qprime, int32_t q, const int32_t twiddles[64]);
void __asm_asymmetric_mul_257_16_opt_m7(int32_t c[256], const int32_t a[256], const int32_t b[256], const int16_t b_prime[128]);

void __asm_ifnt_257_opt_m7(int32_t *p, const int32_t twiddles[112], int32_t qprime, int32_t q);

void fnt_ntt_opt_m7(int32_t *a) {
__asm_fnt_257_opt_m7(a, twiddles_ntt_257_streamlined, FNT_Q_PRIME, FNT_Q);
}

void fnt_invntt_tomont_opt_m7(int32_t *a) {
__asm_ifnt_257_opt_m7(a, twiddles_intt_257_streamlined, FNT_Q_PRIME, FNT_Q);
}

void fnt_point_mul_opt_m7(int16_t * b_prime, int32_t *b){
__asm_point_mul_257_16_opt_m7(b_prime, b, FNT_Q_PRIME, FNT_Q, twiddles_basemul_257);
}

void fnt_asymmetric_mul_opt_m7(int32_t *c, int32_t *a, int32_t *b, int16_t *b_prime) {
__asm_asymmetric_mul_257_16_opt_m7(c, a, b, b_prime);
}



#endif
Loading
Loading