This library contains arithmetic operations for prime fields upto 256 bit. Operations are optimized for AMD64 architecture.
New field can be created from standart big.Int prime number. Montgomery constants are precomputed during construction of new field.
pStr = "0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"
pBig := new(big.Int).SetString(pStr[:2],16)
field := NewField(pBig)
New field element can be created using bytes input. Given 32 bytes input new field element is transformed into Montgomery domain.
// input bytes with big endian order
feBytes := []byte{12, 14, 250, ... }
fe := field.NewElementFromBytes(feBytes)
// random element
fe2 := new(FieldElement)
field.RandElement(fe2, rand.Reader)
Prime field operations benchmarked on 2,7 GHz i5.
BenchmarkAddition 5.90 ns/op
BenchmarkMontgomeryMultiplication 37.1 ns/op
BenchmarkMontgomerySquaring 32.9 ns/op
BenchmarkInvertion 2829 ns/op