fcrcrypto

package
Version: v0.0.0-...-12ab560 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: Apache-2.0 Imports: 18 Imported by: 5

Documentation

Overview

Package fcrcrypto - location for cryptographic tools to perform common operations on hashes, keys and signatures

Index

Constants

View Source
const (

	// SigAlgEcdsaSecP256K1Blake2b indicates the signature algorithm ECDSA
	// using curve SecP256K1 with Blake2b message digest algorithm.
	SigAlgEcdsaSecP256K1Blake2b = uint8(1)
)

Variables

This section is empty.

Functions

func BlockchainHash

func BlockchainHash(data []byte) []byte

BlockchainHash message digests some data using the algorithm used by the Filecoin blockchain.

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 GetBlockchainHasher

func GetBlockchainHasher() hash.Hash

GetBlockchainHasher returns a message digest implementation that hashes according to the algorithms used by the Filecoin blockchain.

func GetRetrievalV1Hasher

func GetRetrievalV1Hasher() hash.Hash

GetRetrievalV1Hasher returns a message digest implementation that hashes according to the algorithms used by version one of the Filecoin retrieval protocol.

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 RetrievalV1Hash

func RetrievalV1Hash(data []byte) []byte

RetrievalV1Hash message digests some data using the algorithm used by version one of the Filecoin retrieval protocol.

func RetrievalV1Verify

func RetrievalV1Verify(signature, toBeSigned, hashedPublicKey []byte) (bool, error)

RetrievalV1Verify verifies a signature across some data assuming algorithms used for Retrieval V1.

func SignMessage

func SignMessage(pKey *KeyPair, keyVersion *KeyVersion, msg []byte) (string, error)

SignMessage signs a message using the specified private key. Note that the struct must contain a field "Signature"

func VerifyMessage

func VerifyMessage(pubKey *KeyPair, signature string, msg []byte) (bool, error)

VerifyMessage verifies a message using the specified public key. Note that the struct must contain a field "Signature"

Types

type KeyPair

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

KeyPair holds information related to a key pair. Either of the private key or public key may be nil.

func DecodePrivateKey

func DecodePrivateKey(encoded string) (*KeyPair, error)

DecodePrivateKey decodes the algorithm and private key from a hex string.

func DecodePublicKey

func DecodePublicKey(encoded string) (*KeyPair, error)

DecodePublicKey decodes the algorithm and public key from a hex string.

func DecodeRawPrivateKey

func DecodeRawPrivateKey(encoded string) (*KeyPair, error)

DecodeRawPrivateKey decodes the private key from a hex string, and assumes the key algorithm is the default one for Filecoin: SigAlgEcdsaSecP256K1Blake2b

func GenerateBlockchainKeyPair

func GenerateBlockchainKeyPair() (*KeyPair, error)

GenerateBlockchainKeyPair generates a key pair for use with the Filecoin blockchain

func GenerateRetrievalV1KeyPair

func GenerateRetrievalV1KeyPair() (*KeyPair, error)

GenerateRetrievalV1KeyPair generates a key pair for use with v1 of the Filecoin Retrieval protocol.

func (*KeyPair) EncodePrivateKey

func (k *KeyPair) EncodePrivateKey() string

EncodePrivateKey encodes the algorithm and private key as a hex string.

func (*KeyPair) EncodePublicKey

func (k *KeyPair) EncodePublicKey() (string, error)

EncodePublicKey encodes the algorithm and public key as a hex string.

func (*KeyPair) EncodeRawPrivateKey

func (k *KeyPair) EncodeRawPrivateKey() (string, error)

EncodeRawPrivateKey encodes the private key as a hex string. Note that the algorithm is not stored with the key. As such, the code will return an error if the key algorithm is anything other than SigAlgEcdsaSecP256K1Blake2b.

func (*KeyPair) HashPublicKey

func (k *KeyPair) HashPublicKey() ([]byte, error)

HashPublicKey generates a message digest that matches the public key.

func (KeyPair) MarshalJSON

func (k KeyPair) MarshalJSON() ([]byte, error)

MarshalJSON is used to marshal public Keypair into bytes

func (*KeyPair) Sign

func (k *KeyPair) Sign(toBeSigned []byte) ([]byte, error)

Sign some data.

func (*KeyPair) UnmarshalJSON

func (k *KeyPair) UnmarshalJSON(p []byte) error

UnmarshalJSON is used to unmarshal bytes into Keypair

func (*KeyPair) Verify

func (k *KeyPair) Verify(signature, toBeSigned []byte) (bool, error)

Verify a signature across some data.

type KeySigAlg

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

KeySigAlg is holds the signature algorithm

func DecodeSigAlg

func DecodeSigAlg(alg uint8) KeySigAlg

DecodeSigAlg converts a number to an object.

func DecodeSigAlgFromBytes

func DecodeSigAlgFromBytes(data []byte) *KeySigAlg

DecodeSigAlgFromBytes converts bytes to an object

func (*KeySigAlg) EncodeSigAlg

func (k *KeySigAlg) EncodeSigAlg() uint8

EncodeSigAlg converts a number to an object.

func (*KeySigAlg) EncodeSigAlgAsBytes

func (k *KeySigAlg) EncodeSigAlgAsBytes() []byte

EncodeSigAlgAsBytes converts an object to bytes.

func (*KeySigAlg) Equals

func (k *KeySigAlg) Equals(other *KeySigAlg) bool

Equals returns true if the value passed in matches the algorithm.

func (*KeySigAlg) Is

func (k *KeySigAlg) Is(other uint8) bool

Is returns true if the value passed in matches the algorithm.

func (*KeySigAlg) IsNot

func (k *KeySigAlg) IsNot(other uint8) bool

IsNot returns true if the value passed in does not match the algorithm.

type KeyVersion

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

KeyVersion wraps a key version number.

func DecodeKeyVersion

func DecodeKeyVersion(ver uint32) *KeyVersion

DecodeKeyVersion converts a number to an object.

func DecodeKeyVersionFromBytes

func DecodeKeyVersionFromBytes(version []byte) (*KeyVersion, error)

DecodeKeyVersionFromBytes converts a byte array to ann object.

func ExtractKeyVersionFromMessage

func ExtractKeyVersionFromMessage(signature string) (*KeyVersion, error)

ExtractKeyVersionFromMessage extracts the key version from a signature string

func InitialKeyVersion

func InitialKeyVersion() *KeyVersion

InitialKeyVersion returns the first key version

func (*KeyVersion) EncodeKeyVersion

func (k *KeyVersion) EncodeKeyVersion() uint32

EncodeKeyVersion converts an object to a number

func (*KeyVersion) EncodeKeyVersionAsBytes

func (k *KeyVersion) EncodeKeyVersionAsBytes() []byte

EncodeKeyVersionAsBytes converts an object to a byte array

func (*KeyVersion) Equals

func (k *KeyVersion) Equals(other *KeyVersion) bool

Equals returns true if the value passed in matches the version.

func (*KeyVersion) EqualsRaw

func (k *KeyVersion) EqualsRaw(other uint32) bool

EqualsRaw returns true if the value passed in matches the version.

func (*KeyVersion) NextKeyVersion

func (k *KeyVersion) NextKeyVersion() *KeyVersion

NextKeyVersion creates a new key version

func (*KeyVersion) NotEquals

func (k *KeyVersion) NotEquals(other *KeyVersion) bool

NotEquals returns true if the value passed in does not match the version.

func (*KeyVersion) NotEqualsRaw

func (k *KeyVersion) NotEqualsRaw(other uint32) bool

NotEqualsRaw returns true if the value passed in does not match the version.

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