Files

36 lines
909 B
Go
Raw Permalink Normal View History

2025-06-25 15:53:29 +02:00
package p384
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
)
const (
// PublicKeyBytesSize is the size, in bytes, of public keys in raw bytes.
PublicKeyBytesSize = 1 + coordinateSize
2025-06-25 15:53:29 +02:00
// PrivateKeyBytesSize is the size, in bytes, of private keys in raw bytes.
PrivateKeyBytesSize = coordinateSize
2025-06-25 15:53:29 +02:00
// SignatureBytesSize is the size, in bytes, of signatures in raw bytes.
SignatureBytesSize = 2 * coordinateSize
2025-06-25 15:53:29 +02:00
MultibaseCode = uint64(0x1201)
// coordinateSize is the size, in bytes, of one coordinate in the elliptic curve.
coordinateSize = 48
2025-06-25 15:53:29 +02:00
)
func GenerateKeyPair() (*PublicKey, *PrivateKey, error) {
priv, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)
if err != nil {
return nil, nil, err
}
pub := priv.Public().(*ecdsa.PublicKey)
2025-06-25 16:46:43 +02:00
return &PublicKey{k: pub}, &PrivateKey{k: priv}, nil
2025-06-25 15:53:29 +02:00
}
const (
pemPubBlockType = "PUBLIC KEY"
pemPrivBlockType = "PRIVATE KEY"
)