convert method
Transforms the message of bytes using the algorithm.
Implementation
@override
Uint8List convert(List<int> message) {
int i, j, n, m, pos;
int h0, h1, h2, h3;
int s0, s1, s2, s3;
n = message.length;
m = n + 16 - (n & 15);
final output = Uint8List(m);
final block32 = Uint32List(4); // 128-bit
final iv32 = Uint32List.view(iv.buffer);
final key32 = Uint32List.view(key.buffer);
final block = Uint8List.view(block32.buffer);
final output32 = Uint32List.view(output.buffer);
final xkey32 = AESCore.$expandEncryptionKey(key32);
s0 = iv32[0];
s1 = iv32[1];
s2 = iv32[2];
s3 = iv32[3];
// process 16-byte blocks
for (i = 0; i + 16 <= n; i += 16) {
h0 = (message[i + 0] ^
(message[i + 1] << 8) ^
(message[i + 2] << 16) ^
(message[i + 3] << 24));
h1 = ((message[i + 4]) ^
(message[i + 5] << 8) ^
(message[i + 6] << 16) ^
message[i + 7] << 24);
h2 = (message[i + 8] ^
(message[i + 9] << 8) ^
(message[i + 10] << 16) ^
(message[i + 11] << 24));
h3 = (message[i + 12] ^
(message[i + 13] << 8) ^
(message[i + 14] << 16) ^
(message[i + 15] << 24));
block32[0] = h0 ^ s0;
block32[1] = h1 ^ s1;
block32[2] = h2 ^ s2;
block32[3] = h3 ^ s3;
AESCore.$encryptLE(block32, xkey32);
s0 = block32[0] ^ h0;
s1 = block32[1] ^ h1;
s2 = block32[2] ^ h2;
s3 = block32[3] ^ h3;
j = i >>> 2;
output32[j + 0] = block32[0];
output32[j + 1] = block32[1];
output32[j + 2] = block32[2];
output32[j + 3] = block32[3];
}
// process last block
for (pos = 0; i + pos < n; ++pos) {
block[pos] = message[i + pos];
}
if (padding.pad(block, pos)) {
block32[0] ^= s0;
block32[1] ^= s1;
block32[2] ^= s2;
block32[3] ^= s3;
AESCore.$encryptLE(block32, xkey32);
j = i >>> 2;
output32[j + 0] = block32[0];
output32[j + 1] = block32[1];
output32[j + 2] = block32[2];
output32[j + 3] = block32[3];
i += 16;
pos = 0;
}
if (pos != 0) {
throw StateError('Invalid input size');
}
if (i == m) {
return output;
} else {
return output.sublist(0, i);
}
}