-
Notifications
You must be signed in to change notification settings - Fork 1
/
export.go
66 lines (56 loc) · 1.15 KB
/
export.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
package eaglesong
import (
"bytes"
"hash"
)
// Eaglesong func is just a shortcut for EaglesongSponge, it's silly, no time saving on reusing
func Eaglesong(input []byte) (output []byte) {
output = make([]byte, 32)
EaglesongSponge(output, 32, input, uint(len(input)))
return
}
// types
const Size = 32
type digest struct {
state []uint32
length uint
msg []byte
}
func (d *digest) Write(p []byte) (n int, err error) {
if p != nil {
d.length += uint(len(p))
d.msg = bytes.Join([][]byte{d.msg, p}, nil)
EaglesongUpdate(d.state, d.msg)
remLen := d.length % (RATE / 8)
remMsg := d.msg[d.length-remLen:]
d.length = remLen
d.msg = remMsg
return len(p), nil
} else {
return 0, nil
}
}
func (d *digest) Sum(b []byte) []byte {
output := make([]byte, 32)
EaglesongFinalize(d.state, d.msg, output, 32)
return output
}
func (d *digest) Reset() {
d.state = nil
d.msg = nil
d.length = 0
}
func (d *digest) Size() int {
return 32
}
func (d *digest) BlockSize() int {
return 4 * 16
}
// New returns a new hash.Hash computing the Eaglesong.
func New() hash.Hash {
return &digest{
state: make([]uint32, 16),
length: 0,
msg: nil,
}
}