// code originally taken from https://github.com/arnaucube/go-snark (https://github.com/arnaucube/go-snark/blob/master/fields/fq.go), pasted here to ensure compatibility among future changes
packagefield
import(
"bytes"
"crypto/rand"
"math/big"
)
// Fq is the Z field over modulus Q
typeFqstruct{
Q*big.Int// Q
}
// NewFq generates a new Fq
funcNewFq(q*big.Int)Fq{
returnFq{
q,
}
}
// Zero returns a Zero value on the Fq
func(fqFq)Zero()*big.Int{
returnbig.NewInt(int64(0))
}
// One returns a One value on the Fq
func(fqFq)One()*big.Int{
returnbig.NewInt(int64(1))
}
// Add performs an addition on the Fq
func(fqFq)Add(a,b*big.Int)*big.Int{
r:=new(big.Int).Add(a,b)
returnnew(big.Int).Mod(r,fq.Q)
}
// Double performs a doubling on the Fq
func(fqFq)Double(a*big.Int)*big.Int{
r:=new(big.Int).Add(a,a)
returnnew(big.Int).Mod(r,fq.Q)
}
// Sub performs a subtraction on the Fq
func(fqFq)Sub(a,b*big.Int)*big.Int{
r:=new(big.Int).Sub(a,b)
returnnew(big.Int).Mod(r,fq.Q)
}
// Neg performs a negation on the Fq
func(fqFq)Neg(a*big.Int)*big.Int{
m:=new(big.Int).Neg(a)
returnnew(big.Int).Mod(m,fq.Q)
}
// Mul performs a multiplication on the Fq
func(fqFq)Mul(a,b*big.Int)*big.Int{
m:=new(big.Int).Mul(a,b)
returnnew(big.Int).Mod(m,fq.Q)
}
func(fqFq)MulScalar(base,e*big.Int)*big.Int{
returnfq.Mul(base,e)
}
// Inverse returns the inverse on the Fq
func(fqFq)Inverse(a*big.Int)*big.Int{
returnnew(big.Int).ModInverse(a,fq.Q)
}
// Div performs the division over the finite field
// code originally taken from https://github.com/arnaucube/go-snark (https://github.com/arnaucube/go-snark/blob/master/fields/fq.go), pasted here to ensure compatibility among future changes
// MIMC7HashGeneric performs the MIMC7 hash over a *big.Int, in a generic way, where it can be specified the Finite Field over R, and the number of rounds
// HashGeneric performs the MIMC7 hash over a *big.Int array, in a generic way, where it can be specified the Finite Field over R, and the number of rounds