]> Cypherpunks.ru repositories - gostls13.git/commit
[release-branch.go1.20] crypto/internal/nistec: reduce P-256 scalar
authorFilippo Valsorda <filippo@golang.org>
Mon, 13 Feb 2023 14:16:27 +0000 (15:16 +0100)
committerGopher Robot <gobot@golang.org>
Mon, 27 Feb 2023 18:47:07 +0000 (18:47 +0000)
commit602eeaab387f24a4b28c5eccbb50fa934f3bc3c4
treeb2b5297dfceaa243c82c07754075e7317f9d28f4
parentac556f35a27dbd73372af4088b89df4d61ab74e8
[release-branch.go1.20] crypto/internal/nistec: reduce P-256 scalar

Unlike the rest of nistec, the P-256 assembly doesn't use complete
addition formulas, meaning that p256PointAdd[Affine]Asm won't return the
correct value if the two inputs are equal.

This was (undocumentedly) ignored in the scalar multiplication loops
because as long as the input point is not the identity and the scalar is
lower than the order of the group, the addition inputs can't be the same.

As part of the math/big rewrite, we went however from always reducing
the scalar to only checking its length, under the incorrect assumption
that the scalar multiplication loop didn't require reduction.

Added a reduction, and while at it added it in P256OrdInverse, too, to
enforce a universal reduction invariant on p256OrdElement values.

Note that if the input point is the infinity, the code currently still
relies on undefined behavior, but that's easily tested to behave
acceptably, and will be addressed in a future CL.

Updates #58647
Fixes #58720
Fixes CVE-2023-24532

(Filed with the "safe APIs like complete addition formulas are good" dept.)

Change-Id: I7b2c75238440e6852be2710fad66ff1fdc4e2b24
Reviewed-on: https://go-review.googlesource.com/c/go/+/471255
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
(cherry picked from commit 203e59ad41bd288e1d92b6f617c2f55e70d3c8e3)
Reviewed-on: https://go-review.googlesource.com/c/go/+/471695
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
src/crypto/internal/nistec/nistec_test.go
src/crypto/internal/nistec/p256_asm.go
src/crypto/internal/nistec/p256_ordinv.go