diff options
Diffstat (limited to 'nizk/commit')
-rw-r--r-- | nizk/commit/commit.go | 13 | ||||
-rw-r--r-- | nizk/commit/commit_test.go | 22 |
2 files changed, 30 insertions, 5 deletions
diff --git a/nizk/commit/commit.go b/nizk/commit/commit.go index 84ba8e5..1fa653e 100644 --- a/nizk/commit/commit.go +++ b/nizk/commit/commit.go @@ -13,8 +13,8 @@ import ( type Statement struct { bitSet bool - a *Scalar - b *Scalar + a *Scalar + b *Scalar Commitment } @@ -25,11 +25,16 @@ type Commitment struct { Proof *Proof } -func NewStatement(a, b *Scalar, bitSet bool) *Statement { +func NewStatement(bitSet bool) *Statement { + a, b := Curve.RandomScalar(), Curve.RandomScalar() + return NewStatementFromScalars(bitSet, a, b) +} + +func NewStatementFromScalars(bitSet bool, a, b *Scalar) *Statement { return &Statement{ a: a, b: b, - bitSet: bitSet, + bitSet: bitSet, Commitment: commitment(a, b, bitSet), } } diff --git a/nizk/commit/commit_test.go b/nizk/commit/commit_test.go index 8763706..4ea5964 100644 --- a/nizk/commit/commit_test.go +++ b/nizk/commit/commit_test.go @@ -7,11 +7,31 @@ import ( ) func TestStatement(t *testing.T) { + id := Curve.RandomScalar() + Id := G.Exp(id) + + st1, st2 := NewStatement(true), NewStatement(false) + c1, c2 := st1.Commit(Id), st2.Commit(Id) + if !c1.Verify() { + t.Fatal("Could not verify st1 with c1, plus=true case") + } + if !c2.Verify() { + t.Fatal("Could not verify st2 with c2, plus=false case") + } + + // Use the wrong proof + c2.Proof = c1.Proof + if c2.Verify() { + t.Fatal("Verify with wrong proof should have failed!") + } +} + +func TestStatementFromScalar(t *testing.T) { var α, β, id = Curve.RandomScalar(), Curve.RandomScalar(), Curve.RandomScalar() Id := G.Exp(id) - st1, st2 := NewStatement(α, β, true), NewStatement(α, β, false) + st1, st2 := NewStatementFromScalars(true, α, β), NewStatementFromScalars(false, α, β) c1, c2 := st1.Commit(Id), st2.Commit(Id) if !c1.Verify() { t.Fatal("Could not verify st1 with c1, plus=true case") |