verifySignature method

  1. @override
bool verifySignature(
  1. Uint8List message,
  2. covariant ECSignature signature
)
override

Verify the message against the signature.

Implementation

@override
bool verifySignature(Uint8List message, covariant ECSignature signature) {
  message = _hashMessageIfNeeded(message);

  var n = _pbkey!.parameters!.n;
  var e = _calculateE(n, message);

  var r = signature.r;
  var s = signature.s;

  // r in the range [1,n-1]
  if (r.compareTo(BigInt.one) < 0 || r.compareTo(n) >= 0) {
    return false;
  }

  // s in the range [1,n-1]
  if (s.compareTo(BigInt.one) < 0 || s.compareTo(n) >= 0) {
    return false;
  }

  var c = s.modInverse(n);

  var u1 = (e * c) % n;
  var u2 = (r * c) % n;

  var G = _pbkey!.parameters!.G;
  var Q = _pbkey!.Q!;

  var point = _sumOfTwoMultiplies(G, u1, Q, u2)!;

  // components must be bogus.
  if (point.isInfinity) {
    return false;
  }

  var v = point.x!.toBigInteger()! % n;

  return v == r;
}