...
1
2
3
4
5 package rand
6
7 import "internal/chacha8rand"
8
9
10
11 type ChaCha8 struct {
12 state chacha8rand.State
13 }
14
15
16 func NewChaCha8(seed [32]byte) *ChaCha8 {
17 c := new(ChaCha8)
18 c.state.Init(seed)
19 return c
20 }
21
22
23 func (c *ChaCha8) Seed(seed [32]byte) {
24 c.state.Init(seed)
25 }
26
27
28 func (c *ChaCha8) Uint64() uint64 {
29 for {
30 x, ok := c.state.Next()
31 if ok {
32 return x
33 }
34 c.state.Refill()
35 }
36 }
37
38
39 func (c *ChaCha8) UnmarshalBinary(data []byte) error {
40 return chacha8rand.Unmarshal(&c.state, data)
41 }
42
43
44 func (c *ChaCha8) MarshalBinary() ([]byte, error) {
45 return chacha8rand.Marshal(&c.state), nil
46 }
47
View as plain text