-
Notifications
You must be signed in to change notification settings - Fork 0
/
hibkem_test.go
85 lines (67 loc) · 1.93 KB
/
hibkem_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package HIBKEM
import (
"bytes"
"crypto/rand"
"testing"
)
func TestHIBKEM(t *testing.T) {
params, msk, _ := Setup(rand.Reader, 100)
var id1 = params.RootID + string("1001")
var id2 = params.RootID + string("10011")
var id3 = params.RootID + string("10011111111101011111111111111111111111111")
c1sk, err := KeyGen(rand.Reader, params, msk, id1)
if err != nil {
t.Fatal(err)
}
c2sk, err := KeyGen(rand.Reader, params, c1sk, id2)
if err != nil {
t.Fatal(err)
}
c3sk, err := KeyGen(rand.Reader, params, c1sk, id3)
if err != nil {
t.Fatal(err)
}
symk1, ct1, _ := Encapsulate(rand.Reader, params, id1)
symk2, ct2, _ := Encapsulate(rand.Reader, params, id2)
symk3, ct3, _ := Encapsulate(rand.Reader, params, id3)
symk1p := Decapsulate(c1sk, ct1)
symk2p := Decapsulate(c2sk, ct2)
symk3p := Decapsulate(c3sk, ct3)
if bytes.Equal(symk1.Marshal(), symk1p.Marshal()) &&
bytes.Equal(symk2.Marshal(), symk2p.Marshal()) &&
bytes.Equal(symk3.Marshal(), symk3p.Marshal()) {
t.Log("Success!!!")
} else {
t.Fatalf("emmmm!")
}
}
func TestPuncture(t *testing.T) {
params, msk, _ := Setup(rand.Reader, 100)
var id1 = params.RootID + string("1")
var id2 = params.RootID + string("00")
var id3 = params.RootID + string("01")
newset := make([]*PrivateKey, 0)
older := &PrivateKey{}
older = msk
newset = append(newset, older)
older = &PrivateKey{}
older, _ = KeyGen(rand.Reader, params, msk, id1)
newset = append(newset, older)
older = &PrivateKey{}
older, _ = KeyGen(rand.Reader, params, msk, id2)
newset = append(newset, older)
t.Log("punctures tring:", id3)
t.Log("original set length:", len(newset))
for i, item := range newset {
t.Log("original set:", i, item.ID)
}
s1, s2 := PunctureTree(params, newset, id3)
t.Log("punctured set length:", len(s1))
for i, item := range s1 {
t.Log("punctured set:", i, item.ID)
}
t.Log("set prime length:", len(s2))
for i, item := range s2 {
t.Log("set prime:", i, item.ID)
}
}