aesEncryptBlock function

Uint8List aesEncryptBlock(
  1. Uint8List roundKeys,
  2. Uint8List block16
)

Encrypts a single 16-byte block16 under the expanded roundKeys schedule (240 bytes from _expandKey). Returns a new 16-byte block.

Implementation

Uint8List aesEncryptBlock(Uint8List roundKeys, Uint8List block16) {
  if (block16.length != _blockSize) {
    throw ArgumentError('block must be 16 bytes, got ${block16.length}');
  }
  final state = Uint8List.fromList(block16);
  _addRoundKey(state, roundKeys, 0);
  for (var round = 1; round < _nr; round++) {
    _subBytes(state);
    _shiftRows(state);
    _mixColumns(state);
    _addRoundKey(state, roundKeys, round);
  }
  _subBytes(state);
  _shiftRows(state);
  _addRoundKey(state, roundKeys, _nr);
  return state;
}