eckcdsa

package
v1.0.3026 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParametersNotSetUp = errors.New("go-cryptobin/eckcdsa: parameters not set up before generating key")
	ErrInvalidK           = errors.New("go-cryptobin/eckcdsa: use another K")
	ErrInvalidInteger     = errors.New("go-cryptobin/eckcdsa: invalid integer")
	ErrInvalidASN1        = errors.New("go-cryptobin/eckcdsa: invalid ASN.1")
	ErrInvalidSignerOpts  = errors.New("go-cryptobin/eckcdsa: opts must be *SignerOpts")
)

Functions

func AddNamedCurve

func AddNamedCurve(curve elliptic.Curve, oid asn1.ObjectIdentifier)

func BitsToBytes

func BitsToBytes(bits int) int

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 MarshalPrivateKey

func MarshalPrivateKey(key *PrivateKey) ([]byte, error)

包装私钥

func MarshalPublicKey

func MarshalPublicKey(pub *PublicKey) ([]byte, error)

包装公钥

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) (sig []byte, err error)

Sign data returns the ASN.1 encoded signature.

func SignToRS

func SignToRS(rand io.Reader, priv *PrivateKey, h Hasher, msg []byte) (r, s *big.Int, err error)

*

*| IUF - EC-KCDSA signature
*|
*| IUF  1. Compute h = H(z||m)
*|   F  2. If |H| > bitlen(q), set h to beta' rightmost bits of
*|         bitstring h (w/ beta' = 8 * ceil(bitlen(q) / 8)), i.e.
*|         set h to I2BS(beta', BS2I(|H|, h) mod 2^beta')
*|   F  3. Get a random value k in ]0,q[
*|   F  4. Compute W = (W_x,W_y) = kG
*|   F  5. Compute r = H(FE2OS(W_x)).
*|   F  6. If |H| > bitlen(q), set r to beta' rightmost bits of
*|         bitstring r (w/ beta' = 8 * ceil(bitlen(q) / 8)), i.e.
*|         set r to I2BS(beta', BS2I(|H|, r) mod 2^beta')
*|   F  7. Compute e = OS2I(r XOR h) mod q
*|   F  8. Compute s = x(k - e) mod q
*|   F  9. if s == 0, restart at step 3.
*|   F 10. return (r,s)
*

func SignUsingK added in v1.0.3026

func SignUsingK(k *big.Int, priv *PrivateKey, hashFunc Hasher, msg []byte) (r, s *big.Int, err error)

sign with k

func Verify

func Verify(pub *PublicKey, h Hasher, data, sig []byte) bool

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 VerifyWithRS

func VerifyWithRS(pub *PublicKey, hashFunc Hasher, data []byte, r, s *big.Int) bool

*

*| IUF - EC-KCDSA verification
*|
*| I   1. Check the length of r:
*|         - if |H| > bitlen(q), r must be of length
*|           beta' = 8 * ceil(bitlen(q) / 8)
*|         - if |H| <= bitlen(q), r must be of length hsize
*| I   2. Check that s is in ]0,q[
*| IUF 3. Compute h = H(z||m)
*|   F 4. If |H| > bitlen(q), set h to beta' rightmost bits of
*|        bitstring h (w/ beta' = 8 * ceil(bitlen(q) / 8)), i.e.
*|        set h to I2BS(beta', BS2I(|H|, h) mod 2^beta')
*|   F 5. Compute e = OS2I(r XOR h) mod q
*|   F 6. Compute W' = sY + eG, where Y is the public key
*|   F 7. Compute r' = h(W'x)
*|   F 8. If |H| > bitlen(q), set r' to beta' rightmost bits of
*|        bitstring r' (w/ beta' = 8 * ceil(bitlen(q) / 8)), i.e.
*|        set r' to I2BS(beta', BS2I(|H|, r') mod 2^beta')
*|   F 9. Check if r == r'
*

func XY

func XY(D *big.Int, c elliptic.Curve) (X, Y *big.Int)

Types

type Hasher added in v1.0.3026

type Hasher = func() hash.Hash

hash Func

type PrivateKey

type PrivateKey struct {
	PublicKey

	D *big.Int
}

ec-kcdsa PrivateKey

func GenerateKey

func GenerateKey(c elliptic.Curve, randReader io.Reader) (*PrivateKey, error)

Generate the paramters

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 ParsePrivateKey

func ParsePrivateKey(derBytes []byte) (*PrivateKey, error)

解析私钥

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

type PublicKey struct {
	elliptic.Curve

	X, Y *big.Int
}

ec-kcdsa PublicKey

func ParsePublicKey

func ParsePublicKey(derBytes []byte) (pub *PublicKey, err error)

解析公钥

func (*PublicKey) Equal

func (pub *PublicKey) Equal(x crypto.PublicKey) bool

Equal reports whether pub and x have the same value.

func (*PublicKey) Verify

func (pub *PublicKey) Verify(msg, sign []byte, opts crypto.SignerOpts) (bool, error)

Verify asn.1 marshal data

type SignerOpts

type SignerOpts struct {
	Hash Hasher
}

SignerOpts contains options for creating and verifying EC-KCDSA signatures.

func (*SignerOpts) GetHash added in v1.0.3026

func (opts *SignerOpts) GetHash() Hasher

GetHash returns func() hash.Hash

func (*SignerOpts) HashFunc

func (opts *SignerOpts) HashFunc() crypto.Hash

HashFunc returns opts.Hash

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL