.entire
Enable entire
.github
ci: Run the weekly fuzzers with -race
cgo
cgo: Match the ubc signature and sum with a single copy
internal
ubc: Evaluate the DV conditions with AVX-512
test
amd64: Add an AVX2 fallback for CPUs without SHA-NI
ubc
ubc: Evaluate the DV conditions with AVX-512
detection.go
Implement collision detection in Go
Dockerfile.arm
build(deps): Bump golang from 1.25 to 1.26
Dockerfile.arm64
build(deps): Bump golang from 1.25 to 1.26
go.mod
cpu: Detect CPU features in-tree and drop klauspost/cpuid
LICENSE
Update LICENSE
Makefile
amd64: Add an AVX2 fallback for CPUs without SHA-NI
README.md
amd64: Introduce SHANI implementation
sha1cd_test.go
perf: Pass collision-detection arrays by pointer
sha1cd.go
Remove self-registration via crypto.RegisterHash
sha1cdblock_amd64_test.go
amd64: Add an AVX2 fallback for CPUs without SHA-NI
sha1cdblock_amd64.go
amd64: Add an AVX2 fallback for CPUs without SHA-NI
sha1cdblock_amd64.s
amd64: Drop the AVX requirement from SHA-NI and fix state repair stalls
sha1cdblock_arm64_dirtyregs.s
arm64: Gate dirty-register test shim behind sha1cd_asmtest tag
sha1cdblock_arm64_test.go
test: Fuzz the assembly block against blockGeneric
sha1cdblock_arm64.go
cpu: Detect CPU features in-tree and drop klauspost/cpuid
sha1cdblock_arm64.s
arm64: Remove bounds check on uninitialised R16
sha1cdblock_asm_test.go
test: Check the whole compression state against an independent block
sha1cdblock_avx2_amd64.go
amd64: Add an AVX2 fallback for CPUs without SHA-NI
sha1cdblock_avx2_amd64.s
amd64: Add an AVX2 fallback for CPUs without SHA-NI
sha1cdblock_generic.go
amd64: Drop the AVX requirement from SHA-NI and fix state repair stalls
sha1cdblock_noasm.go
Remove type sliceHeader and use of unsafe

sha1cd

A Go implementation of SHA1 with counter-cryptanalysis, which detects collision attacks.

The cgo/lib code is a carbon copy of the original code, based on the award winning white paper by Marc Stevens.

The Go and native implementations are largely based off upstream Go.

Usage

sha1cd can be used as a drop-in replacement for crypto/sha1:

import "github.com/pjbgf/sha1cd"

func test(){
	data := []byte("data to be sha1 hashed")
	h := sha1cd.Sum(data)
	fmt.Printf("hash: %q\n", hex.EncodeToString(h))
}

To obtain information as to whether a collision was found, use the func CollisionResistantSum.

import "github.com/pjbgf/sha1cd"

func test(){
	data := []byte("data to be sha1 hashed")
	h, col  := sha1cd.CollisionResistantSum(data)
	if col {
		fmt.Println("collision found!")
	}
	fmt.Printf("hash: %q", hex.EncodeToString(h))
}

Note that the algorithm will automatically avoid collision, by extending the SHA1 to 240-steps, instead of 80 when a collision attempt is detected. Therefore, inputs that contains the unavoidable bit conditions will yield a different hash from sha1cd, when compared with results using crypto/sha1. Valid inputs will have matching the outputs.

References

Use of the Original Implementation