computeParts static method
Computes HMAC-SHA256 over multiple parts without concatenating externally.
Example:
final tag = HmacSha256.computeParts(key, [part1, part2, part3]);
HINT: Prefer this to reduce temporary allocations for large payloads.
Implementation
static Uint8List computeParts(Uint8List key, List<Uint8List> parts) {
// 1) Normalize key to K0 (block-size bytes)
final k0 = _normalizeKey(key);
// 2) Prepare ipad/opad = K0 ⊕ ipad/opad
final ipad = Uint8List(_blockSize);
final opad = Uint8List(_blockSize);
for (var i = 0; i < _blockSize; i++) {
final b = k0[i];
ipad[i] = b ^ 0x36;
opad[i] = b ^ 0x5c;
}
// 3) inner = SHA256(ipad || data...)
final innerConcat = <Uint8List>[ipad, ...parts];
final inner = _sha256(Bytes.concat(innerConcat));
// 4) tag = SHA256(opad || inner)
final tag = _sha256(Bytes.concat([opad, inner]));
// Zeroize temporary pads as a best-effort hygiene.
Bytes.secureZero(ipad);
Bytes.secureZero(opad);
Bytes.secureZero(k0);
return tag;
}