aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@codeblau.de>2024-03-21 19:11:13 +0100
committerÖzgür Kesim <oec@codeblau.de>2024-03-21 19:11:13 +0100
commit00c59198893ba034fda5dda167bed495a7d4649f (patch)
tree5a669ab9b779f3cb9e5268cf9f42cf5b57c0ee0b
parent989d09c8511eb10f2af06977d210deff39b6ff9e (diff)
veto: -shorten curve name
-rw-r--r--veto/veto.go39
1 files changed, 18 insertions, 21 deletions
diff --git a/veto/veto.go b/veto/veto.go
index cb526d6..6a64c82 100644
--- a/veto/veto.go
+++ b/veto/veto.go
@@ -14,6 +14,8 @@ import (
type Scalar = Curve25519Scalar
type Point = Curve25519Point
+var Curve = Curve25519
+
// Representation of a vote with veto (if set to true)
type Vote struct {
veto bool
@@ -63,16 +65,16 @@ func proof(x *Scalar, id *Point) (pr *Proof, e error) {
pr = &Proof{Id: id}
// choose random v
- v, e := Curve25519.ScalarFromReader(nil)
+ v, e := Curve.ScalarFromReader(nil)
if e != nil {
return nil, e
}
// calculate g^v
- pr.PV = Curve25519.Exp(v)
+ pr.PV = Curve.Exp(v)
// calculate g^x
- gx := Curve25519.Exp(x)
+ gx := Curve.Exp(x)
// calculate h := H(g, g^v, g^x, i)
h, e := hash(pr.PV, gx, id)
@@ -91,12 +93,12 @@ func proof(x *Scalar, id *Point) (pr *Proof, e error) {
// Calculate h := H(g, g^v, g^x, i)
func hash(gv, gx *Point, id *Point) (*Scalar, error) {
h512 := sha512.New()
- h512.Write(Curve25519.Identity().Bytes())
+ h512.Write(Curve.Identity().Bytes())
h512.Write(gv.Bytes())
h512.Write(gx.Bytes())
h512.Write(id.Bytes())
hb := h512.Sum(nil)
- return Curve25519.ScalarFromBytes(hb)
+ return Curve.ScalarFromBytes(hb)
}
func combineErr(es ...error) error {
@@ -125,10 +127,9 @@ func verifyProof(V *Point, Gx *Point, r *Scalar, id *Point) (ok bool) {
gxh := Gx.Exp(h)
// Calculate g^r
- gr := Curve25519.Exp(r)
+ gr := Curve.Exp(r)
// Calculate g^r*g^(x*h)
- // Note that the edwards25519 package uses Addtion as the group
grgxh := gr.Mult(gxh)
// Return true if g^v == g^r*g^(x*h)
@@ -148,22 +149,18 @@ func newVoteWithRand(veto bool, rand io.Reader) (v *Vote, e error) {
v = &Vote{
veto: veto,
}
- var e1, e2, e3 error
- v.private.id, e1 = Curve25519.ScalarFromReader(rand)
- v.private.x, e2 = Curve25519.ScalarFromReader(rand)
- v.private.r, e3 = Curve25519.ScalarFromReader(rand)
+ v.private.id = Curve.RandomScalar()
+ v.private.x = Curve.RandomScalar()
+ v.private.r = Curve.RandomScalar()
- e = combineErr(e1, e2, e3)
- if e != nil {
- return nil, e
- }
+ var e1, e2 error
c := new(Commitment)
v.com = c
- c.Id = Curve25519.Exp(v.private.id)
- c.Points.X = Curve25519.Exp(v.private.x)
- c.Points.R = Curve25519.Exp(v.private.r)
+ c.Id = Curve.Exp(v.private.id)
+ c.Points.X = Curve.Exp(v.private.x)
+ c.Points.R = Curve.Exp(v.private.r)
c.Proofs.X, e1 = proof(v.private.x, c.Id)
c.Proofs.R, e2 = proof(v.private.r, c.Id)
@@ -195,7 +192,7 @@ func (c *Commitment) String() string {
type coms []*Commitment
func (coms coms) prod() (product *Point) {
- product = Curve25519.Identity()
+ product = Curve.Identity()
for _, com := range coms {
product = product.Mult(com.Points.X)
}
@@ -249,7 +246,7 @@ type points []*Point
// received the g^(c_i*y_i) from all other participants and calculates the product
// of them. If the result is the unit element of the group, no veto was present.
func (pts points) IsVetoed() bool {
- product := Curve25519.Product(pts)
- one := Curve25519.Identity()
+ product := Curve.Product(pts)
+ one := Curve.Identity()
return !one.Equal(product)
} \ No newline at end of file