shcrypto

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const BlockSize = 32

BlockSize is the size in bytes of the blocks into which a message is split up before encryption.

Variables

View Source
var G1Comparer = gocmp.Comparer(EqualG1)
View Source
var G2Comparer = gocmp.Comparer(EqualG2)
View Source
var GTComparer = gocmp.Comparer(EqualGT)

Functions

func DegreeFromThreshold

func DegreeFromThreshold(threshold uint64) uint64

DegreeFromThreshold returns the degree polynomials should have for the given threshold.

func EqualG1

func EqualG1(p1, p2 *bn256.G1) bool

EqualG1 checks if two points on G1 are equal.

func EqualG2

func EqualG2(p1, p2 *bn256.G2) bool

EqualG2 checks if two points on G2 are equal.

func EqualGT

func EqualGT(p1, p2 *bn256.GT) bool

EqualGT checks if two points on GT are equal.

func HashBlockToInt

func HashBlockToInt(d Block) *big.Int

HashBlockToInt hashes a block and returns the result as an integer in Z_q.

func KeyperX

func KeyperX(keyperIndex int) *big.Int

KeyperX computes the x value assigned to the keyper identified by its index.

func Shuffle

func Shuffle(txs [][]byte, key *EpochSecretKey) [][]byte

Shuffle shuffles the order of the transactions using the epoch secret key as a source of randomness.

func UnpadMessage

func UnpadMessage(blocks []Block) ([]byte, error)

UnpadMessage returns the message provided in padded form as a sequence of blocks.

func ValidEval

func ValidEval(v *big.Int) bool

ValidEval checks if the given value is a valid polynomial evaluation, i.e., if it is in Z_q.

func VerifyEpochSecretKeyShare

func VerifyEpochSecretKeyShare(epochSecretKeyShare *EpochSecretKeyShare, eonPublicKeyShare *EonPublicKeyShare, epochID *EpochID) bool

VerifyEpochSecretKeyShare checks that an epoch sk share published by a keyper is correct.

func VerifyPolyEval

func VerifyPolyEval(keyperIndex int, polyEval *big.Int, gammas *Gammas, threshold uint64) bool

VerifyPolyEval checks that the evaluation of a polynomial is consistent with the public gammas.

Types

type Block

type Block [BlockSize]byte

Block represents a block of data.

func HashBytesToBlock

func HashBytesToBlock(d ...[]byte) Block

HashBytesToBlock hashes the given byte slice and returns the result as a block.

func HashGTToBlock

func HashGTToBlock(gt *bn256.GT) Block

HashGTToBlock hashes an element of GT and returns the result as a block.

func PadMessage

func PadMessage(m []byte) []Block

PadMessage pads a message and returns it as a sequence of blocks. Implements PKCS #7 according to https://www.ietf.org/rfc/rfc2315.txt

func RandomSigma

func RandomSigma(r io.Reader) (Block, error)

RandomSigma returns a random value to be used during encryption.

func XORBlocks

func XORBlocks(b1 Block, b2 Block) Block

XORBlocks xors the two blocks and returns the result.

type EncryptedMessage

type EncryptedMessage struct {
	C1 *bn256.G2
	C2 Block
	C3 []Block
}

EncryptedMessage represents the full output of the encryption procedure.

func Encrypt

func Encrypt(message []byte, eonPublicKey *EonPublicKey, epochID *EpochID, sigma Block) *EncryptedMessage

Encrypt encrypts a message for the epoch given by its id. It uses the eon public key and randomness provided in sigma.

func (*EncryptedMessage) Decrypt

func (m *EncryptedMessage) Decrypt(epochSecretKey *EpochSecretKey) ([]byte, error)

Decrypt decrypts the given message using the given epoch secret key.

func (*EncryptedMessage) Marshal

func (m *EncryptedMessage) Marshal() []byte

Marshal serializes the EncryptedMessage object. It panics, if C1 is nil.

func (*EncryptedMessage) Sigma

func (m *EncryptedMessage) Sigma(epochSecretKey *EpochSecretKey) Block

Sigma computes the sigma value of the encrypted message given the epoch secret key.

func (*EncryptedMessage) Unmarshal

func (m *EncryptedMessage) Unmarshal(d []byte) error

Unmarshal deserializes an EncryptedMessage from the given byte slice.

type EonPublicKey

type EonPublicKey bn256.G2

EonPublicKey represents the combined eon public key.

func ComputeEonPublicKey

func ComputeEonPublicKey(gammas []*Gammas) *EonPublicKey

ComputeEonPublicKey computes the combined eon public key from the set of eon public key shares.

func (*EonPublicKey) Equal

func (eonpubkey *EonPublicKey) Equal(pk2 *EonPublicKey) bool

func (*EonPublicKey) GobDecode

func (eonpubkey *EonPublicKey) GobDecode(data []byte) error

func (*EonPublicKey) GobEncode

func (eonpubkey *EonPublicKey) GobEncode() ([]byte, error)

func (*EonPublicKey) Marshal

func (eonpubkey *EonPublicKey) Marshal() []byte

Marshal serialized the eon public key.

func (*EonPublicKey) Unmarshal

func (eonpubkey *EonPublicKey) Unmarshal(m []byte) error

Unmarshal deserializes an eon public key from the given byte slice.

type EonPublicKeyShare

type EonPublicKeyShare bn256.G2

EonPublicKeyShare represents a share of the eon public key.

func ComputeEonPublicKeyShare

func ComputeEonPublicKeyShare(keyperIndex int, gammas []*Gammas) *EonPublicKeyShare

ComputeEonPublicKeyShare computes the eon public key share of the given keyper.

func (*EonPublicKeyShare) Equal

func (g2 *EonPublicKeyShare) Equal(pk2 *EonPublicKeyShare) bool

func (*EonPublicKeyShare) GobDecode

func (g2 *EonPublicKeyShare) GobDecode(data []byte) error

func (*EonPublicKeyShare) GobEncode

func (g2 *EonPublicKeyShare) GobEncode() ([]byte, error)

type EonSecretKeyShare

type EonSecretKeyShare big.Int

EonSecretKeyShare represents a share of the eon secret key.

func ComputeEonSecretKeyShare

func ComputeEonSecretKeyShare(polyEvals []*big.Int) *EonSecretKeyShare

ComputeEonSecretKeyShare computes the keyper's secret key share from the set of poly evals received from the other keypers.

func (*EonSecretKeyShare) Equal

func (esks *EonSecretKeyShare) Equal(e2 *EonSecretKeyShare) bool

func (*EonSecretKeyShare) GobDecode

func (esks *EonSecretKeyShare) GobDecode(data []byte) error

func (*EonSecretKeyShare) GobEncode

func (esks *EonSecretKeyShare) GobEncode() ([]byte, error)

type EpochID

type EpochID bn256.G1

EpochID is the identifier of an epoch.

func ComputeEpochID

func ComputeEpochID(epochIndex uint64) *EpochID

ComputeEpochID computes the id of the given epoch.

func (*EpochID) Equal

func (g *EpochID) Equal(g2 *EpochID) bool

func (*EpochID) GobDecode

func (g *EpochID) GobDecode(data []byte) error

func (*EpochID) GobEncode

func (g *EpochID) GobEncode() ([]byte, error)

type EpochSecretKey

type EpochSecretKey bn256.G1

EpochSecretKey represents an epoch secret key.

func ComputeEpochSecretKey

func ComputeEpochSecretKey(keyperIndices []int, epochSecretKeyShares []*EpochSecretKeyShare, threshold uint64) (*EpochSecretKey, error)

ComputeEpochSecretKey computes the epoch secret key from a set of shares.

func (*EpochSecretKey) Equal

func (g *EpochSecretKey) Equal(g2 *EpochSecretKey) bool

func (*EpochSecretKey) GobDecode

func (g *EpochSecretKey) GobDecode(data []byte) error

func (*EpochSecretKey) GobEncode

func (g *EpochSecretKey) GobEncode() ([]byte, error)

type EpochSecretKeyShare

type EpochSecretKeyShare bn256.G1

EpochSecretKeyShare represents a keyper's share of the epoch sk key.

func ComputeEpochSecretKeyShare

func ComputeEpochSecretKeyShare(eonSecretKeyShare *EonSecretKeyShare, epochID *EpochID) *EpochSecretKeyShare

ComputeEpochSecretKeyShare computes a keyper's epoch sk share.

func (*EpochSecretKeyShare) Equal

func (*EpochSecretKeyShare) GobDecode

func (g *EpochSecretKeyShare) GobDecode(data []byte) error

func (*EpochSecretKeyShare) GobEncode

func (g *EpochSecretKeyShare) GobEncode() ([]byte, error)

type Gammas

type Gammas []*bn256.G2

Gammas is a sequence of G2 points based on a polynomial.

func ZeroGammas

func ZeroGammas(degree uint64) *Gammas

ZeroGammas returns the zero value for gammas.

func (*Gammas) Degree

func (g *Gammas) Degree() uint64

Degree returns the degree of the underlying polynomial.

func (Gammas) Equal

func (g Gammas) Equal(g2 Gammas) bool

func (*Gammas) GobDecode

func (g *Gammas) GobDecode(data []byte) error

GobDecode decodes a Gammas value. See https://golang.org/pkg/encoding/gob/#GobDecoder

func (*Gammas) GobEncode

func (g *Gammas) GobEncode() ([]byte, error)

GobEncode encodes a Gammas value. See https://golang.org/pkg/encoding/gob/#GobEncoder

func (*Gammas) Pi

func (g *Gammas) Pi(xi *big.Int) *bn256.G2

Pi computes the pi value at the given x coordinate.

type Polynomial

type Polynomial []*big.Int

Polynomial represents a polynomial over Z_q.

func NewPolynomial

func NewPolynomial(coefficients []*big.Int) (*Polynomial, error)

NewPolynomial creates a new polynomial from the given coefficients. It verifies the number and range of them.

func RandomPolynomial

func RandomPolynomial(r io.Reader, degree uint64) (*Polynomial, error)

RandomPolynomial generates a random polynomial of given degree.

func (*Polynomial) Degree

func (p *Polynomial) Degree() uint64

Degree returns the degree of the polynomial.

func (*Polynomial) Eval

func (p *Polynomial) Eval(x *big.Int) *big.Int

Eval evaluates the polynomial at the given coordinate.

func (*Polynomial) EvalForKeyper

func (p *Polynomial) EvalForKeyper(keyperIndex int) *big.Int

EvalForKeyper evaluates the polynomial at the position designated for the given keyper.

func (*Polynomial) Gammas

func (p *Polynomial) Gammas() *Gammas

Gammas computes the gamma values for a given polynomial.

Jump to

Keyboard shortcuts

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