From 633f7e15c1fbf443bbad752bc45cf2b59d822d6e Mon Sep 17 00:00:00 2001 From: lukechampine Date: Sat, 11 Jan 2020 20:58:07 -0500 Subject: [PATCH] only pad block when necessary --- blake3.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/blake3.go b/blake3.go index c68dee4..5ede51f 100644 --- a/blake3.go +++ b/blake3.go @@ -244,9 +244,6 @@ func (cs *chunkState) update(input []byte) { cs.n.cv = cs.n.chainingValue() // clear the start flag for all but the first block cs.n.flags &^= flagChunkStart - // reset the chunk block. It must contain zeros, because BLAKE3 - // blocks are zero-padded. - cs.block = [blockSize]byte{} cs.blockLen = 0 } @@ -258,10 +255,19 @@ func (cs *chunkState) update(input []byte) { } } +// compiles to memclr +func clear(b []byte) { + for i := range b { + b[i] = 0 + } +} + // node returns a node containing the chunkState's current state, with the // ChunkEnd flag set. func (cs *chunkState) node() node { n := cs.n + // pad the remaining space in the block with zeros + clear(cs.block[cs.blockLen:]) bytesToWords(cs.block[:], n.block[:]) n.blockLen = uint32(cs.blockLen) n.flags |= flagChunkEnd