-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnttneon.go
76 lines (59 loc) · 1.41 KB
/
nttneon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//go:build neon
package mldsa
/*
#cgo CFLAGS: -march=armv8-a+simd -O3
#cgo LDFLAGS: -lm
#include "nttneon.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
func addNtt(parameters ParameterSet, aHat, bHat []int32) []int32 {
if len(aHat) != 256 || len(bHat) != 256 {
panic("input arrays must have length 256")
}
cHat := make([]int32, 256)
C.add_ntt(
(*C.int)(unsafe.Pointer(&aHat[0])),
(*C.int)(unsafe.Pointer(&bHat[0])),
(*C.int)(unsafe.Pointer(&cHat[0])),
C.int(parameters.Q),
)
return cHat
}
func subtractNtt(parameters ParameterSet, aHat, bHat []int32) []int32 {
if len(aHat) != 256 || len(bHat) != 256 {
panic("input arrays must have length 256")
}
cHat := make([]int32, 256)
C.subtract_ntt(
(*C.int)(unsafe.Pointer(&aHat[0])),
(*C.int)(unsafe.Pointer(&bHat[0])),
(*C.int)(unsafe.Pointer(&cHat[0])),
C.int(parameters.Q),
)
return cHat
}
func multiplyNtt(parameters ParameterSet, aHat, bHat []int32) []int32 {
if len(aHat) != 256 || len(bHat) != 256 {
panic("input arrays must have length 256")
}
a := make([]int64, 256)
b := make([]int64, 256)
for i := range 256 {
a[i] = int64(aHat[i])
b[i] = int64(bHat[i])
}
c := make([]int64, 256)
C.multiply_ntt(
(*C.int)(unsafe.Pointer(&a[0])),
(*C.int)(unsafe.Pointer(&b[0])),
(*C.int)(unsafe.Pointer(&c[0])),
C.int(parameters.Q),
)
cHat := make([]int32, 256)
for i := range 256 {
cHat[i] = int32(c[i])
}
return cHat
}