]> Cypherpunks repositories - gostls13.git/commit
crypto/elliptic: move P-256 amd64/arm64 assembly to nistec
authorFilippo Valsorda <filippo@golang.org>
Fri, 25 Mar 2022 15:50:31 +0000 (16:50 +0100)
committerFilippo Valsorda <filippo@golang.org>
Thu, 5 May 2022 21:52:18 +0000 (21:52 +0000)
commit10d1189464dfd232265efc48a6b5bce56f72fe3c
treee3bcf7ffefbc6e186e8d4b170e433e97ff38a711
parent68c2e9eedeaa2ad9d9528fbb58adffb0a48365c9
crypto/elliptic: move P-256 amd64/arm64 assembly to nistec

The goal of this CL is to move the implementation to the new interface
with the least amount of changes possible. A follow-up CL will add
documentation and cleanup the assembly API.

  * SetBytes does the element and point validity checks now, which were
    previously implemented with big.Int.

  * p256BaseMult would return (0:0:1) if the scalar was zero, which is
    not a valid encoding of the point at infinity, but would get
    flattened into (0,0) by p256PointToAffine. The rest of the code can
    cope with any encoding with Z = 0, not just (t²:t³:0) with t != 0.

  * CombinedMult was only avoiding the big.Int and affine conversion
    overhead, which is now gone when operating entirely on nistec types,
    so it can be implemented entirely in the crypto/elliptic wrapper,
    and will automatically benefit all NIST curves.

  * Scalar multiplication can't operate on arbitrarily sized scalars (it
    was using big.Int to reduce them), which is fair enough. Changed the
    nistec point interface to let ScalarMult and ScalarBaseMult reject
    scalars. The crypto/elliptic wrapper still does the big.Int
    reduction as needed.

The ppc64le/s390x assembly is disabled but retained to make review of
the change that will re-enable it easier.

Very small performance changes, which we will more then recoup when
crypto/ecdsa moves to invoking nistec directly.

name                                  old time/op    new time/op    delta
pkg:crypto/elliptic goos:darwin goarch:arm64
ScalarBaseMult/P256-8                   11.3µs ± 0%    11.4µs ± 0%    +0.87%  (p=0.000 n=8+10)
ScalarMult/P256-8                       42.2µs ± 0%    42.2µs ± 0%      ~     (p=0.825 n=10+9)
MarshalUnmarshal/P256/Uncompressed-8     801ns ± 1%     334ns ± 0%   -58.29%  (p=0.000 n=9+10)
MarshalUnmarshal/P256/Compressed-8       798ns ± 0%     334ns ± 0%   -58.13%  (p=0.000 n=10+10)
pkg:crypto/ecdsa goos:darwin goarch:arm64
Sign/P256-8                             19.3µs ± 1%    19.4µs ± 0%    +0.81%  (p=0.003 n=8+9)
Verify/P256-8                           56.6µs ± 0%    56.3µs ± 1%    -0.48%  (p=0.003 n=7+10)
GenerateKey/P256-8                      11.9µs ± 0%    12.0µs ± 0%    +1.22%  (p=0.000 n=7+9)

For #52182

Change-Id: I0690a387e20018f38da55141c0d2659280b1a630
Reviewed-on: https://go-review.googlesource.com/c/go/+/395775
Reviewed-by: Fernando Lobato Meeser <felobato@google.com>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
23 files changed:
src/crypto/elliptic/elliptic.go
src/crypto/elliptic/elliptic_test.go
src/crypto/elliptic/export_generate.go [deleted file]
src/crypto/elliptic/gen_p256_table.go [deleted file]
src/crypto/elliptic/internal/nistec/generate.go
src/crypto/elliptic/internal/nistec/nistec_test.go
src/crypto/elliptic/internal/nistec/p224.go
src/crypto/elliptic/internal/nistec/p256.go
src/crypto/elliptic/internal/nistec/p256_asm.go [moved from src/crypto/elliptic/p256_asm.go with 59% similarity]
src/crypto/elliptic/internal/nistec/p256_asm_amd64.s [moved from src/crypto/elliptic/p256_asm_amd64.s with 100% similarity]
src/crypto/elliptic/internal/nistec/p256_asm_arm64.s [moved from src/crypto/elliptic/p256_asm_arm64.s with 100% similarity]
src/crypto/elliptic/internal/nistec/p256_asm_ppc64le.s [moved from src/crypto/elliptic/p256_asm_ppc64le.s with 99% similarity]
src/crypto/elliptic/internal/nistec/p256_asm_s390x.s [moved from src/crypto/elliptic/p256_asm_s390x.s with 99% similarity]
src/crypto/elliptic/internal/nistec/p256_asm_table.bin [moved from src/crypto/elliptic/p256_asm_table.bin with 100% similarity]
src/crypto/elliptic/internal/nistec/p256_asm_table_test.go [moved from src/crypto/elliptic/p256_asm_table_test.go with 98% similarity]
src/crypto/elliptic/internal/nistec/p256_ppc64le.go [moved from src/crypto/elliptic/p256_ppc64le.go with 99% similarity]
src/crypto/elliptic/internal/nistec/p256_s390x.go [moved from src/crypto/elliptic/p256_s390x.go with 99% similarity]
src/crypto/elliptic/internal/nistec/p384.go
src/crypto/elliptic/internal/nistec/p521.go
src/crypto/elliptic/nistec.go
src/crypto/elliptic/nistec_p256.go [new file with mode: 0644]
src/crypto/elliptic/params.go
src/go/build/deps_test.go