crypto

package
v0.0.0-...-868bdbc Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AddressSize is the size of a pubkey address.
	AddressSize = herhash.TruncatedSize
)

Variables

View Source
var (
	ErrPrivateKeySize = errors.New("private key length does not equal expected key length")
)

Functions

func CRandBytes

func CRandBytes(numBytes int) []byte

This only uses the OS's randomness

func CReader

func CReader() io.Reader

CReader : Returns a crand.Reader.

func Hash

func Hash(hp HashPolicy, s *big.Int) *big.Int

Hash returns a hash of a big integer given a hash policy.

func Sha256

func Sha256(bytes []byte) []byte

Sha256 ...

func Verify

func Verify(sp SignaturePolicy, hp HashPolicy, publicKey []byte, message []byte, signature []byte) bool

Verify returns true if the given signature was generated using the given public key, message, signature policy, and hash policy.

Types

type Address

type Address = cmn.HexBytes

Address : An address is a []byte, but hex-encoded even in JSON. []byte leaves us the option to change the address length. Use an alias so Unmarshal methods (with ptr receivers) are available too.

func AddressHash

func AddressHash(bz []byte) Address

AddressHash ...

type HashPolicy

type HashPolicy interface {
	HashBytes(b []byte) []byte
}

HashPolicy defines how to create a cryptographic hash.

type KeyPair

type KeyPair struct {
	PrivateKey []byte
	PublicKey  []byte

	PrivKey PrivKey
	PubKey  PubKey
}

KeyPair represents a private and public key pair.

func FromPrivateKey

func FromPrivateKey(sp SignaturePolicy, privateKey string) (*KeyPair, error)

FromPrivateKey returns a KeyPair given a signature policy and private key.

func (*KeyPair) PrivateKeyHex

func (k *KeyPair) PrivateKeyHex() string

PrivateKeyHex returns the hex representation of the private key.

func (*KeyPair) PublicKeyHex

func (k *KeyPair) PublicKeyHex() string

PublicKeyHex returns the hex representation of the public key.

func (*KeyPair) Sign

func (k *KeyPair) Sign(sp SignaturePolicy, hp HashPolicy, message []byte) ([]byte, error)

Sign returns a cryptographic signature that is a signed hash of the message.

func (*KeyPair) String

func (k *KeyPair) String() (string, string)

String returns the private and public key pair.

type PrivKey

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

PrivKey ...

type PubKey

type PubKey interface {
	Address() Address
	Bytes() []byte
	VerifyBytes(msg []byte, sig []byte) bool
	Equals(PubKey) bool
	GetAddress() string // Creates address in string format and precedes the address with 'H'
}

PubKey ...

type SignaturePolicy

type SignaturePolicy interface {
	GenerateKeys() ([]byte, []byte, error)
	PrivateKeySize() int
	PrivateToPublic(privateKey []byte) ([]byte, error)
	PublicKeySize() int
	Sign(privateKey []byte, message []byte) []byte
	RandomKeyPair() *KeyPair
	Verify(publicKey []byte, message []byte, signature []byte) bool
}

SignaturePolicy defines the creation and validation of a cryptographic signature.

type Symmetric

type Symmetric interface {
	Keygen() []byte
	Encrypt(plaintext []byte, secret []byte) (ciphertext []byte)
	Decrypt(ciphertext []byte, secret []byte) (plaintext []byte, err error)
}

Symmetric ...

Directories

Path Synopsis
encoding
internal
Updated for Herdius Requirements Original Copyright (c) Tendermint Core.
Updated for Herdius Requirements Original Copyright (c) Tendermint Core.

Jump to

Keyboard shortcuts

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