aboutsummaryrefslogtreecommitdiff
path: root/nizk/commit/commit.go
diff options
context:
space:
mode:
Diffstat (limited to 'nizk/commit/commit.go')
-rw-r--r--nizk/commit/commit.go59
1 files changed, 16 insertions, 43 deletions
diff --git a/nizk/commit/commit.go b/nizk/commit/commit.go
index d9d06b5..5238c15 100644
--- a/nizk/commit/commit.go
+++ b/nizk/commit/commit.go
@@ -1,9 +1,7 @@
package commit
import (
- "crypto/sha512"
-
- "kesim.org/seal/curve"
+ . "kesim.org/seal/nizk"
)
// This is a construction of a proof of a statement of the form
@@ -11,13 +9,6 @@ import (
// || [(Φ = g^(αβ+1)) && (A = g^α) && (Β = g^β)]
// for given Φ, A and B
-type Scalar = curve.Curve25519Scalar
-type Point = curve.Curve25519Point
-
-var Curve = curve.Curve25519
-var g = Curve.Generator()
-var one = Curve.ScalarOne()
-
type Statement struct {
α *Scalar
β *Scalar
@@ -45,14 +36,14 @@ func commitment(α, β *Scalar, plus bool) *Commitment {
φ := α.Mul(β)
if plus {
- Φ = g.Exp(φ.Add(one))
+ Φ = G.Exp(φ.Add(One))
} else {
- Φ = g.Exp(φ)
+ Φ = G.Exp(φ)
}
return &Commitment{
Φ: Φ,
- A: g.Exp(α),
- B: g.Exp(β),
+ A: G.Exp(α),
+ B: G.Exp(β),
}
}
@@ -72,25 +63,19 @@ func (s *Statement) Proof() *Proof {
r2 = Curve.RandomScalar()
ω = Curve.RandomScalar()
- if s == nil {
- panic("s is nil")
- } else if ω == nil {
- panic("ω is nil")
- }
-
if s.plus {
- ε[0][0] = g.Exp(r1)
- ε[0][1] = s.B.Exp(r1).Mul(g.Exp(ω))
- ε[1][0] = g.Exp(r2)
+ ε[0][0] = G.Exp(r1)
+ ε[0][1] = s.B.Exp(r1).Mul(G.Exp(ω))
+ ε[1][0] = G.Exp(r2)
ε[1][1] = s.B.Exp(r2)
} else {
- ε[0][0] = g.Exp(r1)
+ ε[0][0] = G.Exp(r1)
ε[0][1] = s.B.Exp(r1)
- ε[1][0] = g.Exp(r2).Mul(s.A.Exp(ω))
- ε[1][1] = s.B.Exp(r2).Mul(s.Φ.Div(g).Exp(ω))
+ ε[1][0] = G.Exp(r2).Mul(s.A.Exp(ω))
+ ε[1][1] = s.B.Exp(r2).Mul(s.Φ.Div(G).Exp(ω))
}
- ch := challenge(g, s.Φ, s.A, s.B, ε[0][0], ε[0][1], ε[1][0], ε[1][1])
+ ch := Challenge(G, s.Φ, s.A, s.B, ε[0][0], ε[0][1], ε[1][0], ε[1][1])
pr := &Proof{}
if s.plus {
@@ -108,24 +93,12 @@ func (s *Statement) Proof() *Proof {
return pr
}
-func challenge(points ...*Point) *Scalar {
- h512 := sha512.New()
- for _, p := range points {
- h512.Write(p.Bytes())
- }
- ch, e := Curve.ScalarFromBytes(h512.Sum(nil))
- if e != nil {
- panic(e)
- }
- return ch
-}
-
func (c *Commitment) Verify(p *Proof) bool {
var ε [2][2]*Point
- ε[0][0] = g.Exp(p.Rho[0]).Mul(c.A.Exp(p.Ch[0]))
+ ε[0][0] = G.Exp(p.Rho[0]).Mul(c.A.Exp(p.Ch[0]))
ε[0][1] = c.B.Exp(p.Rho[0]).Mul(c.Φ.Exp(p.Ch[0]))
- ε[1][0] = g.Exp(p.Rho[1]).Mul(c.A.Exp(p.Ch[1]))
- ε[1][1] = c.B.Exp(p.Rho[1]).Mul(c.Φ.Div(g).Exp(p.Ch[1]))
- ch := challenge(g, c.Φ, c.A, c.B, ε[0][0], ε[0][1], ε[1][0], ε[1][1])
+ ε[1][0] = G.Exp(p.Rho[1]).Mul(c.A.Exp(p.Ch[1]))
+ ε[1][1] = c.B.Exp(p.Rho[1]).Mul(c.Φ.Div(G).Exp(p.Ch[1]))
+ ch := Challenge(G, c.Φ, c.A, c.B, ε[0][0], ε[0][1], ε[1][0], ε[1][1])
return p.Ch[0].Add(p.Ch[1]).Equal(ch)
}