-
Notifications
You must be signed in to change notification settings - Fork 12
/
fp.go
45 lines (36 loc) · 1.02 KB
/
fp.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
package fp
import (
basefield "github.com/consensys/gnark-crypto/ecc/bls12-381/fr"
)
// Element is a field element representing the basefield of the curve.
type Element = basefield.Element
// Limbs is the number of 64-bit words needed to represent the field element.
const Limbs = basefield.Limbs
// One returns the field element 1.
func One() Element {
return basefield.One()
}
// Zero returns the field element 0.
func Zero() Element {
return basefield.Element{}
}
// MinusOne returns the field element -1.
func MinusOne() Element {
m_one := One()
m_one.Neg(&m_one)
return m_one
}
// MulBy5 multiplies a field element by 5.
func MulBy5(a *Element) {
basefield.MulBy5(a)
}
// BatchInvert computes the inverse of a slice of field elements.
func BatchInvert(a []Element) []Element {
return basefield.BatchInvert(a)
}
// BytesLE returns the little-endian byte representation of a field element.
func BytesLE(a Element) []byte {
var result [basefield.Bytes]byte
basefield.LittleEndian.PutElement(&result, a)
return result[:]
}