Documentation
¶
Index ¶
- Constants
- func BabyStepGiantStepECC(M, G ecc.Point, maxMessage uint64) (*big.Int, error)
- func CheckK(c1 ecc.Point, k *big.Int) bool
- func Decrypt(publicKey ecc.Point, privateKey *big.Int, c1, c2 ecc.Point, maxMessage uint64) (M ecc.Point, message *big.Int, err error)
- func Encrypt(publicKey ecc.Point, msg *big.Int) (ecc.Point, ecc.Point, *big.Int, error)
- func EncryptWithK(pubKey ecc.Point, msg, k *big.Int) (ecc.Point, ecc.Point, error)
- func GenerateKey(curve ecc.Point) (publicKey ecc.Point, privateKey *big.Int, err error)
- func RandK() (*big.Int, error)
- type Ballot
- func (z *Ballot) Add(x, y *Ballot) *Ballot
- func (z *Ballot) BigInts() []*big.Int
- func (z *Ballot) Deserialize(data []byte) error
- func (z *Ballot) Encrypt(message [circuits.FieldsPerBallot]*big.Int, publicKey ecc.Point, k *big.Int) (*Ballot, error)
- func (z *Ballot) MarshalCBOR() ([]byte, error)
- func (z *Ballot) MarshalJSON() ([]byte, error)
- func (z *Ballot) Serialize() []byte
- func (z *Ballot) String() string
- func (z *Ballot) ToGnark() *circuits.Ballot
- func (z *Ballot) ToGnarkEmulatedBN254() *circuits.EmulatedBallot[sw_bn254.ScalarField]
- func (z *Ballot) UnmarshalCBOR(buf []byte) error
- func (z *Ballot) UnmarshalJSON(data []byte) error
- type Ciphertext
- func (z *Ciphertext) Add(x, y *Ciphertext) *Ciphertext
- func (z *Ciphertext) Deserialize(data []byte) error
- func (z *Ciphertext) Encrypt(message *big.Int, publicKey ecc.Point, k *big.Int) (*Ciphertext, error)
- func (z *Ciphertext) MarshalCBOR() ([]byte, error)
- func (z *Ciphertext) MarshalJSON() ([]byte, error)
- func (z *Ciphertext) Serialize() []byte
- func (z *Ciphertext) String() string
- func (z *Ciphertext) ToGnark() *gelgamal.Ciphertext
- func (z *Ciphertext) UnmarshalCBOR(buf []byte) error
- func (z *Ciphertext) UnmarshalJSON(data []byte) error
Constants ¶
const BigIntsPerCiphertext = 4
BigIntsPerCiphertext is 4 since each Ciphertext has C1.X, C1.Y, C2.X and C2.Y coords
const (
SerializedBallotSize = circuits.FieldsPerBallot * sizeCiphertext
)
sizes in bytes needed to serialize a Ballot
Variables ¶
This section is empty.
Functions ¶
func BabyStepGiantStepECC ¶
BabyStepGiantStepECC solves M = x*G for x in [0, maxMessage] using the baby-step giant-step algorithm over elliptic curves.
func CheckK ¶
CheckK checks if a given k was used to produce the ciphertext (c1, c2) under the given publicKey. It returns true if c1 == k * G, false otherwise. This does not require decrypting the message or computing the discrete log.
func Decrypt ¶
func Decrypt(publicKey ecc.Point, privateKey *big.Int, c1, c2 ecc.Point, maxMessage uint64) (M ecc.Point, message *big.Int, err error)
Decrypt decrypts the given ciphertext (c1, c2) using the private key. It returns the point M = c2 - d*c1 and the discrete log message scalar. If no solution is found, returns an error.
func Encrypt ¶
Encrypt function encrypts a message using the public key provided as elliptic curve point. It generates a random k and returns the two points that represent the encrypted message and the random k used to encrypt it. It returns an error if any.
func EncryptWithK ¶
EncryptWithK function encrypts a message using the public key provided as elliptic curve point and the random k value provided. It returns the two points that represent the encrypted message and error if any.
TODO: remove error return, since it can never error
func GenerateKey ¶
GenerateKey generates a new public/private ElGamal encryption key pair.
Types ¶
type Ballot ¶
type Ballot struct { CurveType string `json:"curveType"` Ciphertexts [circuits.FieldsPerBallot]*Ciphertext `json:"ciphertexts"` }
func (*Ballot) Add ¶
Add adds two Ballots and stores the result in the receiver, which is also returned.
func (*Ballot) BigInts ¶
BigInts returns a slice with 8*4 BigInts, namely the coords of each Ciphertext C1.X, C1.Y, C2.X, C2.Y as little-endian, in reduced twisted edwards form.
func (*Ballot) Deserialize ¶
Deserialize reconstructs a Ballot from a slice of bytes. The input must be of len N*4*32 bytes (otherwise it returns an error), representing each Ciphertext C1.X, C1.Y, C2.X, C2.Y as little-endian, in reduced twisted edwards form.
func (*Ballot) Encrypt ¶
func (z *Ballot) Encrypt(message [circuits.FieldsPerBallot]*big.Int, publicKey ecc.Point, k *big.Int) (*Ballot, error)
Encrypt encrypts a message using the public key provided as elliptic curve point. The randomness k can be provided or nil to generate a new one.
func (*Ballot) MarshalCBOR ¶
MarshalCBOR serializes the Ballot to CBOR.
func (*Ballot) MarshalJSON ¶
MarshalJSON serializes the Ballot to JSON.
func (*Ballot) Serialize ¶
Serialize returns a slice of len N*4*32 bytes, representing each Ciphertext C1.X, C1.Y, C2.X, C2.Y as little-endian, in reduced twisted edwards form.
func (*Ballot) ToGnark ¶
ToGnark returns z as the struct used by gnark, with the points in reduced twisted edwards format
func (*Ballot) ToGnarkEmulatedBN254 ¶
func (z *Ballot) ToGnarkEmulatedBN254() *circuits.EmulatedBallot[sw_bn254.ScalarField]
ToGnarkEmulatedBN254 returns z as the struct used by gnark, with the points in reduced twisted edwards format but as emulated.Element[sw_bn254.ScalarField] instead of frontend.Variable
func (*Ballot) UnmarshalCBOR ¶
UnmarshalCBOR deserializes the Ballot from CBOR.
func (*Ballot) UnmarshalJSON ¶
UnmarshalJSON deserializes the Ballot from JSON.
type Ciphertext ¶
Ciphertext represents an ElGamal encrypted message with homomorphic properties. It is a wrapper for convenience of the elGamal ciphersystem that encapsulates the two points of a ciphertext.
func NewCiphertext ¶
func NewCiphertext(curve ecc.Point) *Ciphertext
NewCiphertext creates a new Ciphertext on the same curve as the given Point. The Point must be one on of the supported curves by crypto/ecc/curves package, can be easily created with curves.New(type)
func (*Ciphertext) Add ¶
func (z *Ciphertext) Add(x, y *Ciphertext) *Ciphertext
Add adds two Ciphertext and stores the result in z, which is also returned.
func (*Ciphertext) Deserialize ¶
func (z *Ciphertext) Deserialize(data []byte) error
Deserialize reconstructs an Ciphertext from a slice of bytes. The input must be of len 4*32 bytes (otherwise it returns an error), representing the C1.X, C1.Y, C2.X, C2.Y as little-endian, in reduced twisted edwards form.
func (*Ciphertext) Encrypt ¶
func (z *Ciphertext) Encrypt(message *big.Int, publicKey ecc.Point, k *big.Int) (*Ciphertext, error)
Encrypt encrypts a message using the public key provided as elliptic curve point. The randomness k can be provided or nil to generate a new one.
func (*Ciphertext) MarshalCBOR ¶
func (z *Ciphertext) MarshalCBOR() ([]byte, error)
MarshalCBOR serializes the Ciphertext to CBOR.
func (*Ciphertext) MarshalJSON ¶
func (z *Ciphertext) MarshalJSON() ([]byte, error)
MarshalJSON serializes the Ciphertext to JSON.
func (*Ciphertext) Serialize ¶
func (z *Ciphertext) Serialize() []byte
Serialize returns a slice of len 4*32 bytes, representing the C1.X, C1.Y, C2.X, C2.Y as little-endian, in reduced twisted edwards form.
func (*Ciphertext) String ¶
func (z *Ciphertext) String() string
String returns a string representation of the Ciphertext.
func (*Ciphertext) ToGnark ¶
func (z *Ciphertext) ToGnark() *gelgamal.Ciphertext
ToGnark returns z as the struct used by gnark, with the points in reduced twisted edwards format
func (*Ciphertext) UnmarshalCBOR ¶
func (z *Ciphertext) UnmarshalCBOR(buf []byte) error
UnmarshalCBOR deserializes the Ciphertext from CBOR.
func (*Ciphertext) UnmarshalJSON ¶
func (z *Ciphertext) UnmarshalJSON(data []byte) error
UnmarshalJSON deserializes the Ciphertext from JSON.