Skip to content

Commit 4729bc3

Browse files
committed
fixed
1 parent 8372d74 commit 4729bc3

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

hash/bash/bash.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import (
1010
* An english version of the specifications exist here: https://eprint.iacr.org/2016/587.pdf
1111
*/
1212

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+
1318
// New224 returns a new hash.Hash computing the Bash checksum
1419
func New224() hash.Hash {
1520
h, _ := New(224)

hash/bash/digest.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package bash
22

33
import (
4-
"hash"
54
"errors"
65
)
76

@@ -23,8 +22,8 @@ type digest struct {
2322
hs, bs int
2423
}
2524

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) {
2827
if hashsize == 0 {
2928
return nil, errors.New("go-hash/bash: hash size can't be zero")
3029
}
@@ -92,7 +91,7 @@ func (d *digest) Write(p []byte) (nn int, err error) {
9291

9392
func (d *digest) Sum(in []byte) []byte {
9493
// Make a copy of d so that caller can keep writing and summing.
95-
d0 := *d
94+
d0 := d.copy()
9695
hash := d0.checkSum()
9796
return append(in, hash...)
9897
}
@@ -119,3 +118,20 @@ func (d *digest) processBlock(data []byte) {
119118

120119
BASHF(d.s[:], true)
121120
}
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+
}

hash/belt/digest.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package belt
22

3-
import (
4-
"hash"
5-
)
6-
73
const (
84
// hash size
95
Size = 32
@@ -23,7 +19,7 @@ type digest struct {
2319
}
2420

2521
// New returns a new hash.Hash computing the belt checksum
26-
func newDigest() hash.Hash {
22+
func newDigest() *digest {
2723
d := new(digest)
2824
d.Reset()
2925

hash/md2/digest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type digest struct {
2020
digest [Size]byte // the digest, Size
2121
}
2222

23+
// newDigest returns a new digest computing the md2 checksum
2324
func newDigest() *digest {
2425
d := new(digest)
2526
d.Reset()

0 commit comments

Comments
 (0)