]> 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>
Mon, 23 Mar 2020 17:56:24 +0000 (17:56 +0000)
commit5c9bd499e103709a181f7a1a895d221ae6e7ffc8
tree38942a3590c3aeec0ee44736f4ffbfd1d3414e24
parent24925c7ed9da15fe780d0d2fce21bbaa707e8751
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.

Fixes #21704

Change-Id: Id5379c96384a11c5afde0614955360e7470bb1c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/223754
Reviewed-by: Katie Hockman <katie@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