Skip to content

Commit 6b83bd7

Browse files
committed
crypto/ecdh: add KeyExchanger interface
Updates #75300 Change-Id: I6a6a6964bbfa1f099c74d0a3fb3f7894d7b1b832 Reviewed-on: https://go-review.googlesource.com/c/go/+/705795 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Reviewed-by: Junyang Shao <[email protected]> Reviewed-by: Daniel McCarney <[email protected]>
1 parent 4fef9f8 commit 6b83bd7

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

api/next/75300.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pkg crypto/ecdh, type KeyExchanger interface { Curve, ECDH, PublicKey } #75300
2+
pkg crypto/ecdh, type KeyExchanger interface, Curve() Curve #75300
3+
pkg crypto/ecdh, type KeyExchanger interface, ECDH(*PublicKey) ([]uint8, error) #75300
4+
pkg crypto/ecdh, type KeyExchanger interface, PublicKey() *PublicKey #75300
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The new [KeyExchanger] interface, implemented by [PrivateKey], makes it possible
2+
to accept abstract ECDH private keys, e.g. those implemented in hardware.

src/crypto/ecdh/ecdh.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ func (k *PublicKey) Curve() Curve {
9292
return k.curve
9393
}
9494

95+
// KeyExchanger is an interface for an opaque private key that can be used for
96+
// key exchange operations. For example, an ECDH key kept in a hardware module.
97+
//
98+
// It is implemented by [PrivateKey].
99+
type KeyExchanger interface {
100+
PublicKey() *PublicKey
101+
Curve() Curve
102+
ECDH(*PublicKey) ([]byte, error)
103+
}
104+
105+
var _ KeyExchanger = (*PrivateKey)(nil)
106+
95107
// PrivateKey is an ECDH private key, usually kept secret.
96108
//
97109
// These keys can be parsed with [crypto/x509.ParsePKCS8PrivateKey] and encoded

0 commit comments

Comments
 (0)