File tree Expand file tree Collapse file tree 4 files changed +27
-9
lines changed Expand file tree Collapse file tree 4 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,11 @@ import (
10
10
* An english version of the specifications exist here: https://eprint.iacr.org/2016/587.pdf
11
11
*/
12
12
13
+ // New returns a new hash.Hash computing the bash checksum
14
+ func New (hashsize int ) (hash.Hash , error ) {
15
+ return newDigest (hashsize )
16
+ }
17
+
13
18
// New224 returns a new hash.Hash computing the Bash checksum
14
19
func New224 () hash.Hash {
15
20
h , _ := New (224 )
Original file line number Diff line number Diff line change 1
1
package bash
2
2
3
3
import (
4
- "hash"
5
4
"errors"
6
5
)
7
6
@@ -23,8 +22,8 @@ type digest struct {
23
22
hs , bs int
24
23
}
25
24
26
- // New returns a new hash.Hash computing the bash checksum
27
- func New (hashsize int ) (hash. Hash , error ) {
25
+ // newDigest returns a new hash.Hash computing the bash checksum
26
+ func newDigest (hashsize int ) (* digest , error ) {
28
27
if hashsize == 0 {
29
28
return nil , errors .New ("go-hash/bash: hash size can't be zero" )
30
29
}
@@ -92,7 +91,7 @@ func (d *digest) Write(p []byte) (nn int, err error) {
92
91
93
92
func (d * digest ) Sum (in []byte ) []byte {
94
93
// Make a copy of d so that caller can keep writing and summing.
95
- d0 := * d
94
+ d0 := d . copy ()
96
95
hash := d0 .checkSum ()
97
96
return append (in , hash ... )
98
97
}
@@ -119,3 +118,20 @@ func (d *digest) processBlock(data []byte) {
119
118
120
119
BASHF (d .s [:], true )
121
120
}
121
+
122
+ func (d * digest ) copy () * digest {
123
+ d0 := & digest {}
124
+
125
+ d0 .s = d .s
126
+
127
+ d0 .x = make ([]byte , len (d .x ))
128
+ copy (d0 .x , d .x )
129
+
130
+ d0 .nx = d .nx
131
+ d0 .len = d .len
132
+
133
+ d0 .hs = d .hs
134
+ d0 .bs = d .bs
135
+
136
+ return d0
137
+ }
Original file line number Diff line number Diff line change 1
1
package belt
2
2
3
- import (
4
- "hash"
5
- )
6
-
7
3
const (
8
4
// hash size
9
5
Size = 32
@@ -23,7 +19,7 @@ type digest struct {
23
19
}
24
20
25
21
// New returns a new hash.Hash computing the belt checksum
26
- func newDigest () hash. Hash {
22
+ func newDigest () * digest {
27
23
d := new (digest )
28
24
d .Reset ()
29
25
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ type digest struct {
20
20
digest [Size ]byte // the digest, Size
21
21
}
22
22
23
+ // newDigest returns a new digest computing the md2 checksum
23
24
func newDigest () * digest {
24
25
d := new (digest )
25
26
d .Reset ()
You can’t perform that action at this time.
0 commit comments