-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid race condition in MakeAffine/ValidatePairing #59
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,24 +177,27 @@ func (c *twistPoint) Mul(a *twistPoint, scalar *big.Int) { | |
c.Set(sum) | ||
} | ||
|
||
// NB: Not safe for concurrent calls | ||
func (c *twistPoint) MakeAffine() { | ||
if c.z.IsOne() { | ||
g := c.Clone() | ||
if g.z.IsOne() { | ||
return | ||
} else if c.z.IsZero() { | ||
c.x.SetZero() | ||
c.y.SetOne() | ||
c.t.SetZero() | ||
} else if g.z.IsZero() { | ||
g.x.SetZero() | ||
g.y.SetOne() | ||
g.t.SetZero() | ||
return | ||
} | ||
|
||
zInv := (&gfP2{}).Invert(&c.z) | ||
t := (&gfP2{}).Mul(&c.y, zInv) | ||
zInv := (&gfP2{}).Invert(&g.z) | ||
t := (&gfP2{}).Mul(&g.y, zInv) | ||
zInv2 := (&gfP2{}).Square(zInv) | ||
c.y.Mul(t, zInv2) | ||
t.Mul(&c.x, zInv2) | ||
c.x.Set(t) | ||
c.z.SetOne() | ||
c.t.SetOne() | ||
g.y.Mul(t, zInv2) | ||
t.Mul(&g.x, zInv2) | ||
g.x.Set(t) | ||
g.z.SetOne() | ||
g.t.SetOne() | ||
c.Set(g) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of this Set here, I don't think using a Cloned There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this bit is dicey. I added the "not safe for concurrent use" warning above the function. |
||
} | ||
|
||
func (c *twistPoint) Neg(a *twistPoint) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure this is actually true since now you clone the inputs 🤔