Skip to content

Commit

Permalink
fixup! homomorphic: big refactor, renamed homomorphic -> elgamal
Browse files Browse the repository at this point in the history
add method Ciphertext.Select
  • Loading branch information
altergui committed Dec 9, 2024
1 parent da1f17a commit 421cc1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions elgamal/add.go → elgamal/ciphertext.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import (
ecc_tweds "github.com/consensys/gnark-crypto/ecc/twistededwards"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/std/algebra/native/twistededwards"
"github.com/iden3/go-iden3-crypto/babyjub"
)

type Ciphertext struct {
C1, C2 twistededwards.Point
}

func NewCiphertext() *Ciphertext {
zero := babyjub.NewPoint()
return &Ciphertext{C1: twistededwards.Point{X: zero.X, Y: zero.Y}, C2: twistededwards.Point{X: zero.X, Y: zero.Y}}
}

// Add sets z to the sum x+y and returns z.
//
// Panics if twistededwards curve init fails.
Expand All @@ -33,3 +39,12 @@ func (z *Ciphertext) AssertIsEqual(api frontend.API, x *Ciphertext) {
api.AssertIsEqual(z.C2.X, x.C2.X)
api.AssertIsEqual(z.C2.Y, x.C2.Y)
}

// Select if b is true, sets z = i1, else z = i2, and returns z
func (z *Ciphertext) Select(api frontend.API, b frontend.Variable, i1 *Ciphertext, i2 *Ciphertext) *Ciphertext {
z.C1.X = api.Select(b, i1.C1.X, i2.C1.X)
z.C1.Y = api.Select(b, i1.C1.Y, i2.C1.Y)
z.C2.X = api.Select(b, i1.C2.X, i2.C2.X)
z.C2.Y = api.Select(b, i1.C2.Y, i2.C2.Y)
return z
}
File renamed without changes.

0 comments on commit 421cc1e

Please sign in to comment.