Documentation ¶
Index ¶
- Constants
- Variables
- func AddNamedCurve(curve elliptic.Curve, oid asn1.ObjectIdentifier)
- func BatchVerify(pub []*PublicKey, m, sig [][]byte, hashFunc Hasher) bool
- func MarshalECPrivateKey(key *PrivateKey) ([]byte, error)
- func MarshalPrivateKey(key *PrivateKey) ([]byte, error)
- func MarshalPublicKey(pub *PublicKey) ([]byte, error)
- func NamedCurveFromOid(oid asn1.ObjectIdentifier) elliptic.Curve
- func OidFromNamedCurve(curve elliptic.Curve) (asn1.ObjectIdentifier, bool)
- func PrivateKeyTo(key *PrivateKey) []byte
- func PublicKeyTo(key *PublicKey) []byte
- func Sign(rand io.Reader, priv *PrivateKey, h Hasher, data []byte) (sig []byte, err error)
- func SignBytes(rand io.Reader, priv *PrivateKey, h Hasher, data []byte) (sig []byte, err error)
- func SignToRS(random io.Reader, priv *PrivateKey, hashFunc Hasher, msg []byte) (r, s *big.Int, err error)
- func SignUsingKToRS(k *big.Int, priv *PrivateKey, hashFunc Hasher, msg []byte) (r, s *big.Int, err error)
- func Verify(pub *PublicKey, h Hasher, data, sig []byte) bool
- func VerifyBytes(pub *PublicKey, h Hasher, data, sig []byte) bool
- func VerifyWithRS(pub *PublicKey, hashFunc Hasher, data []byte, r, s *big.Int) bool
- type CurveParams
- func (curve *CurveParams) Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int)
- func (curve *CurveParams) Double(x1, y1 *big.Int) (*big.Int, *big.Int)
- func (curve *CurveParams) IsOnCurve(x, y *big.Int) bool
- func (curve *CurveParams) Params() *elliptic.CurveParams
- func (curve *CurveParams) ScalarBaseMult(k []byte) (*big.Int, *big.Int)
- func (curve *CurveParams) ScalarMult(Bx, By *big.Int, k []byte) (*big.Int, *big.Int)
- func (curve *CurveParams) Unmarshal(data []byte) (x, y *big.Int)
- func (curve *CurveParams) UnmarshalCompressed(data []byte) (x, y *big.Int)
- type Hasher
- type PrivateKey
- type PublicKey
- type SignerOpts
Constants ¶
const ( BIP0340_AUX = "BIP0340/aux" BIP0340_NONCE = "BIP0340/nonce" BIP0340_CHALLENGE = "BIP0340/challenge" )
Variables ¶
var ( ErrPrivateKey = errors.New("go-cryptobin/bip0340: invalid PrivateKey") ErrParametersNotSetUp = errors.New("go-cryptobin/bip0340: parameters not set up before generating key") ErrInvalidK = errors.New("go-cryptobin/bip0340: use another K") ErrInvalidASN1 = errors.New("go-cryptobin/bip0340: invalid ASN.1") ErrInvalidSignerOpts = errors.New("go-cryptobin/bip0340: opts must be *SignerOpts") )
Functions ¶
func AddNamedCurve ¶ added in v1.0.5001
func AddNamedCurve(curve elliptic.Curve, oid asn1.ObjectIdentifier)
func BatchVerify ¶ added in v1.0.5003
* BIP0340 batch verification functions.
func MarshalECPrivateKey ¶ added in v1.0.5001
func MarshalECPrivateKey(key *PrivateKey) ([]byte, error)
MarshalECPrivateKey converts an EC private key to SEC 1, ASN.1 DER form.
This kind of key is commonly encoded in PEM blocks of type "EC PRIVATE KEY". For a more flexible key format which is not EC specific, use MarshalPKCS8PrivateKey.
func MarshalPrivateKey ¶ added in v1.0.5001
func MarshalPrivateKey(key *PrivateKey) ([]byte, error)
Marshal PrivateKey to der
func MarshalPublicKey ¶ added in v1.0.5001
Marshal PublicKey to der
func NamedCurveFromOid ¶ added in v1.0.5001
func NamedCurveFromOid(oid asn1.ObjectIdentifier) elliptic.Curve
func OidFromNamedCurve ¶ added in v1.0.5001
func OidFromNamedCurve(curve elliptic.Curve) (asn1.ObjectIdentifier, bool)
func SignToRS ¶
func SignToRS(random io.Reader, priv *PrivateKey, hashFunc Hasher, msg []byte) (r, s *big.Int, err error)
* BIP0340 signature. * NOTE: because of the semi-deterministinc nonce generation * process, streaming mode is NOT supported for signing. * Hence the following all-in-one signature function.
func SignUsingKToRS ¶
func SignUsingKToRS(k *big.Int, priv *PrivateKey, hashFunc Hasher, msg []byte) (r, s *big.Int, err error)
sign with k
func Verify ¶
Verify verifies the ASN.1 encoded signature, sig, M, of hash using the public key, pub. Its return value records whether the signature is valid.
func VerifyBytes ¶
Verify verifies the Bytes encoded signature
Types ¶
type CurveParams ¶
type CurveParams struct { P *big.Int // the order of the underlying field N *big.Int // the order of the base point B *big.Int // the constant of the curve equation Gx, Gy *big.Int // (x,y) of the base point BitSize int // the size of the underlying field Name string // the canonical name of the curve }
CurveParams contains the parameters of an elliptic curve and also provides a generic, non-constant time implementation of Curve.
func S256 ¶
func S256() *CurveParams
The following conventions are used, with constants as defined for secp256k1. We note that adapting this specification to other elliptic curves is not straightforward and can result in an insecure scheme
func (*CurveParams) IsOnCurve ¶
func (curve *CurveParams) IsOnCurve(x, y *big.Int) bool
IsOnCurve implements Curve.IsOnCurve.
func (*CurveParams) Params ¶
func (curve *CurveParams) Params() *elliptic.CurveParams
func (*CurveParams) ScalarBaseMult ¶
ScalarBaseMult implements Curve.ScalarBaseMult.
func (*CurveParams) ScalarMult ¶
ScalarMult implements Curve.ScalarMult.
func (*CurveParams) Unmarshal ¶
func (curve *CurveParams) Unmarshal(data []byte) (x, y *big.Int)
Unmarshal implements elliptic.Unmarshal.
func (*CurveParams) UnmarshalCompressed ¶
func (curve *CurveParams) UnmarshalCompressed(data []byte) (x, y *big.Int)
UnmarshalCompressed implements elliptic.UnmarshalCompressed.
type PrivateKey ¶
bip0340 PrivateKey
func GenerateKey ¶
Generate the PrivateKey
func NewPrivateKey ¶
func NewPrivateKey(curve elliptic.Curve, k []byte) (*PrivateKey, error)
New a PrivateKey from privatekey data
func ParseECPrivateKey ¶ added in v1.0.5001
func ParseECPrivateKey(der []byte) (*PrivateKey, error)
ParseECPrivateKey parses an EC private key in SEC 1, ASN.1 DER form.
This kind of key is commonly encoded in PEM blocks of type "EC PRIVATE KEY".
func ParsePrivateKey ¶ added in v1.0.5001
func ParsePrivateKey(derBytes []byte) (*PrivateKey, error)
Parse PrivateKey der
func (*PrivateKey) Equal ¶
func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool
Equal reports whether pub and x have the same value.
func (*PrivateKey) Public ¶
func (priv *PrivateKey) Public() crypto.PublicKey
Public returns the public key corresponding to priv.
func (*PrivateKey) Sign ¶
func (priv *PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)
crypto.Signer
type PublicKey ¶
Schnorr Signatures for secp256k1 bip0340 PublicKey
func NewPublicKey ¶
根据公钥明文初始化公钥 New a PublicKey from publicKey data
func ParsePublicKey ¶ added in v1.0.5001
Parse PublicKey der
type SignerOpts ¶
type SignerOpts struct {
Hash Hasher
}
SignerOpts contains options for creating and verifying EC-GDSA signatures.
func (*SignerOpts) GetHash ¶
func (opts *SignerOpts) GetHash() Hasher
GetHash returns func() hash.Hash
func (*SignerOpts) HashFunc ¶
func (opts *SignerOpts) HashFunc() crypto.Hash
HashFunc returns opts.Hash