CovenantSQL: github.com/CovenantSQL/CovenantSQL/crypto/asymmetric Index | Files

package asymmetric

import "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric"

Package asymmetric implements Asymmetric Encryption methods ported from btcd, Ethereum-go etc.

Package btcec implements support for the elliptic curves needed for bitcoin.

Bitcoin uses elliptic curve cryptography using koblitz curves (specifically secp256k1) for cryptographic functions. See http://www.secg.org/collateral/sec2_final.pdf for details on the standard.

This package provides the data structures and functions implementing the crypto/elliptic Curve interface in order to permit using these curves with the standard crypto/ecdsa package provided with go. Helper functionality is provided to parse signatures and public keys from standard formats. It was designed for use with btcd, but should be general enough for other uses of elliptic curve crypto. It was originally based on some initial work by ThePiachu, but has significantly diverged since then.

Index

Package Files

doc.go keyexchange.go keypair.go signature.go

Constants

const PrivateKeyBytesLen = ec.PrivKeyBytesLen

PrivateKeyBytesLen defines the length in bytes of a serialized private key.

const PublicKeyBytesLen = ec.PubKeyBytesLenCompressed

PublicKeyBytesLen defines the length in bytes of a serialized public key.

const PublicKeyFormatHeader byte = 0x2

PublicKeyFormatHeader is the default header of PublicKey.Serialize()

see: github.com/btcsuite/btcd/btcec/pubkey.go#L63

Variables

var (
    // BypassSignature is the flag indicate if bypassing signature sign & verify
    BypassSignature = false
)

func GenECDHSharedSecret Uses

func GenECDHSharedSecret(privateKey *PrivateKey, publicKey *PublicKey) []byte

GenECDHSharedSecret is just a wrapper of ec.GenerateSharedSecret which generates a shared secret based on a private key and a public key using Diffie-Hellman key exchange (ECDH) (RFC 4753). RFC5903 Section 9 states we should only return x. Key Feature:

GenECDHSharedSecret(BPub, APriv) == GenECDHSharedSecret(APub, BPriv).

func GenSecp256k1KeyPair Uses

func GenSecp256k1KeyPair() (
    privateKey *PrivateKey,
    publicKey *PublicKey,
    err error)

GenSecp256k1KeyPair generate Secp256k1(used by Bitcoin) key pair.

func GetPubKeyNonce Uses

func GetPubKeyNonce(
    publicKey *PublicKey,
    difficulty int,
    timeThreshold time.Duration,
    quit chan struct{}) (nonce mine.NonceInfo)

GetPubKeyNonce will make his best effort to find a difficult enough nonce.

func PrivKeyFromBytes Uses

func PrivKeyFromBytes(pk []byte) (*PrivateKey, *PublicKey)

PrivKeyFromBytes returns a private and public key for `curve' based on the private key passed as an argument as a byte slice.

type PrivateKey Uses

type PrivateKey ec.PrivateKey

PrivateKey wraps an ec.PrivateKey as a convenience mainly for signing things with the the private key without having to directly import the ecdsa package.

func (*PrivateKey) PubKey Uses

func (private *PrivateKey) PubKey() *PublicKey

PubKey return the public key.

func (*PrivateKey) Serialize Uses

func (private *PrivateKey) Serialize() []byte

Serialize returns the private key number d as a big-endian binary-encoded number, padded to a length of 32 bytes.

func (*PrivateKey) Sign Uses

func (private *PrivateKey) Sign(hash []byte) (*Signature, error)

Sign generates an ECDSA signature for the provided hash (which should be the result of hashing a larger message) using the private key. Produced signature is deterministic (same message and same key yield the same signature) and canonical in accordance with RFC6979 and BIP0062.

type PublicKey Uses

type PublicKey ec.PublicKey

PublicKey wraps an ec.PublicKey as a convenience mainly verifying signatures with the the public key without having to directly import the ecdsa package.

func ParsePubKey Uses

func ParsePubKey(pubKeyStr []byte) (*PublicKey, error)

ParsePubKey recovers the public key from pubKeyStr.

func (*PublicKey) IsEqual Uses

func (k *PublicKey) IsEqual(public *PublicKey) bool

IsEqual return true if two keys are equal.

func (*PublicKey) MarshalBinary Uses

func (k *PublicKey) MarshalBinary() (keyBytes []byte, err error)

MarshalBinary does the serialization.

func (*PublicKey) MarshalHash Uses

func (k *PublicKey) MarshalHash() (keyBytes []byte, err error)

MarshalHash marshals for hash.

func (PublicKey) MarshalYAML Uses

func (k PublicKey) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (PublicKey) Msgsize Uses

func (k PublicKey) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message.

func (*PublicKey) Serialize Uses

func (k *PublicKey) Serialize() []byte

Serialize is a function that converts a public key to uncompressed byte array

TODO(leventeliu): use SerializeUncompressed, which is about 40 times faster than SerializeCompressed.

BenchmarkParsePublicKey-12 50000 39819 ns/op 2401 B/op 35 allocs/op BenchmarkParsePublicKey-12 1000000 1039 ns/op 384 B/op 9 allocs/op.

func (*PublicKey) UnmarshalBinary Uses

func (k *PublicKey) UnmarshalBinary(keyBytes []byte) (err error)

UnmarshalBinary does the deserialization.

func (*PublicKey) UnmarshalYAML Uses

func (k *PublicKey) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type Signature Uses

type Signature struct {
    R   *big.Int
    S   *big.Int
}

Signature is a type representing an ecdsa signature.

func ParseDERSignature Uses

func ParseDERSignature(sigStr []byte, curve elliptic.Curve) (*Signature, error)

ParseDERSignature recovers the signature from a sigStr.

func ParseSignature Uses

func ParseSignature(sigStr []byte) (*Signature, error)

ParseSignature recovers the signature from a sigStr using koblitz curve.

func (*Signature) IsEqual Uses

func (s *Signature) IsEqual(signature *Signature) bool

IsEqual return true if two signature is equal.

func (*Signature) MarshalBinary Uses

func (s *Signature) MarshalBinary() (keyBytes []byte, err error)

MarshalBinary does the serialization.

func (*Signature) MarshalHash Uses

func (s *Signature) MarshalHash() (keyBytes []byte, err error)

MarshalHash marshals for hash.

func (Signature) Msgsize Uses

func (s Signature) Msgsize() (sz int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message.

func (*Signature) Serialize Uses

func (s *Signature) Serialize() []byte

Serialize converts a signature to stirng.

func (*Signature) UnmarshalBinary Uses

func (s *Signature) UnmarshalBinary(keyBytes []byte) (err error)

UnmarshalBinary does the deserialization.

func (*Signature) Verify Uses

func (s *Signature) Verify(hash []byte, signee *PublicKey) bool

Verify calls ecdsa.Verify to verify the signature of hash using the public key. It returns true if the signature is valid, false otherwise.

Package asymmetric imports 15 packages (graph) and is imported by 32 packages. Updated 2019-04-03. Refresh now. Tools for package owners.