encryptBlock method
Encrypts the block at input[inputOffset..+16) into
output[outputOffset..+16) (may alias).
Implementation
void encryptBlock(
Uint8List input,
int inputOffset,
Uint8List output,
int outputOffset,
) {
final rk = _encKeys;
final te0 = _t.te0, te1 = _t.te1, te2 = _t.te2, te3 = _t.te3;
var s0 = _load(input, inputOffset) ^ rk[0];
var s1 = _load(input, inputOffset + 4) ^ rk[1];
var s2 = _load(input, inputOffset + 8) ^ rk[2];
var s3 = _load(input, inputOffset + 12) ^ rk[3];
var k = 4;
for (var round = 1; round < _rounds; round++, k += 4) {
final t0 =
te0[s0 >>> 24] ^
te1[(s1 >>> 16) & 0xFF] ^
te2[(s2 >>> 8) & 0xFF] ^
te3[s3 & 0xFF] ^
rk[k];
final t1 =
te0[s1 >>> 24] ^
te1[(s2 >>> 16) & 0xFF] ^
te2[(s3 >>> 8) & 0xFF] ^
te3[s0 & 0xFF] ^
rk[k + 1];
final t2 =
te0[s2 >>> 24] ^
te1[(s3 >>> 16) & 0xFF] ^
te2[(s0 >>> 8) & 0xFF] ^
te3[s1 & 0xFF] ^
rk[k + 2];
final t3 =
te0[s3 >>> 24] ^
te1[(s0 >>> 16) & 0xFF] ^
te2[(s1 >>> 8) & 0xFF] ^
te3[s2 & 0xFF] ^
rk[k + 3];
s0 = t0;
s1 = t1;
s2 = t2;
s3 = t3;
}
final sbox = _t.sbox;
_store(
output,
outputOffset,
((sbox[s0 >>> 24] << 24) |
(sbox[(s1 >>> 16) & 0xFF] << 16) |
(sbox[(s2 >>> 8) & 0xFF] << 8) |
sbox[s3 & 0xFF]) ^
rk[k],
);
_store(
output,
outputOffset + 4,
((sbox[s1 >>> 24] << 24) |
(sbox[(s2 >>> 16) & 0xFF] << 16) |
(sbox[(s3 >>> 8) & 0xFF] << 8) |
sbox[s0 & 0xFF]) ^
rk[k + 1],
);
_store(
output,
outputOffset + 8,
((sbox[s2 >>> 24] << 24) |
(sbox[(s3 >>> 16) & 0xFF] << 16) |
(sbox[(s0 >>> 8) & 0xFF] << 8) |
sbox[s1 & 0xFF]) ^
rk[k + 2],
);
_store(
output,
outputOffset + 12,
((sbox[s3 >>> 24] << 24) |
(sbox[(s0 >>> 16) & 0xFF] << 16) |
(sbox[(s1 >>> 8) & 0xFF] << 8) |
sbox[s2 & 0xFF]) ^
rk[k + 3],
);
}