forked from cloudflare/circl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dl_test.go
60 lines (47 loc) · 1.35 KB
/
dl_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package dl_test
import (
"crypto/rand"
"testing"
"github.com/cloudflare/circl/group"
"github.com/cloudflare/circl/zk/dl"
)
const testzkDLCount = 1 << 8
func testzkDL(t *testing.T, myGroup group.Group) {
kA := myGroup.RandomNonZeroScalar(rand.Reader)
DB := myGroup.RandomElement(rand.Reader)
R := myGroup.NewElement()
R.Mul(DB, kA)
dst := "zeroknowledge"
rnd := rand.Reader
proof := dl.Prove(myGroup, DB, R, kA, []byte("Prover"), []byte(dst), rnd)
verify := dl.Verify(myGroup, DB, R, proof, []byte("Prover"), []byte(dst))
if verify == false {
t.Error("zk/dl verification failed")
}
}
func testzkDLNegative(t *testing.T, myGroup group.Group) {
kA := myGroup.RandomNonZeroScalar(rand.Reader)
DB := myGroup.RandomElement(rand.Reader)
R := myGroup.RandomElement(rand.Reader)
dst := "zeroknowledge"
rnd := rand.Reader
proof := dl.Prove(myGroup, DB, R, kA, []byte("Prover"), []byte(dst), rnd)
verify := dl.Verify(myGroup, DB, R, proof, []byte("Prover"), []byte(dst))
if verify == true {
t.Error("zk/dl verification should fail")
}
}
func TestZKDL(t *testing.T) {
t.Run("zkDL", func(t *testing.T) {
for i := 0; i < testzkDLCount; i++ {
currGroup := group.P256
testzkDL(t, currGroup)
}
})
t.Run("zkDLNegative", func(t *testing.T) {
for i := 0; i < testzkDLCount; i++ {
currGroup := group.P256
testzkDLNegative(t, currGroup)
}
})
}