processBlock method

  1. @visibleForTesting
void processBlock({
  1. required Uint32List output,
  2. required Uint32List input0,
  3. required Uint32List input1,
  4. required bool isXorred,
})

Processes a block.

Parameters output, input0, input1, and tmp are 1024 byte blocks.

Implementation

@visibleForTesting
void processBlock({
  required Uint32List output,
  required Uint32List input0,
  required Uint32List input1,
  required bool isXorred,
}) {
  final tmp = _tmpBlock;

  // In the specification:
  //   R = X ⊕ Y
  for (var i = 0; i < 256; i++) {
    tmp[i] = input0[i] ^ input1[i];
  }

  // Apply to P to each row
  //
  // Note that the input t the function P is:
  //   8 * 16 bytes = 32 * uint32
  for (var i = 0; i < 8; i++) {
    final row = i * 32;
    permutation(
      tmp,
      row,
      row + 4,
      row + 8,
      row + 12,
      row + 16,
      row + 20,
      row + 24,
      row + 28,
    );
  }

  // Apply to P to each column
  for (var i = 0; i < 8; i++) {
    final column = i * 4;
    permutation(
      tmp,
      0 + column,
      32 + column,
      64 + column,
      96 + column,
      128 + column,
      160 + column,
      192 + column,
      224 + column,
    );
  }

  // In the specification iteration:
  //   output = Z ⊕ R = Z ⊕ X ⊕ Y
  //
  // In the first iteration, we do not need to XOR without `output`.
  if (isXorred) {
    for (var i = 0; i < 256; i++) {
      output[i] ^= tmp[i] ^ input0[i] ^ input1[i];
    }
  } else {
    for (var i = 0; i < 256; i++) {
      output[i] = tmp[i] ^ input0[i] ^ input1[i];
    }
  }
}