crypto

package
v0.0.0-...-59da782 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

README

crypto

功能

  • 支持 ed25519, secp256k1, sm2
  • 统一的 PrivKey,Pubkey, Signature 接口, 详见 crypto.go

依赖

  • sm2 编译依赖 gmssl 2.0 版本
  • 安装:bash ./deps/install_gmssl.sh

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CRandBytes

func CRandBytes(numBytes int) []byte

This uses the OS and the Seed(s).

func CRandHex

func CRandHex(numDigits int) string

RandHex(24) gives 96 bits of randomness, strong enough for most purposes.

func CReader

func CReader() io.Reader

Returns a crand.Reader mixed with user-supplied entropy

func MixEntropy

func MixEntropy(seedBytes []byte)

Mix additional bytes of randomness, e.g. from hardware, user-input, etc. It is OK to call it multiple times. It does not diminish security.

func Register

func Register(name string, driver Crypto)

func Ripemd160

func Ripemd160(bytes []byte) []byte

func Sha256

func Sha256(bytes []byte) []byte

func Sm3Hash

func Sm3Hash(msg []byte) []byte

Types

type Crypto

type Crypto interface {
	GenKey() (PrivKey, error)
	SignatureFromBytes([]byte) (Signature, error)
	PrivKeyFromBytes([]byte) (PrivKey, error)
	PubKeyFromBytes([]byte) (PubKey, error)
}

func New

func New(name string) (c Crypto, err error)

type PrivKey

type PrivKey interface {
	Bytes() []byte
	Sign(msg []byte) Signature
	PubKey() PubKey
	Equals(PrivKey) bool
}

type PubKey

type PubKey interface {
	Bytes() []byte
	KeyString() string
	VerifyBytes(msg []byte, sig Signature) bool
	Equals(PubKey) bool
}

type Signature

type Signature interface {
	Bytes() []byte
	IsZero() bool
	String() string
	Equals(Signature) bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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