File: sha1cdblock_amd64.go

package info (click to toggle)
golang-github-pjbgf-sha1cd 0.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,576 kB
  • sloc: ansic: 2,188; asm: 1,527; makefile: 28
file content (50 lines) | stat: -rw-r--r-- 1,108 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//go:build !noasm && gc && amd64
// +build !noasm,gc,amd64

package sha1cd

import (
	"math"
	"unsafe"

	shared "github.com/pjbgf/sha1cd/internal"
)

type sliceHeader struct {
	base uintptr
	len  int
	cap  int
}

// blockAMD64 hashes the message p into the current state in dig.
// Both m1 and cs are used to store intermediate results which are used by the collision detection logic.
//
//go:noescape
func blockAMD64(dig *digest, p sliceHeader, m1 []uint32, cs [][5]uint32)

func block(dig *digest, p []byte) {
	m1 := [shared.Rounds]uint32{}
	cs := [shared.PreStepState][shared.WordBuffers]uint32{}

	for len(p) >= shared.Chunk {
		// Only send a block to be processed, as the collission detection
		// works on a block by block basis.
		ips := sliceHeader{
			base: uintptr(unsafe.Pointer(&p[0])),
			len:  int(math.Min(float64(len(p)), float64(shared.Chunk))),
			cap:  shared.Chunk,
		}

		blockAMD64(dig, ips, m1[:], cs[:])

		col := checkCollision(m1, cs, dig.h)
		if col {
			dig.col = true

			blockAMD64(dig, ips, m1[:], cs[:])
			blockAMD64(dig, ips, m1[:], cs[:])
		}

		p = p[shared.Chunk:]
	}
}