-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrandom_test.go
74 lines (58 loc) · 1.79 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package otr4
import (
"crypto/rand"
"github.com/otrv4/ed448"
. "gopkg.in/check.v1"
)
func (s *OTR4Suite) Test_Randomness(c *C) {
// randomness
r := fixedRand([]byte{0x00})
con := &conversation{random: r}
c.Assert(con.rand(), DeepEquals, r)
// no randomness
con = &conversation{}
c.Assert(con.rand(), DeepEquals, rand.Reader)
}
func (s *OTR4Suite) Test_RandomBytes(c *C) {
b, err := randSymKey(fixedRand(randData))
exp := []byte{
0x40, 0x80, 0x66, 0x2d, 0xd8, 0xe7, 0xf0, 0x9c,
0xdf, 0xb0, 0x4e, 0x1c, 0x6e, 0x12, 0x62, 0xa3,
0x7c, 0x31, 0x9a, 0xe1, 0xe7, 0x86, 0x87, 0xcc,
0x82, 0x05, 0x78, 0xe6, 0x44, 0x2f, 0x4f, 0x77,
}
c.Assert(err, IsNil)
c.Assert(b, DeepEquals, exp)
}
func (s *OTR4Suite) Test_RandomScalar(c *C) {
scalar, err := randScalar(fixedRand(randData))
exp := ed448.NewScalar(
[]byte{
0x40, 0x80, 0x66, 0x2d, 0xd8, 0xe7, 0xf0, 0x9c,
0xdf, 0xb0, 0x4e, 0x1c, 0x6e, 0x12, 0x62, 0xa3,
0x7c, 0x31, 0x9a, 0xe1, 0xe7, 0x86, 0x87, 0xcc,
0x82, 0x05, 0x78, 0xe6, 0x44, 0x2f, 0x4f, 0x77,
0x0e, 0xd1, 0xb4, 0x48, 0xa6, 0x05, 0x90, 0x5e,
0xe7, 0xba, 0xfc, 0x25, 0x99, 0x99, 0xb8, 0xc3,
0x90, 0x3e, 0xf4, 0xa3, 0x75, 0xee, 0x85, 0x32,
},
)
c.Assert(err, IsNil)
c.Assert(scalar, DeepEquals, exp)
}
func (s *OTR4Suite) Test_RandomLongTermScalar(c *C) {
scalar, err := randLongTermScalar(fixedRand(randData))
exp := ed448.NewScalar(
[]byte{
0xc6, 0xd0, 0x98, 0x2e, 0xe4, 0xe5, 0x81, 0xe4,
0x61, 0x3c, 0x46, 0x99, 0x0a, 0x37, 0x79, 0xc3,
0xfa, 0xe5, 0xd5, 0x29, 0x27, 0x31, 0xa3, 0x55,
0x9f, 0x34, 0x91, 0xd1, 0x0c, 0x7f, 0x88, 0x56,
0x8c, 0x62, 0xe1, 0x86, 0xb7, 0xef, 0xd6, 0xcb,
0x1b, 0x14, 0x88, 0x3b, 0xc0, 0xfb, 0xac, 0x46,
0x0c, 0xc7, 0x20, 0x82, 0x3e, 0xd0, 0xdc, 0x2c,
},
)
c.Assert(err, IsNil)
c.Assert(scalar, DeepEquals, exp)
}