initialize method
Initializes the first two blocks of every lane.
Implementation
@visibleForTesting
void initialize({
required Uint8List h0,
}) {
if (h0.length != 64) {
throw ArgumentError();
}
// Our implementation uses the third block for temporarily storing input for
// the hash function.
final thirdBlock = getBlock(lane: 0, slice: 0, index: 3);
final input = Uint8List.view(
thirdBlock.buffer,
thirdBlock.offsetInBytes,
_blake2bSize + 8,
);
input.setAll(0, h0);
final inputByteData = ByteData.view(
input.buffer,
input.offsetInBytes,
input.lengthInBytes,
);
// For each lane
for (var lane = 0; lane < parallelism; lane++) {
// Set lane index
inputByteData.setUint32(
64 + 4,
lane,
Endian.little,
);
// Block 0 of the lane
{
// Set block index
inputByteData.setUint32(
64,
0,
Endian.little,
);
// BLAKE2B
final block = getBlock(lane: lane, slice: 0, index: 0);
variableLengthHash(
output: block.buffer.asUint8List(
block.offsetInBytes,
block.lengthInBytes,
),
input: input,
);
}
// Block 1 of the lane
{
// Set: block index
inputByteData.setUint32(
64,
1,
Endian.little,
);
// BLAKE2B
final block = getBlock(lane: lane, slice: 0, index: 1);
variableLengthHash(
output: block.buffer.asUint8List(
block.offsetInBytes,
block.lengthInBytes,
),
input: input,
);
}
}
// Erase the temporary buffer
input.fillRange(0, input.length, 0);
}