Skip to content

Instantly share code, notes, and snippets.

@obscuren
Created February 8, 2017 13:48
Show Gist options
  • Save obscuren/808a3da5350d91a097602a567dbab3da to your computer and use it in GitHub Desktop.
Save obscuren/808a3da5350d91a097602a567dbab3da to your computer and use it in GitHub Desktop.
// Exp sets z = x**y mod |fm|
func (z *Fq) Exp(x, y *Fq) *Fq {
load(z)
if y.abs.Cmp(bigZero) == 0 {
return z.SetInt64(0)
} else if y.abs.Cmp(bigOne) == 0 {
return z
} else if new(big.Int).Mod(y.abs, big.NewInt(2)).Cmp(bigZero) == 0 {
t := new(Fq).Div(y, NewField(2))
z.Mul(x, x).Exp(z, t)
} else {
z.Mul(x, x)
t := new(Fq).Div(y, NewField(2))
z.Exp(z, t)
z.Mul(z, x)
}
return z
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment