Documentation ¶
Index ¶
- Variables
- func AddNamedCurve(curve elliptic.Curve, oid asn1.ObjectIdentifier)
- func BitsToBytes(bits int) int
- 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(rand io.Reader, 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
- func XY(D *big.Int, c elliptic.Curve) (X, Y *big.Int)
- type Hasher
- type PrivateKey
- type PublicKey
- type SignerOpts
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func AddNamedCurve ¶
func AddNamedCurve(curve elliptic.Curve, oid asn1.ObjectIdentifier)
func BitsToBytes ¶
func MarshalECPrivateKey ¶
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 NamedCurveFromOid ¶
func NamedCurveFromOid(oid asn1.ObjectIdentifier) elliptic.Curve
func OidFromNamedCurve ¶
func OidFromNamedCurve(curve elliptic.Curve) (asn1.ObjectIdentifier, bool)
func SignToRS ¶
func SignToRS(rand io.Reader, priv *PrivateKey, hashFunc Hasher, msg []byte) (r, s *big.Int, err error)
*
*| IUF - EC-GDSA signature *| *| UF 1. Compute h = H(m). If |h| > bitlen(q), set h to bitlen(q) *| leftmost (most significant) bits of h *| F 2. Compute e = - OS2I(h) mod q *| F 3. Get a random value k in [0,q] *| F 4. Compute W = (W_x,W_y) = kG *| F 5. Compute r = W_x mod q *| F 6. If r is 0, restart the process at step 4. *| F 7. Compute s = x(kr + e) mod q *| F 8. If s is 0, restart the process at step 4. *| F 9. Return (r,s) *
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
func VerifyWithRS ¶
*| IUF - EC-GDSA verification *| *| I 1. Reject the signature if r or s is 0. *| UF 2. Compute h = H(m). If |h| > bitlen(q), set h to bitlen(q) *| leftmost (most significant) bits of h *| F 3. Compute e = OS2I(h) mod q *| F 4. Compute u = ((r^-1)e mod q) *| F 5. Compute v = ((r^-1)s mod q) *| F 6. Compute W' = uG + vY *| F 7. Compute r' = W'_x mod q *| F 8. Accept the signature if and only if r equals r' *
Types ¶
type PrivateKey ¶
ec-gdsa 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 ¶
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 (*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 ¶
ec-gdsa PublicKey
func NewPublicKey ¶
根据公钥明文初始化公钥 New a PublicKey from publicKey data
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