-
Notifications
You must be signed in to change notification settings - Fork 71
all: replace Div/Mul with Rsh/Lsh if possible #29911 #1966
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -205,13 +205,13 @@ func (bitCurve *BitCurve) doubleJacobian(x, y, z *big.Int) (*big.Int, *big.Int, | |||||
| d.Mul(d, d) //(X1+B)² | ||||||
| d.Sub(d, a) //(X1+B)²-A | ||||||
| d.Sub(d, c) //(X1+B)²-A-C | ||||||
| d.Mul(d, big.NewInt(2)) //2*((X1+B)²-A-C) | ||||||
| d.Lsh(d, 1) //2*((X1+B)²-A-C) | ||||||
|
|
||||||
| e := new(big.Int).Mul(big.NewInt(3), a) //3*A | ||||||
| f := new(big.Int).Mul(e, e) //E² | ||||||
|
|
||||||
| x3 := new(big.Int).Mul(big.NewInt(2), d) //2*D | ||||||
| x3.Sub(f, x3) //F-2*D | ||||||
| x3 := new(big.Int).Lsh(d, 1) //2*D | ||||||
| x3.Sub(f, x3) //F-2*D | ||||||
| x3.Mod(x3, bitCurve.P) | ||||||
|
|
||||||
| y3 := new(big.Int).Sub(d, x3) //D-X3 | ||||||
|
|
@@ -220,7 +220,7 @@ func (bitCurve *BitCurve) doubleJacobian(x, y, z *big.Int) (*big.Int, *big.Int, | |||||
| y3.Mod(y3, bitCurve.P) | ||||||
|
|
||||||
| z3 := new(big.Int).Mul(y, z) //Y1*Z1 | ||||||
| z3.Mul(big.NewInt(2), z3) //3*Y1*Z1 | ||||||
| z3.Lsh(z3, 1) //3*Y1*Z1 | ||||||
|
||||||
| z3.Lsh(z3, 1) //3*Y1*Z1 | |
| z3.Lsh(z3, 1) //2*Y1*Z1 |
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.
The variable name is inconsistent with the function signature. At line 592,
vis being modified (usingSubwhich modifies the receiver), but this shadows the parametervfrom line 584. The original code created a new big.Int withv = new(big.Int).Sub(v, big.NewInt(35)), but the updated code modifies the parameter directly withv.Sub(v, big.NewInt(35)). This changes the behavior by mutating the input parameter, which could cause unexpected side effects if the caller retains a reference to the parameter.