aboutsummaryrefslogtreecommitdiff
path: root/nizk/schnorr
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@codeblau.de>2024-11-21 17:13:47 +0100
committerÖzgür Kesim <oec@codeblau.de>2024-11-21 17:13:47 +0100
commit0ada8c47427bfe604024d383ed7a250b04c82fee (patch)
tree4bc5e6432512a8060308413d303b675b0658bd1b /nizk/schnorr
parent32cee46e39527a09504615b822cc61969c46184d (diff)
refactor: lifted nizk/ up and awayHEADwip
Diffstat (limited to 'nizk/schnorr')
-rw-r--r--nizk/schnorr/schnorr.go77
-rw-r--r--nizk/schnorr/schnorr_test.go34
2 files changed, 0 insertions, 111 deletions
diff --git a/nizk/schnorr/schnorr.go b/nizk/schnorr/schnorr.go
deleted file mode 100644
index ad42770..0000000
--- a/nizk/schnorr/schnorr.go
+++ /dev/null
@@ -1,77 +0,0 @@
-// Proof of knowledge of a for given A = G^a
-
-package schnorr
-
-import (
- . "kesim.org/seal/common"
-)
-
-type Statement Scalar
-
-type Commitment Point
-
-// A Schnorr signature to prove knowledge of v for given g^v.
-// Choosing a scalar v randomly, the signature consists of (V, r) with
-//
-// V := g^v, with randomly chosen v
-// r := (v - x*h), with h := H(g, g^v, g^x, i), where i is given by the context.
-//
-// Verification of the signature is by comparing V =?= g^r * g^(x*h)
-type Proof struct {
- V *Point `json:"V"`
- R *Scalar `json:"r"`
-}
-
-// Generates a commitment
-
-// Generates the proof, aka Schnorr signature, for given priv and i.
-// Choosing a scalar v randomly, the signature consists of (V, r) with
-//
-// V := g^v, with randomly chosen v
-// r := (v - x*h), with h := H(g, g^v, g^x, i), where i is given by the context.
-//
-// Verification of the signature is by comparing V =?= g^r * g^(x*h)
-func (s *Statement) Proof(id Bytes) (pr *Proof) {
- x := (*Scalar)(s)
-
- // choose random v
- v := Curve.RandomScalar()
-
- pr = &Proof{}
-
- // calculate g^v
- pr.V = Curve.Exp(v)
-
- // calculate g^x
- gx := G.Exp(x)
-
- // calculate h := H(g, g^v, g^x, i)
- h := Challenge(pr.V, gx, id)
-
- // Calculate r := v - x*h
- xh := x.Mul(h)
- r := v.Sub(xh)
- pr.R = r
-
- return pr
-}
-
-// Verifies that g^v == g^r*g^(x*h)
-func (c *Commitment) Verify(p *Proof, id Bytes) bool {
- Gx := (*Point)(c)
-
- // Calculate h = H(g, g^v, g^x, id)
- h := Challenge(p.V, Gx, id)
-
- // Calculate g^(x*h) = (g^x)^h
- gxh := Gx.Exp(h)
-
- // Calculate g^r
- gr := G.Exp(p.R)
-
- // Calculate g^r*g^(x*h)
- grgxh := gr.Mul(gxh)
-
- // Return true if g^v == g^r*g^(x*h)
- return p.V.Equal(grgxh)
-}
diff --git a/nizk/schnorr/schnorr_test.go b/nizk/schnorr/schnorr_test.go
deleted file mode 100644
index 2adec8e..0000000
--- a/nizk/schnorr/schnorr_test.go
+++ /dev/null
@@ -1,34 +0,0 @@
-package schnorr
-
-import (
- "testing"
-
- . "kesim.org/seal/common"
-)
-
-func TestSchnorr(t *testing.T) {
- a, e := Curve.ScalarFromReader(nil)
- if e != nil {
- t.Fatal(e)
- }
- A := G.Exp(a)
-
- id, e := Curve.ScalarFromReader(nil)
- if e != nil {
- t.Fatal(e)
- }
- ID := G.Exp(id)
-
- s := (*Statement)(a)
- c := (*Commitment)(A)
-
- pr := s.Proof(ID)
-
- if !c.Verify(pr, ID) {
- t.Fatalf("Verification failed!")
- }
-
- if c.Verify(pr, ID.Exp(a)) {
- t.Fatal("Verification didn't fail!")
- }
-}