diff options
author | Özgür Kesim <oec@kesim.org> | 2024-03-21 20:12:42 +0100 |
---|---|---|
committer | Özgür Kesim <oec@kesim.org> | 2024-03-21 20:12:42 +0100 |
commit | 3ba341e3c464e7a92bc99fd7d8bde65737c1aac9 (patch) | |
tree | 699c7215c1ce904591cc6a9fb2c8dd2e0265e20f | |
parent | 8eeb35615f0483e21dc48f96877a2681cf48b1ec (diff) |
veto, curve: slight refactor
- Mult -> Mul
- newVoteWithRand uses input rand io.Reader again.
-rw-r--r-- | curve/curve.go | 6 | ||||
-rw-r--r-- | curve/ed25519.go | 6 | ||||
-rw-r--r-- | veto/veto.go | 23 |
3 files changed, 20 insertions, 15 deletions
diff --git a/curve/curve.go b/curve/curve.go index 75626bd..36c9eed 100644 --- a/curve/curve.go +++ b/curve/curve.go @@ -12,7 +12,7 @@ type Data interface { type SomeScalar[S Data] interface { Add(S) S Sub(S) S - Mult(S) S + Mul(S) S Equal(S) bool // Maybe later: @@ -36,7 +36,7 @@ type SomeCurve[S SomeScalar[s], s Data, P SomePoint[S, s, p], p Data] interface } type SomePoint[S SomeScalar[s], s Data, P Data] interface { - Mult(P) P + Mul(P) P Div(P) P Inv() P Exp(S) P @@ -60,4 +60,4 @@ type APoint[S SomeScalar[s], s Data, P Data] interface { ScalarMult(S) P Equal(P) bool } -*/
\ No newline at end of file +*/ diff --git a/curve/ed25519.go b/curve/ed25519.go index 6d7e1a0..3d0ba81 100644 --- a/curve/ed25519.go +++ b/curve/ed25519.go @@ -46,7 +46,7 @@ func (s *scalar) Sub(t *scalar) *scalar { return (*scalar)(new(ed.Scalar).Subtract((*ed.Scalar)(s), (*ed.Scalar)(t))) } -func (s *scalar) Mult(t *scalar) *scalar { +func (s *scalar) Mul(t *scalar) *scalar { return (*scalar)(new(ed.Scalar).Multiply((*ed.Scalar)(s), (*ed.Scalar)(t))) } @@ -89,7 +89,7 @@ func (c *c25519) Generator() *point { func (c *c25519) Product(pts []*point) (product *point) { product = c.Identity() for _, p := range pts { - product = product.Mult(p) + product = product.Mul(p) } return product } @@ -105,7 +105,7 @@ func (p *point) Bytes() []byte { } // Return p (*) q in group -func (p *point) Mult(q *point) *point { +func (p *point) Mul(q *point) *point { r := new(ed.Point).Add((*ed.Point)(p), (*ed.Point)(q)) return (*point)(r) } diff --git a/veto/veto.go b/veto/veto.go index 6a64c82..2b164bc 100644 --- a/veto/veto.go +++ b/veto/veto.go @@ -83,7 +83,7 @@ func proof(x *Scalar, id *Point) (pr *Proof, e error) { } // Calculate r := v - x*h - xh := x.Mult(h) + xh := x.Mul(h) r := v.Sub(xh) pr.Sr = r @@ -130,7 +130,7 @@ func verifyProof(V *Point, Gx *Point, r *Scalar, id *Point) (ok bool) { gr := Curve.Exp(r) // Calculate g^r*g^(x*h) - grgxh := gr.Mult(gxh) + grgxh := gr.Mul(gxh) // Return true if g^v == g^r*g^(x*h) return V.Equal(grgxh) @@ -150,11 +150,16 @@ func newVoteWithRand(veto bool, rand io.Reader) (v *Vote, e error) { veto: veto, } - v.private.id = Curve.RandomScalar() - v.private.x = Curve.RandomScalar() - v.private.r = Curve.RandomScalar() + var e1, e2, e3 error - var e1, e2 error + v.private.id, e1 = Curve.ScalarFromReader(rand) + v.private.x, e2 = Curve.ScalarFromReader(rand) + v.private.r, e3 = Curve.ScalarFromReader(rand) + + e = combineErr(e1, e2, e3) + if e != nil { + return nil, e + } c := new(Commitment) v.com = c @@ -194,7 +199,7 @@ type coms []*Commitment func (coms coms) prod() (product *Point) { product = Curve.Identity() for _, com := range coms { - product = product.Mult(com.Points.X) + product = product.Mul(com.Points.X) } return product } @@ -204,7 +209,7 @@ func (coms coms) prod() (product *Point) { func (coms coms) computeGy(index int) *Point { gy1 := coms[:index].prod() gy2 := coms[index+1:].prod().Inv() - return gy1.Mult(gy2) + return gy1.Mul(gy2) } // Round2 implements the round 2 of the AV-Net protocol, where a participant @@ -249,4 +254,4 @@ func (pts points) IsVetoed() bool { product := Curve.Product(pts) one := Curve.Identity() return !one.Equal(product) -}
\ No newline at end of file +} |