initializeSync method
- @mustCallSuper
- @override
- required SecretKeyData secretKey,
- required List<
int> nonce, - List<
int> aad = const [],
override
Re-initializes the sink.
Implementation
@mustCallSuper
@override
void initializeSync({
required SecretKeyData secretKey,
required List<int> nonce,
List<int> aad = const [],
}) {
_blockLength = 0;
_isClosed = false;
_mac = null;
_length = 0;
// RFC variable `r`
final r = _r;
final keyBytes = secretKey.bytes;
final key = Uint16List.view(
keyBytes is Uint8List
? keyBytes.buffer
: Uint8List.fromList(keyBytes).buffer,
);
// In RFC:
// r = (le_bytes_to_num(key[0..15])
// clamp(r)
final k0 = key[0];
r[0] = 0x1FFF & k0;
final k1 = key[1];
r[1] = 0x1FFF & ((k0 >> 13) | (k1 << 3));
final k2 = key[2];
r[2] = 0x1F03 & ((k1 >> 10) | (k2 << 6));
final k3 = key[3];
r[3] = 0x1FFF & ((k2 >> 7) | (k3 << 9));
r[4] = 0xFF & (k3 >> 4);
final k4 = key[4];
r[5] = 0x1FFE & (k4 >> 1);
final k5 = key[5];
r[6] = 0x1FFF & ((k4 >> 14) | (k5 << 2));
final k6 = key[6];
r[7] = 0x1F81 & ((k5 >> 11) | (k6 << 5));
final k7 = key[7];
r[8] = 0x1FFF & ((k6 >> 8) | (k7 << 8));
r[9] = 0x7F & (k7 >> 5);
// In RFC:
// s = le_num(key[16..31])
final s = _s;
final sBytes = Uint8List.view(s.buffer);
for (var i = 0; i < 16; i++) {
sBytes[i] = keyBytes[16 + i];
}
// Erase helper `h`
final h = _a;
for (var i = 0; i < 10; i++) {
h[i] = 0;
}
final buffer = _buffer;
buffer.setUint32(0, 0);
buffer.setUint32(4, 0);
buffer.setUint32(8, 0);
buffer.setUint32(12, 0);
buffer.setUint32(16, 0);
beforeData(
secretKey: secretKey,
nonce: nonce,
aad: aad,
);
}