Documentation ¶
Overview ¶
Package fcrcrypto - location for cryptographic tools to perform common operations on hashes, keys and signatures
Index ¶
- Constants
- func BlockchainHash(data []byte) []byte
- func GeneratePrivateRandomBytes(b []byte)
- func GeneratePublicRandomBytes(b []byte)
- func GetBlockchainHasher() hash.Hash
- func GetRetrievalV1Hasher() hash.Hash
- func PRNGEntropyKick()
- func RetrievalV1Hash(data []byte) []byte
- func RetrievalV1Verify(signature, toBeSigned, hashedPublicKey []byte) (bool, error)
- func SignMessage(pKey *KeyPair, keyVersion *KeyVersion, msg []byte) (string, error)
- func VerifyMessage(pubKey *KeyPair, signature string, msg []byte) (bool, error)
- type KeyPair
- func (k *KeyPair) EncodePrivateKey() string
- func (k *KeyPair) EncodePublicKey() (string, error)
- func (k *KeyPair) EncodeRawPrivateKey() (string, error)
- func (k *KeyPair) HashPublicKey() ([]byte, error)
- func (k KeyPair) MarshalJSON() ([]byte, error)
- func (k *KeyPair) Sign(toBeSigned []byte) ([]byte, error)
- func (k *KeyPair) UnmarshalJSON(p []byte) error
- func (k *KeyPair) Verify(signature, toBeSigned []byte) (bool, error)
- type KeySigAlg
- type KeyVersion
- func (k *KeyVersion) EncodeKeyVersion() uint32
- func (k *KeyVersion) EncodeKeyVersionAsBytes() []byte
- func (k *KeyVersion) Equals(other *KeyVersion) bool
- func (k *KeyVersion) EqualsRaw(other uint32) bool
- func (k *KeyVersion) NextKeyVersion() *KeyVersion
- func (k *KeyVersion) NotEquals(other *KeyVersion) bool
- func (k *KeyVersion) NotEqualsRaw(other uint32) bool
- type Random
Constants ¶
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 ¶
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 ¶
GetBlockchainHasher returns a message digest implementation that hashes according to the algorithms used by the Filecoin blockchain.
func GetRetrievalV1Hasher ¶
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 ¶
RetrievalV1Hash message digests some data using the algorithm used by version one of the Filecoin retrieval protocol.
func RetrievalV1Verify ¶
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"
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 ¶
DecodePrivateKey decodes the algorithm and private key from a hex string.
func DecodePublicKey ¶
DecodePublicKey decodes the algorithm and public key from a hex string.
func DecodeRawPrivateKey ¶
DecodeRawPrivateKey decodes the private key from a hex string, and assumes the key algorithm is the default one for Filecoin: SigAlgEcdsaSecP256K1Blake2b
func GenerateBlockchainKeyPair ¶
GenerateBlockchainKeyPair generates a key pair for use with the Filecoin blockchain
func GenerateRetrievalV1KeyPair ¶
GenerateRetrievalV1KeyPair generates a key pair for use with v1 of the Filecoin Retrieval protocol.
func (*KeyPair) EncodePrivateKey ¶
EncodePrivateKey encodes the algorithm and private key as a hex string.
func (*KeyPair) EncodePublicKey ¶
EncodePublicKey encodes the algorithm and public key as a hex string.
func (*KeyPair) EncodeRawPrivateKey ¶
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 ¶
HashPublicKey generates a message digest that matches the public key.
func (KeyPair) MarshalJSON ¶
MarshalJSON is used to marshal public Keypair into bytes
func (*KeyPair) UnmarshalJSON ¶
UnmarshalJSON is used to unmarshal bytes into Keypair
type KeySigAlg ¶
type KeySigAlg struct {
// contains filtered or unexported fields
}
KeySigAlg is holds the signature algorithm
func DecodeSigAlg ¶
DecodeSigAlg converts a number to an object.
func DecodeSigAlgFromBytes ¶
DecodeSigAlgFromBytes converts bytes to an object
func (*KeySigAlg) EncodeSigAlg ¶
EncodeSigAlg converts a number to an object.
func (*KeySigAlg) EncodeSigAlgAsBytes ¶
EncodeSigAlgAsBytes converts an object to bytes.
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 ¶
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 ¶
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.