pq-crystals / dilithium

Other
374 stars 136 forks source link

Is it AVX2 or AVX512 instruction set in the avx2 folder? #77

Closed marius-enlock closed 11 months ago

marius-enlock commented 11 months ago

Hello,

I have compiled the code in the avx2 folder, and encountered this error while calling int crypto_sign_verify(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *pk)

from cgo (golang):

SIGILL: illegal instruction PC=0xd0f392 m=7 sigcode=2 signal arrived during cgo execution instruction bytes: 0x62 0xf1 0x7f 0x28 0x7f 0x7 0x62 0xf1 0x7f 0x28 0x7f 0x47 0x1 0x62 0xf1 0x7f

I have searched (found here: https://bugs.kde.org/show_bug.cgi?id=426330 ) for the instruction bytes and they seem to correspond to an AVX512 instruction, I can't pinpoint which instruction more exactly.

This is the lscpu info for the machine that has this error (it has avx2 support): ` lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 48 bits physical, 48 bits virtual CPU(s): 2 On-line CPU(s) list: 0,1 Thread(s) per core: 2 Core(s) per socket: 1 Socket(s): 1 NUMA node(s): 1 Vendor ID: AuthenticAMD CPU family: 23 Model: 1 Model name: AMD EPYC 7571 Stepping: 2 CPU MHz: 2199.782 BogoMIPS: 4399.56 Hypervisor vendor: KVM Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdt scp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch topoext vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 clzero xsaveerptr arat npt nrip_save

`

I have tested on a different machine that has an intel processor and it works. ` Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 8 On-line CPU(s) list: 0-7 Vendor ID: GenuineIntel Model name: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz CPU family: 6 Model: 142 Thread(s) per core: 2 Core(s) per socket: 4 Socket(s): 1 Stepping: 10 CPU max MHz: 4200,0000 CPU min MHz: 400,0000 BogoMIPS: 4199.88 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mc a cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts repgood nopl xtopology nonstop tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cp l vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid ss e4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_f ault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_sh adow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adj ust sgx bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsave s dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities Virtualization features: Virtualization: VT-x

`

My problem is that the avx2 is supported for both machines but the one with the error doesn't support AVX512 I think.

What flag must I look for in order to decide if to use the code in the avx2 folder or the one in the ref one?