mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-09-27 04:36:12 +08:00
19 lines
411 B
Go
19 lines
411 B
Go
package curve25519
|
|
|
|
import (
|
|
"crypto/rand"
|
|
|
|
"golang.org/x/crypto/curve25519"
|
|
)
|
|
|
|
func GenerateKeyPair() ([]byte, []byte) {
|
|
var publicKey, privateKey [32]byte
|
|
_, _ = rand.Read(privateKey[:])
|
|
curve25519.ScalarBaseMult(&publicKey, &privateKey)
|
|
return publicKey[:], privateKey[:]
|
|
}
|
|
|
|
func SharedSecret(privateKey, otherPublicKey []byte) ([]byte, error) {
|
|
return curve25519.X25519(privateKey, otherPublicKey)
|
|
}
|