From da74b98565c85e8f856173985efc37d44507e6e7 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 15 Jan 2015 14:22:01 -0600 Subject: [PATCH] Fix a benign race detected by the race detector. The addition of the pre-computed values for the ScalarBaseMult optimizations added a benign race condition since a pointer to each pre-computed Jacobian point was being used in the call to addJacobian instead of a local stack copy. This resulted in the code which normalizes the field values to check for further optimization conditions such as equal Z values to race against the IsZero checks when multiple goroutines were performing EC operations since they were all operating on the same point in memory. In practice this was benign since the value was being replaced with the same thing and thus it was the same before and after the race, but it's never a good idea to have races. --- btcec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/btcec.go b/btcec.go index bcde3b04..dbec9b2c 100644 --- a/btcec.go +++ b/btcec.go @@ -646,7 +646,7 @@ func (curve *KoblitzCurve) ScalarBaseMult(k []byte) (*big.Int, *big.Int) { // Each "digit" in the 8-bit window can be looked up using bytePoints // and added together. for i, byteVal := range k { - point := &curve.bytePoints[diff+i][byteVal] + point := curve.bytePoints[diff+i][byteVal] curve.addJacobian(qx, qy, qz, &point[0], &point[1], &point[2], qx, qy, qz) } return curve.fieldJacobianToBigAffine(qx, qy, qz)