init method

  1. @override
void init(
  1. bool forEncryption,
  2. CipherParameters? params
)
override

Initialise the cipher and, possibly, the initialisation vector (IV). If an IV isn't passed as part of the parameter, the IV will be all zeros. An IV which is too short is handled in FIPS compliant fashion.

Implementation

@override
void init(bool forEncryption, CipherParameters? params) {
  if (params is ParametersWithIV) {
    var ivParam = params;
    var iv = ivParam.iv;

    if (iv.length < _iv.length) {
      // prepend the supplied IV with zeros (per FIPS PUB 81)
      var offset = _iv.length - iv.length;
      _iv.fillRange(0, offset, 0);
      _iv.setAll(offset, iv);
    } else {
      _iv.setRange(0, _iv.length, iv);
    }

    reset();

    // if null it's an IV changed only.
    if (ivParam.parameters != null) {
      _underlyingCipher.init(true, ivParam.parameters);
    }
  } else {
    _underlyingCipher.init(true, params);
  }
}