36 lines
941 B
Go
36 lines
941 B
Go
// Package secp256r1 implements Cosmos-SDK compatible ECDSA public and private key. The keys
|
|
// can be protobuf serialized and packed in Any.
|
|
package secp256r1
|
|
|
|
import (
|
|
"crypto/elliptic"
|
|
"fmt"
|
|
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
|
)
|
|
|
|
const (
|
|
// fieldSize is the curve domain size.
|
|
fieldSize = 32
|
|
pubKeySize = fieldSize + 1
|
|
|
|
name = "secp256r1"
|
|
)
|
|
|
|
var secp256r1 elliptic.Curve
|
|
|
|
func init() {
|
|
secp256r1 = elliptic.P256()
|
|
// pubKeySize is ceil of field bit size + 1 for the sign
|
|
expected := (secp256r1.Params().BitSize + 7) / 8
|
|
if expected != fieldSize {
|
|
panic(fmt.Sprintf("Wrong secp256r1 curve fieldSize=%d, expecting=%d", fieldSize, expected))
|
|
}
|
|
}
|
|
|
|
// RegisterInterfaces adds secp256r1 PubKey to pubkey registry
|
|
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
|
registry.RegisterImplementations((*cryptotypes.PubKey)(nil), &PubKey{})
|
|
}
|