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 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, h Hasher, msg []byte) (r, s *big.Int, err error)
- func SignUsingK(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
- 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 ¶
var ( ErrParametersNotSetUp = errors.New("go-cryptobin/eckcdsa: parameters not set up before generating key") ErrInvalidK = errors.New("go-cryptobin/eckcdsa: use another K") 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 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 ¶
*
*| 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 ¶
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 ¶ added in v1.0.3028
Verify verifies the Bytes encoded signature
func VerifyWithRS ¶
*
*| 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' *
Types ¶
type PrivateKey ¶
ec-kcdsa PrivateKey
func GenerateKey ¶
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 (*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-kcdsa PublicKey
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