verifies method

bool verifies(
  1. BigInt hash,
  2. ECDSASignature signature
)

Verifies an ECDSA signature against a hash value.

Parameters:

  • hash: A hash value of the message to be verified.
  • signature: An ECDSA signature to be verified.

Returns: true if the signature is valid, false otherwise.

Implementation

bool verifies(BigInt hash, ECDSASignature signature) {
  final ProjectiveECCPoint G = generator;
  final BigInt n = G.order!;
  final r = signature.r;
  final s = signature.s;

  if (r < BigInt.one || r > n - BigInt.one) {
    return false;
  }

  if (s < BigInt.one || s > n - BigInt.one) {
    return false;
  }
  final c = BigintUtils.inverseMod(s, n);
  final u1 = (hash * c) % n;
  final u2 = (r * c) % n;

  final xy = G.mulAdd(u1, point, u2);

  final v = xy.x % n;

  return v == r;
}