forked from hybridnetwork/bliss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_test.go
56 lines (48 loc) · 1.13 KB
/
demo_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
package bliss
import (
"fmt"
"testing"
"github.com/hybridnetwork/bliss/params"
"github.com/hybridnetwork/bliss/sampler"
)
func TestDemo(t *testing.T) {
version := params.BLISS_B_0
seed := []uint8{
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
}
msg := "Hello world"
entropy, err := sampler.NewEntropy(seed)
if err != nil {
t.Errorf("Error in creating entropy: %s\n", err.Error())
return
}
key, err := GeneratePrivateKey(version, entropy)
if err != nil {
t.Errorf("Error in generating private key: %s\n", err.Error())
return
} else {
fmt.Errorf("Private Key: %s\n", key.String())
}
pub := key.PublicKey()
fmt.Printf("Public Key: %s\n", pub.String())
sig, err := key.Sign([]byte(msg), entropy)
if err != nil {
t.Errorf("Error in signing: %s\n", err.Error())
return
} else {
fmt.Printf("Signature: %s\n", sig.String())
}
res, err := pub.Verify([]byte(msg), sig)
if res {
fmt.Printf("Verified!\n")
} else {
t.Errorf("Error: %s\n", err.Error())
}
}