Repository navigation
Conversation
Cloning with useASM true while the state lives in h.xc returned an empty sponge and a nil error. Branch on which sub-state the receiver holds, use comma-ok for the KeccakState assertion so Clone returns errCloneUnsupported instead of panicking, and cover the fallback receiver by building it directly rather than by writing the useASM global from a test.
The asm-side caller went away with keccak_clone_asm_test.go.
Copying only the live one made the copy dispatch differently from the original: with both populated, Clone returned a zero sponge and the copy hashed the empty string where the original hashed its sponge data.
Found
Dead indirection. Fixed
Not fixed — your call
|
|
Summary
Hashermust not be copied directlyClonefor an explicit, implementation-independent deep copyWhy
Direct struct copies currently have platform-dependent behavior. The native sponge is stored by value, while the fallback stores an interface containing a pointer to the
x/crypto/sha3state. A direct copy is therefore independent on an accelerated CPU but aliases state on the fallback.Clonecopies the native sponge directly and deep-copies the fallback through its binary state implementation. This is an independent, focused split of the cloning part of #13; it does not add marshaling APIs or squeeze changes.TDD
The first tests failed because
Hasher.Clonedid not exist. A separate zero-value cycle then failed in the runtime fallback with:The zero-value path was added after that failure.
Verification
go test ./...go test -race ./...go test -tags purego ./...go vet ./...go vet -tags purego ./...go mod tidy -diffgolangci-lint rungolangci-lint run --build-tags purego