-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
109 lines (79 loc) · 2.44 KB
/
main_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package ecdaa
import (
"testing"
amcl_utils "github.com/akakou/fp256bn-amcl-utils"
"github.com/akakou/ecdaa/tpm_utils"
)
func TestTPM(t *testing.T) {
rng := amcl_utils.InitRandom()
password := []byte("piyo")
tpm, err := tpm_utils.OpenTPM(password, tpm_utils.TPM_PATH)
if err != nil {
t.Fatalf("%v", err)
}
defer tpm.Close()
issuer, signer, err := ExampleTPMInitialize(tpm, rng)
if err != nil {
t.Fatalf("%v", err)
}
testSignAndVerify(t, signer, issuer)
}
func TestSW(t *testing.T) {
rng := amcl_utils.InitRandom()
issuer, signer, err := ExampleInitialize(rng)
if err != nil {
t.Errorf("%v", err)
}
testSignAndVerify(t, signer, issuer)
}
func testSignAndVerify(t *testing.T, signer Signer, issuer *Issuer) {
message := []byte("hoge")
incorrect_message := []byte("hoge2")
basename := []byte("fuga")
basename2 := []byte("fuga2")
incorrect_basename := []byte("fuga3")
rng := amcl_utils.InitRandom()
signature, err := signer.Sign(message, basename, rng)
if err != nil {
t.Fatalf("sign: %v", err)
}
same_bsn_signature, err := signer.Sign(message, basename, rng)
if err != nil {
t.Fatalf("sign: %v", err)
}
not_same_bsn_signature, err := signer.Sign(message, basename2, rng)
if err != nil {
t.Fatalf("sign: %v", err)
}
t.Run("verify_signature_correct", func(t *testing.T) {
// fmt.Print("sign_correct...\n")
err = Verify(message, basename, signature, &issuer.Ipk, RevocationList{})
if err != nil {
t.Fatalf("verify: %v", err)
}
})
t.Run("verify_signature_msg_incorrect", func(t *testing.T) {
// fmt.Print("sign_msg_incorrect...\n")
err = Verify(incorrect_message, basename, signature, &issuer.Ipk, RevocationList{})
if err == nil {
t.Fatalf("verify: incorrect judge, msg is incorrect but verify say valid")
}
})
t.Run("verify_signature_bsn_incorrect", func(t *testing.T) {
// fmt.Print("sign_bsn_incorrect...\n")
err = Verify(message, incorrect_basename, signature, &issuer.Ipk, RevocationList{})
if err == nil {
t.Fatalf("verify: incorrect judge, basename is incorrect but verify say valid")
}
})
t.Run("signing_are_same_k", func(t *testing.T) {
if !signature.Proof.K.Equals(same_bsn_signature.Proof.K) {
t.Fatalf("wrong that, Ks which are made by same base name are not same.")
}
})
t.Run("signing_are_not_same k", func(t *testing.T) {
if signature.Proof.K.Equals(not_same_bsn_signature.Proof.K) {
t.Fatalf("wrong that, Ks which are made by same base name are same.")
}
})
}