verifySignature method

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

Verify the message against the signature.

Implementation

@override
bool verifySignature(Uint8List message, covariant PSSSignature signature) {
  if (_forSigning) {
    throw StateError('Signer was not initialised for signature verification');
  }

  _contentDigest.reset();
  _contentDigest.update(message, 0, message.length);
  _contentDigest.doFinal(_mDash, _mDash.length - _hLen - _sLen);

  var b = _cipher.process(signature.bytes);
  _block.fillRange(0, _block.length - b.length, 0);
  arrayCopy(b, 0, _block, _block.length - b.length, b.length);

  var firstByteMask = 0xFF >> ((_block.length * 8) - _emBits);

  if (_block[0] != (_block[0] & firstByteMask) ||
      _block[_block.length - 1] != _trailer) {
    _clearBlock(_block);
    return false;
  }

  var dbMask = _maskGeneratorFunction1(
      _block, _block.length - _hLen - 1, _hLen, _block.length - _hLen - 1);

  for (var i = 0; i != dbMask.length; i++) {
    _block[i] ^= dbMask[i];
  }

  _block[0] &= firstByteMask;

  for (var i = 0; i != _block.length - _hLen - _sLen - 2; i++) {
    if (_block[i] != 0) {
      _clearBlock(_block);
      return false;
    }
  }

  if (_block[_block.length - _hLen - _sLen - 2] != 0x01) {
    _clearBlock(_block);
    return false;
  }

  if (_sSet) {
    arrayCopy(_salt, 0, _mDash, _mDash.length - _sLen, _sLen);
  } else {
    arrayCopy(_block, _block.length - _sLen - _hLen - 1, _mDash,
        _mDash.length - _sLen, _sLen);
  }

  _contentDigest.update(_mDash, 0, _mDash.length);
  _contentDigest.doFinal(_mDash, _mDash.length - _hLen);

  for (var i = _block.length - _hLen - 1, j = _mDash.length - _hLen;
      j != _mDash.length;
      i++, j++) {
    if ((_block[i] ^ _mDash[j]) != 0) {
      _clearBlock(_mDash);
      _clearBlock(_block);
      return false;
    }
  }

  _clearBlock(_mDash);
  _clearBlock(_block);
  return true;
}