crypto

package
v0.0.0-...-412d469 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const Secp256k1PrivateKeyBytes = 32

Secp256k1PrivateKeyBytes is the size of a serialized private key.

View Source
const Secp256k1PublicKeyBytes = 65

Secp256k1PublicKeyBytes is the size of a serialized public key.

Variables

This section is empty.

Functions

func GeneratePrivateRandomBytes

func GeneratePrivateRandomBytes(b []byte)

GeneratePrivateRandomBytes generates zero or more random numbers using the Private PRNG instance. These bytes should never be made public. Users of this function should consider creating a separate PRNG using GetNewPrivatePRNG if security domain separation is required.

func GeneratePublicRandomBytes

func GeneratePublicRandomBytes(b []byte)

GeneratePublicRandomBytes generates zero or more random numbers

func Keccak256

func Keccak256(data ...[]byte) []byte

Keccak256 calculates the keccak256 hash of given bytes

func PRNGEntropyKick

func PRNGEntropyKick()

PRNGEntropyKick is called when an application event occurs that an attacker on a computer on the network can not observe. For example, when a message arrives, this function can be called. Attackers may know down to the milli or even micro second when a message is serviced. However, they are unlikely to know the timing down to the nearest nano second.

func Secp256k1EcRecover

func Secp256k1EcRecover(msg, signature []byte) ([]byte, error)

Secp256k1EcRecover recovers the public key from a message, signature pair.

func Secp256k1Equals

func Secp256k1Equals(sk, other []byte) bool

Secp256k1Equals compares two private key for equality and returns true if they are the same.

func Secp256k1GenerateKey

func Secp256k1GenerateKey() ([]byte, error)

Secp256k1GenerateKey creates a new key using the private PRNG

func Secp256k1GenerateKeyFromSeed

func Secp256k1GenerateKeyFromSeed(seed io.Reader) ([]byte, error)

Secp256k1GenerateKeyFromSeed generates a new key from the given reader.

func Secp256k1PublicKey

func Secp256k1PublicKey(sk []byte) []byte

Secp256k1PublicKey returns the public key for this private key.

func Secp256k1Sign

func Secp256k1Sign(sk, toBeSigned []byte) ([]byte, error)

Secp256k1Sign signs some data and returns the signature.

func Secp256k1SignDigest

func Secp256k1SignDigest(sk, msg []byte) ([]byte, error)

Secp256k1SignDigest signs the given message, which must be 32 bytes long.

func Secp256k1Verify

func Secp256k1Verify(pk, toBeVerified, signature []byte) bool

Secp256k1Verify checks the given signature and returns true if it is valid.

func Secp256k1VerifyDigest

func Secp256k1VerifyDigest(pk, digest, signature []byte) bool

Secp256k1VerifyDigest checks the given signature and returns true if it is valid.

Types

type Random

type Random interface {
	ReadBytes(b []byte)
	Reseed(seed []byte)
	QuickReseedKick()
	GetReader() io.Reader
}

Random is the interface for pseudo random number generators in this project.

func GetPrivatePRNG

func GetPrivatePRNG() Random

GetPrivatePRNG returns the PRNG that should be used for generating random values that will stay private.

func GetPublicPRNG

func GetPublicPRNG() Random

GetPublicPRNG returns the PRNG that should be used for generating random values that will become public.

func NewPRNG

func NewPRNG(securityDomain []byte) Random

NewPRNG returns a new instance of the PRNG. The PRNG has a custom personalisation string, so identical instances on identical hardware should have differently seeded PRNGs.

func NewPrivatePRNG

func NewPrivatePRNG(securityDomain []byte) Random

NewPrivatePRNG returns the PRNG that should be used for generating random values that will stay private. Creating a separate PRNG for each set of usages helps to guarentee security domain separation.

Jump to

Keyboard shortcuts

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