crypto

package
v0.0.0-...-1c4572a Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: BSD-2-Clause 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

View Source
const (
	SignNameED25519 = "ed25519"
)

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 GetName

func GetName(ty int) string

func GetType

func GetType(name string) int

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 RegisterType

func RegisterType(name string, ty int)

func Ripemd160

func Ripemd160(bytes []byte) []byte

func Sha256

func Sha256(bytes []byte) []byte

func Sm3Hash

func Sm3Hash(msg []byte) []byte

Types

type CertSignature

type CertSignature struct {
	Signature []byte
	Cert      []byte
}

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
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.

Jump to

Keyboard shortcuts

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