go-pkgs: github.com/iotexproject/go-pkgs/crypto Index | Files

package crypto

import "github.com/iotexproject/go-pkgs/crypto"

Index

Package Files

cryptosort.go key.go merkle.go p256sm2.go secp256k1.go

Variables

var (
    // ErrInvalidKey is the error that the key format is invalid
    ErrInvalidKey = errors.New("invalid key format")
    // ErrPublicKey indicates the error of public key
    ErrPublicKey = errors.New("invalid public key")
    // ErrPrivateKey indicates the error of private key
    ErrPrivateKey = errors.New("invalid private key")
)
var (
    // CryptoSeed is a hardcoded seed that will be replaced by a seed produced dynamically.
    CryptoSeed = []byte{0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef}
)

func Sort Uses

func Sort(hashes [][]byte, nonce uint64)

Sort sorts a given slices of hashes cryptographically using hash function

func SortCandidates Uses

func SortCandidates(candidates []string, epochNum uint64, cryptoSeed []byte)

SortCandidates sorts a given slices of hashes cryptographically using hash function

func UpdatePrivateKeyPasswordToPem Uses

func UpdatePrivateKeyPasswordToPem(fileName string, oldPwd string, newPwd string) error

UpdatePrivateKeyPasswordToPem updates private key's password for PEM file

func WritePrivateKeyToPem Uses

func WritePrivateKeyToPem(file string, key *P256sm2PrvKey, pwd string) error

WritePrivateKeyToPem writes the private key to PEM file

func WritePublicKeyToPem Uses

func WritePublicKeyToPem(file string, key *P256sm2PubKey, pwd string) error

WritePublicKeyToPem writes the public key to PEM file

type Merkle Uses

type Merkle struct {
    // contains filtered or unexported fields
}

Merkle tree struct

func NewMerkleTree Uses

func NewMerkleTree(leaves []hash.Hash256) *Merkle

NewMerkleTree creates a merkle tree given hashed leaves

func (*Merkle) HashTree Uses

func (mk *Merkle) HashTree() hash.Hash256

HashTree calculates the root hash of a merkle tree

type P256sm2PrvKey Uses

type P256sm2PrvKey struct {
    *sm2.PrivateKey
}

P256sm2PrvKey implements the P256sm2 private key

func (*P256sm2PrvKey) Bytes Uses

func (k *P256sm2PrvKey) Bytes() []byte

Bytes returns the private key in bytes representation

func (*P256sm2PrvKey) D Uses

func (k *P256sm2PrvKey) D() []byte

D returns the secret D in big-endian

func (*P256sm2PrvKey) EcdsaPrivateKey Uses

func (k *P256sm2PrvKey) EcdsaPrivateKey() interface{}

EcdsaPrivateKey returns the embedded ecdsa private key

func (*P256sm2PrvKey) HexString Uses

func (k *P256sm2PrvKey) HexString() string

HexString returns the private key in hex string

func (*P256sm2PrvKey) PublicKey Uses

func (k *P256sm2PrvKey) PublicKey() PublicKey

PublicKey returns the public key corresponding to private key

func (*P256sm2PrvKey) Sign Uses

func (k *P256sm2PrvKey) Sign(hash []byte) ([]byte, error)

Sign signs the message/hash

func (*P256sm2PrvKey) Zero Uses

func (k *P256sm2PrvKey) Zero()

Zero zeroes the private key data

type P256sm2PubKey Uses

type P256sm2PubKey struct {
    *sm2.PublicKey
}

P256sm2PubKey implements the P256sm2 public key

func (*P256sm2PubKey) Bytes Uses

func (k *P256sm2PubKey) Bytes() []byte

Bytes returns the public key in bytes representation

func (*P256sm2PubKey) EcdsaPublicKey Uses

func (k *P256sm2PubKey) EcdsaPublicKey() interface{}

EcdsaPublicKey returns the embedded ecdsa publick key

func (*P256sm2PubKey) Hash Uses

func (k *P256sm2PubKey) Hash() []byte

Hash is the last 20-byte of keccak hash of public key (X, Y) co-ordinate

func (*P256sm2PubKey) HexString Uses

func (k *P256sm2PubKey) HexString() string

HexString returns the public key in hex string

func (*P256sm2PubKey) Verify Uses

func (k *P256sm2PubKey) Verify(hash, sig []byte) bool

Verify verifies the signature

type PrivateKey Uses

type PrivateKey interface {
    Bytes() []byte
    HexString() string
    EcdsaPrivateKey() interface{}
    PublicKey() PublicKey
    Sign([]byte) ([]byte, error)
    Zero()
}

PrivateKey represents a private key

func BytesToPrivateKey Uses

func BytesToPrivateKey(prvKey []byte) (PrivateKey, error)

BytesToPrivateKey converts a byte slice to SECP256K1 PrivateKey

func GenerateKey Uses

func GenerateKey() (PrivateKey, error)

GenerateKey generates a SECP256k1 PrivateKey

func GenerateKeySm2 Uses

func GenerateKeySm2() (PrivateKey, error)

GenerateKeySm2 generates a P256sm2 PrivateKey

func HexStringToPrivateKey Uses

func HexStringToPrivateKey(prvKey string) (PrivateKey, error)

HexStringToPrivateKey decodes a string to PrivateKey

func KeystoreToPrivateKey Uses

func KeystoreToPrivateKey(account accounts.Account, password string) (PrivateKey, error)

KeystoreToPrivateKey generates PrivateKey from Keystore account

func ReadPrivateKeyFromPem Uses

func ReadPrivateKeyFromPem(file string, pwd string) (PrivateKey, error)

ReadPrivateKeyFromPem reads the private key from PEM file

type PublicKey Uses

type PublicKey interface {
    Bytes() []byte
    HexString() string
    EcdsaPublicKey() interface{}
    Hash() []byte
    Verify([]byte, []byte) bool
}

PublicKey represents a public key

func BytesToPublicKey Uses

func BytesToPublicKey(pubKey []byte) (PublicKey, error)

BytesToPublicKey converts a byte slice to SECP256K1 PublicKey

func HexStringToPublicKey Uses

func HexStringToPublicKey(pubKey string) (PublicKey, error)

HexStringToPublicKey decodes a string to PublicKey

func ReadPublicKeyFromPem Uses

func ReadPublicKeyFromPem(file string, pwd string) (PublicKey, error)

ReadPublicKeyFromPem reads the public key from PEM file

func RecoverPubkey Uses

func RecoverPubkey(msg, sig []byte) (PublicKey, error)

RecoverPubkey recovers the public key from signature

Package crypto imports 20 packages (graph) and is imported by 11 packages. Updated 2020-05-29. Refresh now. Tools for package owners.