/
arith384_asm.go
42 lines (32 loc) · 1.15 KB
/
arith384_asm.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
package evmmax_arith
import (
"github.com/jwasinger/evmmax-arith/arith384_asm"
"unsafe"
)
func MulMont384_asm(f *Field, out_bytes, x_bytes, y_bytes []byte) error {
x := (*[6]uint64)(unsafe.Pointer(&x_bytes[0]))
y := (*[6]uint64)(unsafe.Pointer(&y_bytes[0]))
z := (*[6]uint64)(unsafe.Pointer(&out_bytes[0]))
mod := (*[6]uint64)(unsafe.Pointer(&f.Modulus[0]))
// TODO bounds checks
arith384_asm.MulMod384(z, x, y, mod, f.MontParamInterleaved)
return nil
}
func AddMod384_asm(f *Field, out_bytes, x_bytes, y_bytes []byte) error {
x := (*[6]uint64)(unsafe.Pointer(&x_bytes[0]))
y := (*[6]uint64)(unsafe.Pointer(&y_bytes[0]))
z := (*[6]uint64)(unsafe.Pointer(&out_bytes[0]))
mod := (*[6]uint64)(unsafe.Pointer(&f.Modulus[0]))
// TODO bounds checks
arith384_asm.AddMod384(z, x, y, mod)
return nil
}
func SubMod384_asm(f *Field, out_bytes, x_bytes, y_bytes []byte) error {
x := (*[6]uint64)(unsafe.Pointer(&x_bytes[0]))
y := (*[6]uint64)(unsafe.Pointer(&y_bytes[0]))
z := (*[6]uint64)(unsafe.Pointer(&out_bytes[0]))
mod := (*[6]uint64)(unsafe.Pointer(&f.Modulus[0]))
// TODO bounds checks
arith384_asm.SubMod384(z, x, y, mod)
return nil
}