crypto

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPubkeyGroupNotSet occurs when the group public key
	// (master public key [mpk]) has not been set
	ErrPubkeyGroupNotSet = errors.New("groupPubk not set")

	// ErrPrivkNotSet occurs when the private key has not been set
	ErrPrivkNotSet = errors.New("privk not set")

	// ErrInvalidSignature occurs when signature validation fails
	ErrInvalidSignature = errors.New("signature validation failed")

	// ErrInvalidPubkeyShares occurs when multiple copies of the same public
	// key are contained when attempting to set GroupShares.
	ErrInvalidPubkeyShares = errors.New("groupShares contains repeated public keys")
)

Functions

func CalcThreshold

func CalcThreshold(n int) int

CalcThreshold returns the correct definition of threshold. With this definition, t+1 participants form a BFT subset. This ensures

t <= 2/3*n		and 	t + 1 > 2/3*n

func GetAccount

func GetAccount(pubk []byte) []byte

GetAccount returns the account, which corresponds to the rightmost 20 bytes of the hash of the public key.

func Hasher

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

Hasher is the default hasher and calls the hash function defined in our cloudflare library. It has 32 byte (256 bit) output.

Types

type BNGroupSigner

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

BNGroupSigner creates cryptographic signatures using the bn256 curve.

func (*BNGroupSigner) Aggregate

func (bns *BNGroupSigner) Aggregate(sigs [][]byte, groupShares [][]byte) ([]byte, error)

Aggregate attempts to combine the slice of signatures in sigs into a group signature.

func (*BNGroupSigner) PubkeyGroup

func (bns *BNGroupSigner) PubkeyGroup() ([]byte, error)

PubkeyGroup returns the marshalled public key of the group (master public key).

func (*BNGroupSigner) PubkeyShare

func (bns *BNGroupSigner) PubkeyShare() ([]byte, error)

PubkeyShare returns the marshalled public key of the BNGroupSigner

func (*BNGroupSigner) SetGroupPubk

func (bns *BNGroupSigner) SetGroupPubk(groupPubk []byte) error

SetGroupPubk will set the public key of the entire group; this is also called the master public key.

func (*BNGroupSigner) SetPrivk

func (bns *BNGroupSigner) SetPrivk(privk []byte)

SetPrivk sets the private key of the BNGroupSigner.

func (*BNGroupSigner) Sign

func (bns *BNGroupSigner) Sign(msg []byte) ([]byte, error)

Sign will generate a signature for msg using the private key of the BNGroupSigner; this signature can be aggregated to form a valid group signature.

func (*BNGroupSigner) VerifyGroupShares

func (bns *BNGroupSigner) VerifyGroupShares(groupShares [][]byte) error

VerifyGroupShares checks groupShares to ensure that it can be used as a valid ordering of the validators to correctly compute valid group signatures.

We first check to make sure that each public key is a valid element of bn256.G2. From there, we also check to make sure that the byte slice did not appear in a previous position; to do this, we use a hash map.

type BNGroupValidator

type BNGroupValidator struct {
}

BNGroupValidator is the object that performs cryptographic validation of BNGroupSigner signatures.

func (*BNGroupValidator) PubkeyFromSig

func (bnv *BNGroupValidator) PubkeyFromSig(sig []byte) ([]byte, error)

PubkeyFromSig returns the public key of the signer from the signature.

func (*BNGroupValidator) Validate

func (bnv *BNGroupValidator) Validate(msg []byte, sig []byte) ([]byte, error)

Validate will validate a BNGroupSigner signature or group signature for msg.

type BNSigner

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

BNSigner creates cryptographic signatures using the bn256 curve.

func (*BNSigner) Pubkey

func (bns *BNSigner) Pubkey() ([]byte, error)

Pubkey returns the marshalled public key of the BNSigner.

func (*BNSigner) SetPrivk

func (bns *BNSigner) SetPrivk(privk []byte)

SetPrivk sets the private key of the BNSigner.

func (*BNSigner) Sign

func (bns *BNSigner) Sign(msg []byte) ([]byte, error)

Sign will generate a signature for msg using the private key of the BNSigner.

type BNValidator

type BNValidator struct {
}

BNValidator is the object that performs cryptographic validation of BNSigner signatures.

func (*BNValidator) PubkeyFromSig

func (bnv *BNValidator) PubkeyFromSig(sig []byte) ([]byte, error)

PubkeyFromSig returns the public key of the signer from the signature.

func (*BNValidator) Validate

func (bnv *BNValidator) Validate(msg []byte, sig []byte) ([]byte, error)

Validate will validate a BNSigner signature for msg.

type Secp256k1Signer

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

Secp256k1Signer creates cryptographic signatures using the secp256k1 curve.

func (*Secp256k1Signer) Pubkey

func (secps *Secp256k1Signer) Pubkey() ([]byte, error)

Pubkey returns the marshalled public key of the Secp256k1Signer (uncompressed format).

func (*Secp256k1Signer) SetPrivk

func (secps *Secp256k1Signer) SetPrivk(privk []byte) error

SetPrivk sets the private key of the Secp256k1Signer; privk is required to be 32 bytes!

func (*Secp256k1Signer) Sign

func (secps *Secp256k1Signer) Sign(msg []byte) ([]byte, error)

Sign will generate a signature for msg using the private key of the Secp256k1Signer; eth.Sign *assumes* we are signing the *hash of the message* (digestHash) and *not* the message itself.

type Secp256k1Validator

type Secp256k1Validator struct {
}

Secp256k1Validator is a struct which allows for validation of cryptographic signatures from Secp256k1Signer.

func (*Secp256k1Validator) PubkeyFromSig

func (secpv *Secp256k1Validator) PubkeyFromSig(msg []byte, sig []byte) ([]byte, error)

PubkeyFromSig returns the public key of the signer from the signature and message.

func (*Secp256k1Validator) Validate

func (secpv *Secp256k1Validator) Validate(msg []byte, sig []byte) ([]byte, error)

Validate will validate a Secp256k1Signer signature for msg.

Directories

Path Synopsis
cloudflare
Package cloudflare implements a particular bilinear group at the 128-bit security level.
Package cloudflare implements a particular bilinear group at the 128-bit security level.

Jump to

Keyboard shortcuts

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