Skip to content

Commit 193c16a

Browse files
committed
crypto/elliptic: reduce subtraction term to prevent long busy loop
If beta8 is unusually large, the addition loop might take a very long time to bring x3-beta8 back positive. This would lead to a DoS vulnerability in the implementation of the P-521 and P-384 elliptic curves that may let an attacker craft inputs to ScalarMult that consume excessive amounts of CPU. This fixes CVE-2019-6486. Fixes #29903 Change-Id: Ia969e8b5bf5ac4071a00722de9d5e4d856d8071a Reviewed-on: https://team-review.git.corp.google.com/c/399777 Reviewed-by: Adam Langley <[email protected]> Reviewed-by: Julie Qiu <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/159218 Reviewed-by: Julie Qiu <[email protected]>
1 parent 1e450aa commit 193c16a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/crypto/elliptic/elliptic.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ func (curve *CurveParams) doubleJacobian(x, y, z *big.Int) (*big.Int, *big.Int,
210210

211211
x3 := new(big.Int).Mul(alpha, alpha)
212212
beta8 := new(big.Int).Lsh(beta, 3)
213+
beta8.Mod(beta8, curve.P)
213214
x3.Sub(x3, beta8)
214-
for x3.Sign() == -1 {
215+
if x3.Sign() == -1 {
215216
x3.Add(x3, curve.P)
216217
}
217218
x3.Mod(x3, curve.P)

0 commit comments

Comments
 (0)