forked from l0k18/kcp9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gfcp_entropy.go
59 lines (53 loc) · 880 Bytes
/
gfcp_entropy.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
// Copyright © 2021 Jeffrey H. Johnson <trnsz@pobox.com>.
// Copyright © 2015 Daniel Fu <daniel820313@gmail.com>.
// Copyright © 2019 Loki 'l0k18' Verloren <stalker.loki@protonmail.ch>.
// Copyright © 2021 Gridfinity, LLC. <admin@gridfinity.com>.
//
// All rights reserved.
//
// All use of this code is governed by the MIT license.
// The complete license is available in the LICENSE file.
package gfcp
import (
"crypto/rand"
"io"
)
// Entropy defines a entropy source
type Entropy interface {
Init()
Fill(
nonce []byte,
)
}
// Nonce ...
type Nonce struct {
seed []byte
}
// Init ...
func (
n *Nonce,
) Init() {
}
// Fill ...
func (
n *Nonce,
) Fill(
nonce []byte,
) {
var err error
if n.seed[0] == 0 {
_, err = io.ReadFull(
rand.Reader,
n.seed,
)
if err != nil {
panic(
"io.ReadFull failure",
)
}
}
copy(
nonce,
n.seed,
)
}