Skip to content

Commit 4c82824

Browse files
committed
fix:sha3 clone implementation
1 parent 203cbf2 commit 4c82824

File tree

3 files changed

+3
-25
lines changed

3 files changed

+3
-25
lines changed

cng/hash.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,6 @@ func hashToID(h hash.Hash) string {
149149
return hx.alg.id
150150
}
151151

152-
// cloneHash is an interface that defines a Clone method.
153-
//
154-
// hash.CloneHash will probably be added in Go 1.25, see https://golang.org/issue/69521,
155-
// but we need it now.
156-
type cloneHash interface {
157-
hash.Hash
158-
// Clone returns a separate Hash instance with the same state as h.
159-
Clone() hash.Hash
160-
}
161-
162152
var _ hash.Hash = (*hashX)(nil)
163153
var _ HashCloner = (*hashX)(nil)
164154

cng/hash_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,6 @@ func TestHash(t *testing.T) {
7979
t.Error("Write didn't change internal hash state")
8080
}
8181

82-
h2 := h.(interface{ Clone() hash.Hash }).Clone()
83-
h.Write(msg)
84-
h2.Write(msg)
85-
if actual, actual2 := h.Sum(nil), h2.Sum(nil); !bytes.Equal(actual, actual2) {
86-
t.Errorf("%s(%q) = 0x%x != cloned 0x%x", tt.String(), msg, actual, actual2)
87-
}
88-
h.Reset()
89-
sum = h.Sum(nil)
90-
if !bytes.Equal(sum, initSum) {
91-
t.Errorf("got:%x want:%x", sum, initSum)
92-
}
93-
9482
bw := h.(io.ByteWriter)
9583
for i := 0; i < len(msg); i++ {
9684
bw.WriteByte(msg[i])

cng/sha3.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func SupportsSHAKE(securityBits int) bool {
7676
}
7777

7878
var _ hash.Hash = (*DigestSHA3)(nil)
79-
var _ cloneHash = (*DigestSHA3)(nil)
79+
var _ HashCloner = (*DigestSHA3)(nil)
8080

8181
// DigestSHA3 is the [sha3.SHA3] implementation using the CNG API.
8282
type DigestSHA3 struct {
@@ -115,14 +115,14 @@ func (h *DigestSHA3) init() {
115115
runtime.SetFinalizer(h, (*DigestSHA3).finalize)
116116
}
117117

118-
func (h *DigestSHA3) Clone() hash.Hash {
118+
func (h *DigestSHA3) Clone() (HashCloner, error) {
119119
defer runtime.KeepAlive(h)
120120
h2 := &DigestSHA3{alg: h.alg}
121121
if h.ctx != 0 {
122122
hashClone(h.ctx, &h2.ctx)
123123
runtime.SetFinalizer(h2, (*DigestSHA3).finalize)
124124
}
125-
return h2
125+
return h2, nil
126126
}
127127

128128
func (h *DigestSHA3) Reset() {

0 commit comments

Comments
 (0)