main
1//go:build !noasm && gc && amd64
2// +build !noasm,gc,amd64
3
4package sha1cd
5
6import (
7 "math"
8 "unsafe"
9
10 shared "github.com/pjbgf/sha1cd/internal"
11)
12
13type sliceHeader struct {
14 base uintptr
15 len int
16 cap int
17}
18
19// blockAMD64 hashes the message p into the current state in dig.
20// Both m1 and cs are used to store intermediate results which are used by the collision detection logic.
21//
22//go:noescape
23func blockAMD64(dig *digest, p sliceHeader, m1 []uint32, cs [][5]uint32)
24
25func block(dig *digest, p []byte) {
26 m1 := [shared.Rounds]uint32{}
27 cs := [shared.PreStepState][shared.WordBuffers]uint32{}
28
29 for len(p) >= shared.Chunk {
30 // Only send a block to be processed, as the collission detection
31 // works on a block by block basis.
32 ips := sliceHeader{
33 base: uintptr(unsafe.Pointer(&p[0])),
34 len: int(math.Min(float64(len(p)), float64(shared.Chunk))),
35 cap: shared.Chunk,
36 }
37
38 blockAMD64(dig, ips, m1[:], cs[:])
39
40 col := checkCollision(m1, cs, dig.h)
41 if col {
42 dig.col = true
43
44 blockAMD64(dig, ips, m1[:], cs[:])
45 blockAMD64(dig, ips, m1[:], cs[:])
46 }
47
48 p = p[shared.Chunk:]
49 }
50}