verify function

bool verify(
  1. Uint8List a,
  2. Uint8List b
)

Compares two byte arrays a and b in constant time. Returns true if they are identical, false otherwise. This function avoids early exits that could leak information.

Implementation

bool verify(Uint8List a, Uint8List b) {
  if (a.length != b.length) return false;
  int r = 0;
  for (int i = 0; i < a.length; i++) {
    r |= a[i] ^ b[i];
  }
  return r == 0;
}