-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathecdh.go
31 lines (24 loc) · 800 Bytes
/
ecdh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package key25519
import "github.com/lyonnee/key25519/x25519"
// ECDH functions for KeyPair
func (kp *KeyPair) ExportEcdhKeyPair() (*x25519.KeyPair, error) {
return x25519.GenerateKeyPair(kp.privKey.Bytes())
}
func (kp *KeyPair) ECDH(peerEcdhPubKey []byte) ([]byte, error) {
x25519kp, err := kp.ExportEcdhKeyPair()
if err != nil {
return nil, err
}
return x25519kp.EcdhShare(peerEcdhPubKey)
}
// PrivateKey functions for KeyPair
func (privKey PrivateKey) ExportEcdhKeyPair() (*x25519.KeyPair, error) {
return x25519.GenerateKeyPair(privKey.ToEd25519PrivKey())
}
func (privKey PrivateKey) ECDH(peerEcdhPubKey []byte) ([]byte, error) {
x25519kp, err := x25519.GenerateKeyPair(privKey.ToEd25519PrivKey())
if err != nil {
return nil, err
}
return x25519kp.EcdhShare(peerEcdhPubKey)
}