This repository has been archived on 2023-05-01. You can view files and clone it, but cannot push or open issues or pull requests.
blake3/compress_noasm.go

65 lines
1.5 KiB
Go

// +build !amd64
package blake3
import "encoding/binary"
func compressNode(n node) (out [16]uint32) {
compressNodeGeneric(&out, n)
return
}
func compressBuffer(buf *[8192]byte, length int, key *[8]uint32, counter uint64, flags uint32) node {
return compressBufferGeneric(buf, length, 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 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)
}
}