generateSignature method

  1. @override
Signature generateSignature(
  1. Uint8List message
)
override

Sign the passed in message (usually the output of a hash function)

Implementation

@override
Signature generateSignature(Uint8List message) {
  message = _hashMessageIfNeeded(message);

  var n = _pvkey!.parameters!.n;
  var e = _calculateE(n, message);
  BigInt r;
  BigInt s;

  dynamic kCalculator;
  if (_kMac != null) {
    kCalculator = _RFC6979KCalculator(_kMac, n, _pvkey!.d!, message);
  } else {
    kCalculator = _RandomKCalculator(n, _random!);
  }

  // 5.3.2
  do {
    // generate s
    BigInt? k;

    do {
      // generate r
      k = kCalculator.nextK() as BigInt?;

      var p = (_pvkey!.parameters!.G * k)!;

      // 5.3.3
      var x = p.x!.toBigInteger()!;

      r = x % n;
    } while (r == BigInt.zero);

    var d = _pvkey!.d!;

    s = (k!.modInverse(n) * (e + (d * r))) % n;
  } while (s == BigInt.zero);

  return ECSignature(r, s);
}