-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_test.go
60 lines (45 loc) · 1.4 KB
/
random_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 cryptoauthlib_test
import (
"bytes"
"encoding/hex"
"fmt"
"testing"
element "github.com/riddleandcode/go-cryptoauthlib"
)
func TestRandom(t *testing.T) {
zeroBytes := make([]byte, 32)
const numLoops = 10
fmt.Println("hello")
for i := 0; i < 10; i++ {
randomBytes := element.Random()
fmt.Printf("randomBytes:\n%s\n", hex.Dump(randomBytes))
if len(randomBytes) != 32 {
t.Errorf("The length is incorrect, got: %d, want: %d.", len(randomBytes), 32)
}
if bytes.Equal(zeroBytes, randomBytes) {
t.Errorf("The random bytes are all zero. Not very random, is it?\n%s", hex.Dump(randomBytes))
}
}
var res int
var random_number = Random()
fmt.Printf("Here's your random: %d\n", res)
fmt.Printf("%s\n", hex.Dump(random_number))
var digest = Random()
fmt.Printf("Here's your digest: %d\n", res)
fmt.Printf("%s\n", hex.Dump(digest))
var public_key []byte
res, public_key = GetPublicKey()
fmt.Printf("Here's your public key: %d\n", res)
fmt.Printf("%s\n", hex.Dump(public_key))
var signature []byte
res, signature = SignDigest(digest)
fmt.Printf("Here's your signature: %d\n", res)
fmt.Printf("%s\n", hex.Dump(signature))
var verified bool
res, verified = VerifySignedDigest( digest, signature, public_key )
fmt.Printf("Here's your verification: %d\n", res)
fmt.Printf("%t \n",verified )
if !verified {
t.Errorf("The verification of the singing process failed?")
}
}