go/src/crypto
Roland Shoemaker dc50683bf7 crypto/elliptic: upgrade from generic curve impl to specific if available
This change alters the CurveParam methods to upgrade from the generic
curve implementation to the specific P224 or P256 implementations when
called on the embedded CurveParams. This removes the trap of using
elliptic.P224().Params() instead of elliptic.P224(), for example, which
results in using the generic implementation instead of the optimized
constant time one. For P224 this is done for all of the CurveParams
methods, except Params, as the optimized implementation covers all
these methods. For P256 this is only done for ScalarMult and
ScalarBaseMult, as despite having implementations of addition and
doubling they aren't exposed and instead the generic implementation is
used. For P256 an additional check that there actually is a specific
implementation is added, as unlike the P224 implementation the P256 one
is only available on certain platforms.

This change takes the simple, fast approach to checking this, it simply
compares pointers. This removes the most obvious class of mistakes
people make, but still allows edge cases where the embedded CurveParams
pointer has been dereferenced (as seen in the unit tests) or when someone
has manually constructed their own CurveParams that matches one of the
standard curves. A more complex approach could be taken to also address
these cases, but it would require directly comparing all of the
CurveParam fields which would, in the worst case, require comparing
against two standard CurveParam sets in the ScalarMult and
ScalarBaseMult paths, which are likely to be the hottest already.

Updates #34648

Change-Id: I82d752f979260394632905c15ffe4f65f4ffa376
Reviewed-on: https://go-review.googlesource.com/c/go/+/233939
Trust: Roland Shoemaker <roland@golang.org>
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
2021-05-10 19:19:34 +00:00
..
aes all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
cipher crypto/cipher: make AES-GCM benchmarks match ChaCha20Poly1305 ones 2021-04-28 19:13:50 +00:00
des crypto/des: fix typo in permuteInitialBlock function comments 2020-09-22 21:24:40 +00:00
dsa crypto/dsa,crypto/x509: deprecate DSA and remove crypto/x509 support 2020-10-02 10:48:33 +00:00
ecdsa crypto/ecdsa,crypto/elliptic: improve tests and benchmarks 2021-05-06 02:21:55 +00:00
ed25519 crypto/ed25519: skip allocations test on -noopt builder 2021-05-06 02:20:28 +00:00
elliptic crypto/elliptic: upgrade from generic curve impl to specific if available 2021-05-10 19:19:34 +00:00
hmac crypto/hmac: panic if reusing hash.Hash values 2020-10-19 15:00:02 +00:00
internal all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
md5 crypto/md5: improve ppc64x performance 2021-03-15 12:30:38 +00:00
rand crypto/rand, internal/syscall/unix: add support for getentropy syscall on darwin 2021-03-17 22:14:28 +00:00
rc4 crypto/rc4: remove false guarantees from Reset docs and deprecate it 2019-02-22 17:05:17 +00:00
rsa crypto/rsa: fix salt length calculation with PSSSaltLengthAuto 2021-03-29 15:20:11 +00:00
sha1 docs: fix case of GitHub 2021-03-05 02:35:21 +00:00
sha256 docs: fix case of GitHub 2021-03-05 02:35:21 +00:00
sha512 all: remove redundant spaces before . and , 2021-04-20 00:49:17 +00:00
subtle crypto/subtle: normalize constant time ops docs 2019-01-22 19:40:30 +00:00
tls crypto/tls: make cipher suite preference ordering automatic 2021-05-08 05:15:48 +00:00
x509 crypto/x509: check the private key passed to CreateCertificate 2021-05-09 00:07:34 +00:00
crypto.go crypto: fix PKCS space in docs 2020-07-08 17:21:49 +00:00
issue21104_test.go