1//go:build !noasm && gc && arm64 && !amd64
 2// +build !noasm,gc,arm64,!amd64
 3
 4package sha1cd
 5
 6import (
 7	"runtime"
 8
 9	"github.com/klauspost/cpuid/v2"
10	shared "github.com/pjbgf/sha1cd/internal"
11)
12
13var hasSHA1 = (runtime.GOARCH == "arm64" && cpuid.CPU.Supports(cpuid.SHA1))
14
15// blockARM64 hashes the message p into the current state in h.
16// Both m1 and cs are used to store intermediate results which are used by the collision detection logic.
17//
18//go:noescape
19func blockARM64(h []uint32, p []byte, m1 []uint32, cs [][5]uint32)
20
21func block(dig *digest, p []byte) {
22	if forceGeneric || !hasSHA1 {
23		blockGeneric(dig, p)
24		return
25	}
26
27	m1 := [shared.Rounds]uint32{}
28	cs := [shared.PreStepState][shared.WordBuffers]uint32{}
29
30	for len(p) >= shared.Chunk {
31		// The assembly code only supports processing a block at a time,
32		// so adjust the chunk accordingly.
33		chunk := p[:shared.Chunk]
34
35		blockARM64(dig.h[:], chunk, m1[:], cs[:])
36
37		rectifyCompressionState(&m1, &cs)
38		col := checkCollision(&m1, &cs, &dig.h)
39		if col {
40			dig.col = true
41
42			blockARM64(dig.h[:], chunk, m1[:], cs[:])
43			blockARM64(dig.h[:], chunk, m1[:], cs[:])
44		}
45
46		p = p[shared.Chunk:]
47	}
48}