/
cubehash.go
186 lines (147 loc) · 3.71 KB
/
cubehash.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package cubehash
import (
"hash"
)
// NewCubehash returns a new hash.Hash.
func NewCubehash(hashSize, blockSize, r, ir, fr int) hash.Hash {
return newDigest(hashSize, blockSize, r, ir, fr)
}
// NewHS512x returns a new hash.Hash.
func NewHS512x() hash.Hash {
return NewCubehash(512, 1, 16, 16, 32)
}
// NewHS512 returns a new hash.Hash.
func NewHS512() hash.Hash {
return NewCubehash(512, 32, 16, 16, 32)
}
// NewHS384 returns a new hash.Hash.
func NewHS384() hash.Hash {
return NewCubehash(384, 32, 16, 16, 32)
}
// NewHS256 returns a new hash.Hash.
func NewHS256() hash.Hash {
return NewCubehash(256, 32, 16, 16, 32)
}
// NewHS224 returns a new hash.Hash.
func NewHS224() hash.Hash {
return NewCubehash(224, 32, 16, 16, 32)
}
// NewHS192 returns a new hash.Hash.
func NewHS192() hash.Hash {
return NewCubehash(192, 32, 16, 16, 32)
}
// NewHS160 returns a new hash.Hash.
func NewHS160() hash.Hash {
return NewCubehash(160, 32, 16, 16, 32)
}
// NewHS128 returns a new hash.Hash.
func NewHS128() hash.Hash {
return NewCubehash(128, 32, 16, 16, 32)
}
// =======
// NewSH512 returns a new hash.Hash.
func NewSH512() hash.Hash {
return NewCubehash(512, 32, 16, 160, 160)
}
// NewSH256 returns a new hash.Hash.
func NewSH256() hash.Hash {
return NewCubehash(256, 32, 16, 160, 160)
}
// NewSH224 returns a new hash.Hash.
func NewSH224() hash.Hash {
return NewCubehash(224, 32, 16, 160, 160)
}
// NewSH192 returns a new hash.Hash.
func NewSH192() hash.Hash {
return NewCubehash(192, 32, 16, 160, 160)
}
// =======
// SumHS512 returns the cubehash checksum of the data.
func SumHS512(data []byte) (out [Size512]byte) {
h := NewHS512()
h.Write(data)
sum := h.Sum(nil)
copy(out[:], sum)
return
}
// SumHS384 returns the cubehash checksum of the data.
func SumHS384(data []byte) (out [Size384]byte) {
h := NewHS384()
h.Write(data)
sum := h.Sum(nil)
copy(out[:], sum)
return
}
// SumHS256 returns the cubehash checksum of the data.
func SumHS256(data []byte) (out [Size256]byte) {
h := NewHS256()
h.Write(data)
sum := h.Sum(nil)
copy(out[:], sum)
return
}
// SumHS224 returns the cubehash checksum of the data.
func SumHS224(data []byte) (out [Size224]byte) {
h := NewHS224()
h.Write(data)
sum := h.Sum(nil)
copy(out[:], sum)
return
}
// SumHS192 returns the cubehash checksum of the data.
func SumHS192(data []byte) (out [Size192]byte) {
h := NewHS192()
h.Write(data)
sum := h.Sum(nil)
copy(out[:], sum)
return
}
// SumHS160 returns the cubehash checksum of the data.
func SumHS160(data []byte) (out [Size160]byte) {
h := NewHS160()
h.Write(data)
sum := h.Sum(nil)
copy(out[:], sum)
return
}
// SumHS128 returns the cubehash checksum of the data.
func SumHS128(data []byte) (out [Size128]byte) {
h := NewHS128()
h.Write(data)
sum := h.Sum(nil)
copy(out[:], sum)
return
}
// =======
// SumSH512 returns the cubehash checksum of the data.
func SumSH512(data []byte) (out [Size512]byte) {
h := NewSH512()
h.Write(data)
sum := h.Sum(nil)
copy(out[:], sum)
return
}
// SumSH256 returns the cubehash checksum of the data.
func SumSH256(data []byte) (out [Size256]byte) {
h := NewSH256()
h.Write(data)
sum := h.Sum(nil)
copy(out[:], sum)
return
}
// SumSH224 returns the cubehash checksum of the data.
func SumSH224(data []byte) (out [Size224]byte) {
h := NewSH224()
h.Write(data)
sum := h.Sum(nil)
copy(out[:], sum)
return
}
// SumSH192 returns the cubehash checksum of the data.
func SumSH192(data []byte) (out [Size192]byte) {
h := NewSH192()
h.Write(data)
sum := h.Sum(nil)
copy(out[:], sum)
return
}