beforeData method
void
beforeData({
- required SecretKeyData secretKey,
- required List<
int> nonce, - List<
int> aad = const [],
override
A protected method required by DartChacha20Poly1305AeadMacAlgorithm implementation.
Implementation
@override
void beforeData({
required SecretKeyData secretKey,
required List<int> nonce,
List<int> aad = const [],
}) {
// Add Additional Authenticated Data (AAD)
final aadLength = aad.length;
_aadLength = aadLength;
if (aadLength != 0) {
add(aad);
// Add padding until 16-byte aligned
final rem = aad.length % 16;
if (rem != 0) {
// Fill `tmp` with zeroes
final tmp = _tmpAsByteData;
tmp.setUint32(0, 0);
tmp.setUint32(4, 0);
tmp.setUint32(8, 0);
tmp.setUint32(12, 0);
final paddingLength = 16 - rem;
addSlice(_tmpAsUint8List, 0, paddingLength, false);
}
}
// Initialize ChaCha20 initial state
super.beforeData(
secretKey: secretKey,
nonce: nonce,
aad: const [],
);
}