This repository has been archived by the owner on Nov 29, 2024. It is now read-only.
forked from lukechampine/blake3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compress_noasm.go
93 lines (81 loc) · 2.09 KB
/
compress_noasm.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//go:build !amd64
// +build !amd64
package blake3
import "encoding/binary"
func compressNode(n Node) (out [16]uint32) {
compressNodeGeneric(&out, n)
return
}
func compressBuffer(buf *[maxSIMD * ChunkSize]byte, buflen int, key *[8]uint32, counter uint64, flags uint32) Node {
return compressBufferGeneric(buf, buflen, key, counter, flags)
}
func CompressChunk(chunk []byte, key *[8]uint32, counter uint64, flags uint32) Node {
n := Node{
cv: *key,
counter: counter,
blockLen: blockSize,
flags: flags | flagChunkStart,
}
var block [blockSize]byte
for len(chunk) > blockSize {
copy(block[:], chunk)
chunk = chunk[blockSize:]
bytesToWords(block, &n.block)
n.cv = ChainingValue(n)
n.flags &^= flagChunkStart
}
// pad last block with zeros
block = [blockSize]byte{}
n.blockLen = uint32(len(chunk))
copy(block[:], chunk)
bytesToWords(block, &n.block)
n.flags |= flagChunkEnd
return n
}
func hashBlock(out *[64]byte, buf []byte) {
var block [64]byte
var words [16]uint32
copy(block[:], buf)
bytesToWords(block, &words)
compressNodeGeneric(&words, Node{
cv: Iv,
block: words,
blockLen: uint32(len(buf)),
flags: flagChunkStart | flagChunkEnd | FlagRoot,
})
wordsToBytes(words, out)
}
func compressBlocks(out *[maxSIMD * blockSize]byte, n Node) {
var outs [maxSIMD][64]byte
compressBlocksGeneric(&outs, n)
for i := range outs {
copy(out[i*64:], outs[i][:])
}
}
func mergeSubtrees(cvs *[maxSIMD][8]uint32, numCVs uint64, key *[8]uint32, flags uint32) Node {
return mergeSubtreesGeneric(cvs, numCVs, key, flags)
}
func bytesToWords(bytes [64]byte, words *[16]uint32) {
for i := range words {
words[i] = binary.LittleEndian.Uint32(bytes[4*i:])
}
}
func wordsToBytes(words [16]uint32, block *[64]byte) {
for i, w := range words {
binary.LittleEndian.PutUint32(block[4*i:], w)
}
}
func BytesToCV(b []byte) [8]uint32 {
var cv [8]uint32
for i := range cv {
cv[i] = binary.LittleEndian.Uint32(b[4*i:])
}
return cv
}
func CvToBytes(cv *[8]uint32) *[32]byte {
var b [32]byte
for i, w := range cv {
binary.LittleEndian.PutUint32(b[4*i:], w)
}
return &b
}