Make the race detect happy.
Since the Z values are normalized (which ordinarily mutates them as needed) before checking for equality, the race detector gets confused when using a global value for the field representation of the value 1 and passing it into the various internal arithmetic routines and reports a false positive. Even though the race was a false positive and had no adverse effects, this commit silences the race detector by creating new variables at the top level and passing them instead of the global fieldOne variable. The global is still used for comparison operations since those have no potential to mutate the value and hence don't trigger the race detector.
This commit is contained in:
parent
7427e82664
commit
218906a91e
2 changed files with 20 additions and 18 deletions
14
btcec.go
14
btcec.go
|
@ -98,7 +98,7 @@ func (curve *KoblitzCurve) IsOnCurve(x, y *big.Int) bool {
|
|||
// (x1, y1, 1) + (x2, y2, 1) = (x3, y3, z3). It performs faster addition than
|
||||
// the generic add routine since less arithmetic is needed due to the ability to
|
||||
// avoid the z value multiplications.
|
||||
func (curve *KoblitzCurve) addZ1AndZ2EqualsOne(x1, y1, x2, y2, x3, y3, z3 *fieldVal) {
|
||||
func (curve *KoblitzCurve) addZ1AndZ2EqualsOne(x1, y1, z1, x2, y2, x3, y3, z3 *fieldVal) {
|
||||
// To compute the point addition efficiently, this implementation splits
|
||||
// the equation into intermediate elements which are used to minimize
|
||||
// the number of field multiplications using the method shown at:
|
||||
|
@ -124,7 +124,7 @@ func (curve *KoblitzCurve) addZ1AndZ2EqualsOne(x1, y1, x2, y2, x3, y3, z3 *field
|
|||
// Since x1 == x2 and y1 == y2, point doubling must be
|
||||
// done, otherwise the addition would end up dividing
|
||||
// by zero.
|
||||
curve.doubleJacobian(x1, y1, fieldOne, x3, y3, z3)
|
||||
curve.doubleJacobian(x1, y1, z1, x3, y3, z3)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -409,7 +409,7 @@ func (curve *KoblitzCurve) addJacobian(x1, y1, z1, x2, y2, z2, x3, y3, z3 *field
|
|||
isZ2One := z2.Equals(fieldOne)
|
||||
switch {
|
||||
case isZ1One && isZ2One:
|
||||
curve.addZ1AndZ2EqualsOne(x1, y1, x2, y2, x3, y3, z3)
|
||||
curve.addZ1AndZ2EqualsOne(x1, y1, z1, x2, y2, x3, y3, z3)
|
||||
return
|
||||
case z1.Equals(z2):
|
||||
curve.addZ1EqualsZ2(x1, y1, z1, x2, y2, x3, y3, z3)
|
||||
|
@ -441,7 +441,8 @@ func (curve *KoblitzCurve) Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int) {
|
|||
fx1, fy1 := curve.bigAffineToField(x1, y1)
|
||||
fx2, fy2 := curve.bigAffineToField(x2, y2)
|
||||
fx3, fy3, fz3 := new(fieldVal), new(fieldVal), new(fieldVal)
|
||||
curve.addJacobian(fx1, fy1, fieldOne, fx2, fy2, fieldOne, fx3, fy3, fz3)
|
||||
fOne := new(fieldVal).SetInt(1)
|
||||
curve.addJacobian(fx1, fy1, fOne, fx2, fy2, fOne, fx3, fy3, fz3)
|
||||
|
||||
// Convert the Jacobian coordinate field values back to affine big
|
||||
// integers.
|
||||
|
@ -583,7 +584,8 @@ func (curve *KoblitzCurve) Double(x1, y1 *big.Int) (*big.Int, *big.Int) {
|
|||
// and do the point doubling in Jacobian projective space.
|
||||
fx1, fy1 := curve.bigAffineToField(x1, y1)
|
||||
fx3, fy3, fz3 := new(fieldVal), new(fieldVal), new(fieldVal)
|
||||
curve.doubleJacobian(fx1, fy1, fieldOne, fx3, fy3, fz3)
|
||||
fOne := new(fieldVal).SetInt(1)
|
||||
curve.doubleJacobian(fx1, fy1, fOne, fx3, fy3, fz3)
|
||||
|
||||
// Convert the Jacobian coordinate field values back to affine big
|
||||
// integers.
|
||||
|
@ -600,7 +602,7 @@ func (curve *KoblitzCurve) ScalarMult(Bx, By *big.Int, k []byte) (*big.Int, *big
|
|||
|
||||
// Point P = the point to multiply the scalar with.
|
||||
px, py := curve.bigAffineToField(Bx, By)
|
||||
pz := fieldOne
|
||||
pz := new(fieldVal).SetInt(1)
|
||||
|
||||
// Double and add as necessary depending on the bits set in the scalar.
|
||||
for _, byteVal := range k {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
github.com/conformal/btcec/field.go fieldVal.Normalize 100.00% (93/93)
|
||||
github.com/conformal/btcec/field.go fieldVal.Inverse 100.00% (88/88)
|
||||
github.com/conformal/btcec/field.go fieldVal.SquareVal 100.00% (73/73)
|
||||
github.com/conformal/btcec/field.go fieldVal.Mul2 100.00% (73/73)
|
||||
github.com/conformal/btcec/field.go fieldVal.SquareVal 100.00% (73/73)
|
||||
github.com/conformal/btcec/signature.go parseSig 100.00% (51/51)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.addGeneric 100.00% (35/35)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.addZ2EqualsOne 100.00% (35/35)
|
||||
|
@ -13,47 +13,47 @@ github.com/conformal/btcec/btcec.go KoblitzCurve.addJacobian 100.00% (22/22)
|
|||
github.com/conformal/btcec/btcec.go KoblitzCurve.doubleZ1EqualsOne 100.00% (18/18)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.doubleGeneric 100.00% (18/18)
|
||||
github.com/conformal/btcec/signature.go Signature.Serialize 100.00% (13/13)
|
||||
github.com/conformal/btcec/field.go fieldVal.MulInt 100.00% (12/12)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.fieldJacobianToBigAffine 100.00% (12/12)
|
||||
github.com/conformal/btcec/field.go fieldVal.MulInt 100.00% (12/12)
|
||||
github.com/conformal/btcec/field.go fieldVal.Add2 100.00% (11/11)
|
||||
github.com/conformal/btcec/field.go fieldVal.Add 100.00% (11/11)
|
||||
github.com/conformal/btcec/field.go fieldVal.NegateVal 100.00% (11/11)
|
||||
github.com/conformal/btcec/field.go fieldVal.SetBytes 100.00% (11/11)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.ScalarMult 100.00% (10/10)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.Add 100.00% (10/10)
|
||||
github.com/conformal/btcec/field.go fieldVal.Zero 100.00% (10/10)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.Add 100.00% (9/9)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.doubleJacobian 100.00% (9/9)
|
||||
github.com/conformal/btcec/btcec.go initS256 100.00% (8/8)
|
||||
github.com/conformal/btcec/signature.go canonicalizeInt 100.00% (8/8)
|
||||
github.com/conformal/btcec/pubkey.go PublicKey.SerializeHybrid 100.00% (8/8)
|
||||
github.com/conformal/btcec/btcec.go initS256 100.00% (8/8)
|
||||
github.com/conformal/btcec/pubkey.go PublicKey.SerializeCompressed 100.00% (7/7)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.Double 100.00% (6/6)
|
||||
github.com/conformal/btcec/pubkey.go pad 100.00% (5/5)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.Double 100.00% (7/7)
|
||||
github.com/conformal/btcec/field.go fieldVal.SetByteSlice 100.00% (5/5)
|
||||
github.com/conformal/btcec/pubkey.go PublicKey.SerializeUncompressed 100.00% (5/5)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.bigAffineToField 100.00% (4/4)
|
||||
github.com/conformal/btcec/pubkey.go pad 100.00% (5/5)
|
||||
github.com/conformal/btcec/field.go fieldVal.SetHex 100.00% (4/4)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.IsOnCurve 100.00% (4/4)
|
||||
github.com/conformal/btcec/signature.go canonicalPadding 100.00% (4/4)
|
||||
github.com/conformal/btcec/field.go fieldVal.Bytes 100.00% (3/3)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.bigAffineToField 100.00% (4/4)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.IsOnCurve 100.00% (4/4)
|
||||
github.com/conformal/btcec/field.go fieldVal.SetInt 100.00% (3/3)
|
||||
github.com/conformal/btcec/field.go fieldVal.Bytes 100.00% (3/3)
|
||||
github.com/conformal/btcec/field.go fieldVal.String 100.00% (2/2)
|
||||
github.com/conformal/btcec/field.go fieldVal.Set 100.00% (2/2)
|
||||
github.com/conformal/btcec/btcec.go S256 100.00% (2/2)
|
||||
github.com/conformal/btcec/field.go fieldVal.IsZero 100.00% (2/2)
|
||||
github.com/conformal/btcec/field.go fieldVal.Equals 100.00% (2/2)
|
||||
github.com/conformal/btcec/field.go fieldVal.AddInt 100.00% (2/2)
|
||||
github.com/conformal/btcec/field.go fieldVal.Set 100.00% (2/2)
|
||||
github.com/conformal/btcec/pubkey.go isOdd 100.00% (1/1)
|
||||
github.com/conformal/btcec/field.go fieldVal.Mul 100.00% (1/1)
|
||||
github.com/conformal/btcec/field.go fieldVal.Square 100.00% (1/1)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.Params 100.00% (1/1)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.ScalarBaseMult 100.00% (1/1)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.QPlus1Div4 100.00% (1/1)
|
||||
github.com/conformal/btcec/field.go fieldVal.Negate 100.00% (1/1)
|
||||
github.com/conformal/btcec/btcec.go initAll 100.00% (1/1)
|
||||
github.com/conformal/btcec/field.go fieldVal.Negate 100.00% (1/1)
|
||||
github.com/conformal/btcec/signature.go ParseSignature 100.00% (1/1)
|
||||
github.com/conformal/btcec/signature.go ParseDERSignature 100.00% (1/1)
|
||||
github.com/conformal/btcec/field.go fieldVal.IsOdd 100.00% (1/1)
|
||||
github.com/conformal/btcec/pubkey.go ParsePubKey 96.88% (31/32)
|
||||
github.com/conformal/btcec ------------------------------------- 99.88% (844/845)
|
||||
github.com/conformal/btcec ------------------------------------- 99.88% (846/847)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue