shcrypto

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 11 Imported by: 13

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.

View Source
const VersionIdentifier byte = 0x02

Variables

View Source
var (
	ErrInputTooLong             = errors.New("input too long")
	ErrInvalidEonSecretKeyShare = errors.New("invalid eon secret key share")
	ErrVersionMismatch          = func(version_got byte) error {
		return fmt.Errorf("version mismatch. want %d got %d", VersionIdentifier, version_got)
	}
)

Functions

func DegreeFromThreshold

func DegreeFromThreshold(threshold uint64) uint64

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

func Hash1 added in v0.1.16

func Hash1(b []byte) *bls12381.PointG1

func Hash3 added in v0.1.16

func Hash3(b []byte) *big.Int

func IdentifyVersion added in v0.1.17

func IdentifyVersion(d []byte) byte

IdentifyVersion reads the version identifier byte from the given (marshaled) EncryptedMessage.

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 Uint64toBytes added in v0.1.13

func Uint64toBytes(i uint64) ([]byte, int)

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 VerifyEpochSecretKey added in v0.1.8

func VerifyEpochSecretKey(epochSecretKey *EpochSecretKey, eonPublicKey *EonPublicKey, epochIDBytes []byte) (bool, error)

VerifyEpochSecretKey checks that an epoch secret key is the correct key for an epoch given the eon public key.

func VerifyEpochSecretKeyDeterministic added in v0.1.14

func VerifyEpochSecretKeyDeterministic(epochSecretKey *EpochSecretKey, eonPublicKey *EonPublicKey, epochIDBytes []byte, sigma Block, message []byte) (bool, error)

VerifyEpochSecretKeyDeterministic checks that an epoch secret key is the correct key for an epoch given the eon public key and random inputs for sigma and message.

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 DecryptBlocks added in v0.1.12

func DecryptBlocks(encryptedBlocks []Block, sigma Block) []Block

func Hash2 added in v0.1.16

func Hash2(gt *bls12381.E) Block

func Hash4 added in v0.1.16

func Hash4(b []byte) 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.

func (Block) MarshalText added in v0.1.12

func (block Block) MarshalText() ([]byte, error)

MarshalText serializes the block to hex.

func (*Block) UnmarshalText added in v0.1.12

func (block *Block) UnmarshalText(b []byte) error

UnmarshalText deserializes the block from hex.

type EncryptedMessage

type EncryptedMessage struct {
	C1 *bls12381.PointG2
	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) MarshalText added in v0.1.12

func (m EncryptedMessage) MarshalText() ([]byte, error)

MarshalText serializes the encrypted message to hex.

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.

func (*EncryptedMessage) UnmarshalText added in v0.1.12

func (m *EncryptedMessage) UnmarshalText(b []byte) error

UnmarshalText deserializes the encrypted message from hex.

type EonPublicKey

type EonPublicKey bls12381.PointG2

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 (eonPublicKey *EonPublicKey) Equal(pk2 *EonPublicKey) bool

func (*EonPublicKey) GobDecode

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

func (*EonPublicKey) GobEncode

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

func (*EonPublicKey) Marshal

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

Marshal serializes the eon public key.

func (EonPublicKey) MarshalText added in v0.1.12

func (eonPublicKey EonPublicKey) MarshalText() ([]byte, error)

MarshalText serializes the eon public key to hex.

func (*EonPublicKey) Unmarshal

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

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

func (*EonPublicKey) UnmarshalText added in v0.1.12

func (eonPublicKey *EonPublicKey) UnmarshalText(input []byte) error

UnmarshalText deserializes the eon public key from hex.

type EonPublicKeyShare

type EonPublicKeyShare bls12381.PointG2

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 (eonPublicKeyShare *EonPublicKeyShare) Equal(pk2 *EonPublicKeyShare) bool

func (*EonPublicKeyShare) GobDecode

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

func (*EonPublicKeyShare) GobEncode

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

func (*EonPublicKeyShare) Marshal added in v0.1.9

func (eonPublicKeyShare *EonPublicKeyShare) Marshal() []byte

Marshal serializes the eon public key share.

func (*EonPublicKeyShare) Unmarshal added in v0.1.9

func (eonPublicKeyShare *EonPublicKeyShare) Unmarshal(m []byte) error

Unmarshal deserializes an eon public key share.

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 (eonSecretKeyShare *EonSecretKeyShare) Equal(e2 *EonSecretKeyShare) bool

func (*EonSecretKeyShare) GobDecode

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

func (*EonSecretKeyShare) GobEncode

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

func (*EonSecretKeyShare) Marshal added in v0.1.9

func (eonSecretKeyShare *EonSecretKeyShare) Marshal() []byte

Marshal serializes the eon secret key share.

func (*EonSecretKeyShare) Unmarshal added in v0.1.9

func (eonSecretKeyShare *EonSecretKeyShare) Unmarshal(m []byte) error

Unarshal deserializes an eon secret key share.

type EpochID

type EpochID bls12381.PointG1

EpochID is the identifier of an epoch.

func ComputeEpochID

func ComputeEpochID(epochIDBytes []byte) *EpochID

ComputeEpochID computes the id of the given epoch.

func (*EpochID) Equal

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

func (*EpochID) GobDecode

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

func (*EpochID) GobEncode

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

func (*EpochID) Marshal added in v0.1.9

func (epochID *EpochID) Marshal() []byte

Marshal serializes the epoch id.

func (*EpochID) Unmarshal added in v0.1.9

func (epochID *EpochID) Unmarshal(m []byte) error

Unmarshal deserializes an epoch id.

type EpochSecretKey

type EpochSecretKey bls12381.PointG1

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 (epochSecretKey *EpochSecretKey) Equal(g2 *EpochSecretKey) bool

func (*EpochSecretKey) GobDecode

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

func (*EpochSecretKey) GobEncode

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

func (*EpochSecretKey) Marshal added in v0.1.9

func (epochSecretKey *EpochSecretKey) Marshal() []byte

Marshal serializes the epoch secret key.

func (EpochSecretKey) MarshalText added in v0.1.12

func (epochSecretKey EpochSecretKey) MarshalText() ([]byte, error)

MarshalText serializes the epoch secret key to hex.

func (*EpochSecretKey) Unmarshal added in v0.1.9

func (epochSecretKey *EpochSecretKey) Unmarshal(m []byte) error

Unmarshal deserializes an epoch secret key.

func (*EpochSecretKey) UnmarshalText added in v0.1.12

func (epochSecretKey *EpochSecretKey) UnmarshalText(input []byte) error

UnmarshalText deserializes the epoch secret key from hex.

type EpochSecretKeyShare

type EpochSecretKeyShare bls12381.PointG1

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 *EpochSecretKeyShare) Equal(g2 *EpochSecretKeyShare) bool

func (*EpochSecretKeyShare) GobDecode

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

func (*EpochSecretKeyShare) GobEncode

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

func (*EpochSecretKeyShare) Marshal added in v0.1.9

func (epochSecretKeyShare *EpochSecretKeyShare) Marshal() []byte

Marshal serializes the epoch secret key share.

func (*EpochSecretKeyShare) Unmarshal added in v0.1.9

func (epochSecretKeyShare *EpochSecretKeyShare) Unmarshal(m []byte) error

Unmarshal deserializes an epoch secret key share.

type Gammas

type Gammas []*bls12381.PointG2

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(otherG 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) *bls12381.PointG2

Pi computes the pi value at the given x coordinate.

type LagrangeCoeffs added in v0.1.11

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

LagrangeCoeffs stores the lagrange coefficients that are needed to compute an epoch secret key for a certain array of keypers. We use this to speedup epoch secret key generation.

func NewLagrangeCoeffs added in v0.1.11

func NewLagrangeCoeffs(keyperIndices []int) *LagrangeCoeffs

NewLagrangeCoeffs computes the lagrange coefficients for the given array of keypers.

func (*LagrangeCoeffs) ComputeEpochSecretKey added in v0.1.11

func (lc *LagrangeCoeffs) ComputeEpochSecretKey(epochSecretKeyShares []*EpochSecretKeyShare) (*EpochSecretKey, error)

ComputeEpochSecretKey computes the epoch secret key given the secret key shares of the keypers. The caller has to ensure that the secret shares match the keyperIndices used during initialisation.

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.

type TestKeyGen added in v0.1.15

type TestKeyGen struct {
	EonPublicKey *EonPublicKey
	// contains filtered or unexported fields
}

func NewTestKeyGen added in v0.1.15

func NewTestKeyGen() (*TestKeyGen, error)

func (*TestKeyGen) ComputeEpochSecretKey added in v0.1.15

func (g *TestKeyGen) ComputeEpochSecretKey(epochID *EpochID) (*EpochSecretKey, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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