]> Cypherpunks repositories - gostls13.git/commit
crypto/rsa,crypto/ecdsa,crypto/ed25519: implement PublicKey.Equal
authorFilippo Valsorda <filippo@golang.org>
Wed, 18 Mar 2020 00:34:51 +0000 (20:34 -0400)
committerFilippo Valsorda <filippo@golang.org>
Thu, 26 Mar 2020 15:00:36 +0000 (15:00 +0000)
commitb5f2c0f50297fa5cd14af668ddd7fd923626cf8c
tree58af599ee0724097371cb06a1e5d9ba8214cc2c5
parentf9c5ef8d8f94b364c758930f64b9305c52200b5b
crypto/rsa,crypto/ecdsa,crypto/ed25519: implement PublicKey.Equal

This makes all modern public keys in the standard library implement a
common interface (below) that can be used by applications for better
type safety and allows for checking that public (and private keys via
Public()) are equivalent.

interface {
    Equal(crypto.PublicKey) bool
}

Equality for ECDSA keys is complicated, we take a strict interpretation
that works for all secure applications (the ones not using the
unfortunate non-constant time CurveParams implementation) and fails
closed otherwise.

Tests in separate files to make them x_tests and avoid an import loop
with crypto/x509.

Re-landing of CL 223754. Dropped the test that was assuming named curves
are not implemented by CurveParams, because it's not true for all
curves, and anyway is not a property we need to test. There is still a
test to check that different curves make keys not Equal.

Fixes #21704
Fixes #38035

Reviewed-on: https://go-review.googlesource.com/c/go/+/223754
Reviewed-by: Katie Hockman <katie@golang.org>
Change-Id: I736759b145bfb4f7f8eecd78c324315d5a05385c
Reviewed-on: https://go-review.googlesource.com/c/go/+/225460
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/crypto/ecdsa/ecdsa.go
src/crypto/ecdsa/equal_test.go [new file with mode: 0644]
src/crypto/ed25519/ed25519.go
src/crypto/ed25519/ed25519_test.go
src/crypto/rsa/equal_test.go [new file with mode: 0644]
src/crypto/rsa/rsa.go