30 lines
631 B
Go
30 lines
631 B
Go
package x25519
|
|
|
|
import (
|
|
"crypto/ecdh"
|
|
"crypto/rand"
|
|
)
|
|
|
|
const (
|
|
// PublicKeyBytesSize is the size, in bytes, of public keys in raw bytes.
|
|
PublicKeyBytesSize = 32
|
|
// PrivateKeyBytesSize is the size, in bytes, of private keys in raw bytes.
|
|
PrivateKeyBytesSize = 32
|
|
|
|
MultibaseCode = uint64(0xec)
|
|
)
|
|
|
|
func GenerateKeyPair() (*PublicKey, *PrivateKey, error) {
|
|
priv, err := ecdh.X25519().GenerateKey(rand.Reader)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
pub := priv.Public().(*ecdh.PublicKey)
|
|
return &PublicKey{k: pub}, &PrivateKey{k: priv}, nil
|
|
}
|
|
|
|
const (
|
|
pemPubBlockType = "PUBLIC KEY"
|
|
pemPrivBlockType = "PRIVATE KEY"
|
|
)
|