polyMod static method

int polyMod(
  1. List<int> values
)

Computes the polynomial modulus.

Implementation

static int polyMod(List<int> values) {
  // Generator polynomial
  final generator = [
    0x3b6a57b2,
    0x26508e6d,
    0x1ea119fa,
    0x3d4233dd,
    0x2a1462b3
  ];

  // Compute modulus
  var chk = 1;
  for (final value in values) {
    final top = chk >> 25;
    chk = (chk & 0x1ffffff) << 5 ^ value;
    for (var i = 0; i < 5; i++) {
      chk ^= (top >> i) & 1 != 0 ? generator[i] : 0;
    }
  }
  return chk;
}