]> Cypherpunks repositories - gostls13.git/commit
crypto/ecdsa: use bigmod and nistec instead of math/big and crypto/elliptic
authorFilippo Valsorda <filippo@golang.org>
Mon, 14 Nov 2022 17:43:43 +0000 (18:43 +0100)
committerGopher Robot <gobot@golang.org>
Mon, 21 Nov 2022 16:19:34 +0000 (16:19 +0000)
commit08f2091ce0817346458d2ae984ccea77817cd516
tree157e59526dfe49dc21a794670d43f8e2789c0c8b
parentd7812ab38031ae524a731b4d2f19adcecd22c2f4
crypto/ecdsa: use bigmod and nistec instead of math/big and crypto/elliptic

Ignoring custom curves, this makes the whole package constant-time.
There is a slight loss in performance for P-384 and P-521 because bigmod
is slower than math/big (but P-256 has an assembly scalar field
inversion, so doesn't use bigmod for anything big).

name                old time/op    new time/op    delta
Sign/P256-8           19.2µs ± 2%    19.1µs ± 2%     ~     (p=0.268 n=9+10)
Sign/P384-8            166µs ± 3%     188µs ± 2%  +13.52%  (p=0.000 n=10+10)
Sign/P521-8            337µs ± 2%     359µs ± 2%   +6.46%  (p=0.000 n=10+10)
Verify/P256-8         58.1µs ± 2%    58.1µs ± 2%     ~     (p=0.971 n=10+10)
Verify/P384-8          484µs ± 2%     569µs ±12%  +17.65%  (p=0.000 n=10+10)
Verify/P521-8         1.03ms ± 4%    1.14ms ± 2%  +11.02%  (p=0.000 n=10+10)
GenerateKey/P256-8    12.4µs ±12%    12.0µs ± 2%     ~     (p=0.063 n=10+10)
GenerateKey/P384-8     129µs ±18%     119µs ± 2%     ~     (p=0.190 n=10+10)
GenerateKey/P521-8     241µs ± 2%     240µs ± 2%     ~     (p=0.436 n=10+10)

name                old alloc/op   new alloc/op   delta
Sign/P256-8           3.08kB ± 0%    2.47kB ± 0%  -19.77%  (p=0.000 n=10+10)
Sign/P384-8           6.16kB ± 0%    2.64kB ± 0%  -57.16%  (p=0.000 n=10+10)
Sign/P521-8           7.87kB ± 0%    3.01kB ± 0%  -61.80%  (p=0.000 n=10+10)
Verify/P256-8         1.29kB ± 1%    0.48kB ± 0%  -62.69%  (p=0.000 n=10+10)
Verify/P384-8         2.49kB ± 1%    0.64kB ± 0%  -74.25%  (p=0.000 n=10+10)
Verify/P521-8         3.31kB ± 0%    0.96kB ± 0%  -71.02%  (p=0.000 n=7+10)
GenerateKey/P256-8      720B ± 0%      920B ± 0%  +27.78%  (p=0.000 n=10+10)
GenerateKey/P384-8      921B ± 0%     1120B ± 0%  +21.61%  (p=0.000 n=9+10)
GenerateKey/P521-8    1.30kB ± 0%    1.44kB ± 0%  +10.45%  (p=0.000 n=10+10)

name                old allocs/op  new allocs/op  delta
Sign/P256-8             45.0 ± 0%      33.0 ± 0%  -26.67%  (p=0.000 n=10+10)
Sign/P384-8             69.0 ± 0%      34.0 ± 0%  -50.72%  (p=0.000 n=10+10)
Sign/P521-8             71.0 ± 0%      35.0 ± 0%  -50.70%  (p=0.000 n=10+10)
Verify/P256-8           23.0 ± 0%      10.0 ± 0%  -56.52%  (p=0.000 n=10+10)
Verify/P384-8           43.0 ± 0%      14.0 ± 0%  -67.44%  (p=0.000 n=10+10)
Verify/P521-8           45.0 ± 0%      14.0 ± 0%  -68.89%  (p=0.000 n=7+10)
GenerateKey/P256-8      13.0 ± 0%      14.0 ± 0%   +7.69%  (p=0.000 n=10+10)
GenerateKey/P384-8      16.0 ± 0%      17.0 ± 0%   +6.25%  (p=0.000 n=10+10)
GenerateKey/P521-8      16.5 ± 3%      17.0 ± 0%   +3.03%  (p=0.033 n=10+10)

Change-Id: I4e074ef039b0f7ffbc436a4cdbe4ef90c647018d
Reviewed-on: https://go-review.googlesource.com/c/go/+/353849
Auto-Submit: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
18 files changed:
src/crypto/ecdsa/ecdsa.go
src/crypto/ecdsa/ecdsa_legacy.go [new file with mode: 0644]
src/crypto/ecdsa/ecdsa_noasm.go
src/crypto/ecdsa/ecdsa_s390x.go
src/crypto/ecdsa/ecdsa_test.go
src/crypto/elliptic/nistec.go
src/crypto/internal/bigmod/nat.go
src/crypto/internal/nistec/p256_ordinv.go [moved from src/crypto/internal/nistec/p256_asm_ordinv.go with 100% similarity]
src/crypto/internal/nistec/p256_ordinv_noasm.go [new file with mode: 0644]
src/crypto/internal/nistec/p256_ordinv_test.go [moved from src/crypto/internal/nistec/p256_asm_ordinv_test.go with 100% similarity]
src/crypto/tls/testdata/Client-TLSv10-ClientCert-ECDSA-ECDSA
src/crypto/tls/testdata/Client-TLSv10-ClientCert-ECDSA-RSA
src/crypto/tls/testdata/Client-TLSv12-ClientCert-ECDSA-ECDSA
src/crypto/tls/testdata/Client-TLSv12-ClientCert-ECDSA-RSA
src/crypto/tls/testdata/Client-TLSv13-ClientCert-ECDSA-RSA
src/crypto/tls/testdata/Server-TLSv10-ECDHE-ECDSA-AES
src/crypto/tls/testdata/Server-TLSv12-ECDHE-ECDSA-AES
src/crypto/tls/testdata/Server-TLSv13-ECDHE-ECDSA-AES