-
Notifications
You must be signed in to change notification settings - Fork 0
/
shake.go
105 lines (73 loc) · 1.69 KB
/
shake.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package hash
import (
"hash"
"golang.org/x/crypto/sha3"
)
var newShake128 = func() hash.Hash {
return sha3.NewShake128()
}
var newShake256 = func() hash.Hash {
return sha3.NewShake256()
}
var newCShake128 = func(N, S []byte) hash.Hash {
return sha3.NewCShake128(N, S)
}
var newCShake256 = func(N, S []byte) hash.Hash {
return sha3.NewCShake256(N, S)
}
// ===========
// Shake128 哈希值 num = 64
func (this Hash) Shake128(num int) Hash {
data := make([]byte, num)
sha3.ShakeSum128(data, this.data)
this.data = data
return this
}
// NewShake128
func (this Hash) NewShake128() Hash {
this.hash = newShake128()
return this
}
// ===========
// Shake256 哈希值 num = 64
func (this Hash) Shake256(num int) Hash {
data := make([]byte, num)
sha3.ShakeSum256(data, this.data)
this.data = data
return this
}
// NewShake256
func (this Hash) NewShake256() Hash {
this.hash = newShake256()
return this
}
// ===========
// CShake128 哈希值 num = 64
func (this Hash) CShake128(N, S []byte, num int) Hash {
h := sha3.NewCShake128(N, S)
h.Write(this.data)
hash := make([]byte, num)
h.Read(hash)
this.data = hash
return this
}
// NewCShake128
func (this Hash) NewCShake128(N, S []byte) Hash {
this.hash = newCShake128(N, S)
return this
}
// ===========
// CShake256 哈希值 num = 64
func (this Hash) CShake256(N, S []byte, num int) Hash {
h := sha3.NewCShake256(N, S)
h.Write(this.data)
hash := make([]byte, num)
h.Read(hash)
this.data = hash
return this
}
// NewCShake256
func (this Hash) NewCShake256(N, S []byte) Hash {
this.hash = newCShake256(N, S)
return this
}