diff --git a/dcrec/secp256k1/curve.go b/dcrec/secp256k1/curve.go index f2af9246fc..cd71c9b2e5 100644 --- a/dcrec/secp256k1/curve.go +++ b/dcrec/secp256k1/curve.go @@ -891,23 +891,20 @@ func ScalarMultNonConst(k *ModNScalar, point, result *JacobianPoint) { func ScalarBaseMultNonConst(k *ModNScalar, result *JacobianPoint) { bytePoints := s256BytePoints() - // Point Q = ∞ (point at infinity). - var q JacobianPoint + // Start with the point at infinity. + result.X.Zero() + result.Y.Zero() + result.Z.Zero() // bytePoints has all 256 byte points for each 8-bit window. The strategy // is to add up the byte points. This is best understood by expressing k in // base-256 which it already sort of is. Each "digit" in the 8-bit window // can be looked up using bytePoints and added together. - var pt JacobianPoint - for i, byteVal := range k.Bytes() { - p := bytePoints[i][byteVal] - pt.X.Set(&p[0]) - pt.Y.Set(&p[1]) - pt.Z.SetInt(1) - AddNonConst(&q, &pt, &q) + kb := k.Bytes() + for i := 0; i < len(kb); i++ { + pt := &bytePoints[i][kb[i]] + AddNonConst(result, pt, result) } - - result.Set(&q) } // isOnCurve returns whether or not the affine point (x,y) is on the curve. diff --git a/dcrec/secp256k1/loadprecomputed.go b/dcrec/secp256k1/loadprecomputed.go index a5b47990db..91c3d37769 100644 --- a/dcrec/secp256k1/loadprecomputed.go +++ b/dcrec/secp256k1/loadprecomputed.go @@ -17,7 +17,7 @@ import ( // bytePointTable describes a table used to house pre-computed values for // accelerating scalar base multiplication. -type bytePointTable [32][256][2]FieldVal +type bytePointTable [32][256]JacobianPoint // compressedBytePointsFn is set to a real function by the code generation to // return the compressed pre-computed values for accelerating scalar base @@ -66,12 +66,12 @@ var s256BytePoints = func() func() *bytePointTable { for byteNum := 0; byteNum < len(bytePoints); byteNum++ { // All points in this window. for i := 0; i < len(bytePoints[byteNum]); i++ { - px := &bytePoints[byteNum][i][0] - py := &bytePoints[byteNum][i][1] - px.SetByteSlice(serialized[offset:]) + p := &bytePoints[byteNum][i] + p.X.SetByteSlice(serialized[offset:]) offset += 32 - py.SetByteSlice(serialized[offset:]) + p.Y.SetByteSlice(serialized[offset:]) offset += 32 + p.Z.SetInt(1) } } data = &bytePoints