Skip to content

Commit dc4005e

Browse files
committed
sha1cd: Reset both m2 and cs
Ensure that during resets both m2 and cs are completely cleared out. This increases the allocs to 1-2, and should be optimised at a later stage. Signed-off-by: Paulo Gomes <[email protected]>
1 parent 58e773e commit dc4005e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

sha1cd.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ func (d *digest) Reset() {
129129
d.ihvtmp[3] = 0x0
130130
d.ihvtmp[4] = 0xA7ECE0
131131

132+
for i := range d.m2 {
133+
d.m2[i] = 0x0
134+
}
135+
136+
for k := range d.cs {
137+
delete(d.cs, k)
138+
}
132139
}
133140

134141
// New returns a new hash.Hash computing the SHA1 checksum. The Hash also

sha1cd_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ func TestAllocations(t *testing.T) {
201201
h.Write(in)
202202
out = h.Sum(out[:0])
203203
}))
204-
if n > 0 {
204+
205+
//TODO: Optimise resetting state to enforce 0 allocs.
206+
if n > 2 {
205207
t.Errorf("allocs = %d, want 0", n)
206208
}
207209
}

0 commit comments

Comments
 (0)