Documentation ¶
Index ¶
- Constants
- Variables
- func AddNamedCurve(curve elliptic.Curve, oid asn1.ObjectIdentifier)
- func BitsToBytes(bits int) int
- func GetOidFromAdata(adata []byte) (oid []byte, err error)
- func GetTFromAdata(adata []byte) (t []byte, err error)
- func MakeAdata(oid, t []byte) (adata []byte)
- 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, adata []byte) (sig []byte, err error)
- func SignBytes(rand io.Reader, priv *PrivateKey, h Hasher, data []byte, adata []byte) (sig []byte, err error)
- func SignToRS(random io.Reader, priv *PrivateKey, hashFunc Hasher, msg []byte, adata []byte) (r, s *big.Int, err error)
- func Verify(pub *PublicKey, h Hasher, data, adata []byte, sig []byte) bool
- func VerifyBytes(pub *PublicKey, h Hasher, data, adata []byte, sig []byte) bool
- func VerifyWithRS(pub *PublicKey, hashFunc Hasher, data []byte, adata []byte, r, s *big.Int) bool
- type Hasher
- type PrivateKey
- type PublicKey
- type SignerOpts
Constants ¶
const BELT_BLOCK_LEN = 16
const MAX_DIGEST_SIZE = 64
Variables ¶
var ( ErrAdata = errors.New("go-cryptobin/bign: invalid adata") ErrPrivateKey = errors.New("go-cryptobin/bign: invalid PrivateKey") ErrParametersNotSetUp = errors.New("go-cryptobin/bign: parameters not set up before generating key") ErrInvalidASN1 = errors.New("go-cryptobin/bign: invalid ASN.1") ErrInvalidSignerOpts = errors.New("go-cryptobin/bign: opts must be *SignerOpts") )
Functions ¶
func AddNamedCurve ¶
func AddNamedCurve(curve elliptic.Curve, oid asn1.ObjectIdentifier)
func BitsToBytes ¶
func GetOidFromAdata ¶
The additional data for bign are specific. We provide * helpers to extract them from an adata pointer.
func GetTFromAdata ¶
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 Sign ¶
func Sign(rand io.Reader, priv *PrivateKey, h Hasher, data []byte, adata []byte) (sig []byte, err error)
Sign data returns the ASN.1 encoded signature.
func SignBytes ¶
func SignBytes(rand io.Reader, priv *PrivateKey, h Hasher, data []byte, adata []byte) (sig []byte, err error)
Sign data returns the Bytes encoded signature.
func SignToRS ¶
func SignToRS(random io.Reader, priv *PrivateKey, hashFunc Hasher, msg []byte, adata []byte) (r, s *big.Int, err error)
*| IUF - bign signature
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 PrivateKey ¶
bign 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 ¶
bign PublicKey
func NewPublicKey ¶
根据公钥明文初始化公钥 New a PublicKey from publicKey data
type SignerOpts ¶
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