init method

  1. @override
void init(
  1. bool encrypting,
  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.

@param encrypting if true the cipher is initialised for encryption, if false for decryption. //ignored by this CTR mode @param params the key and other data required by the cipher. @exception IllegalArgumentException if the params argument is inappropriate.

Implementation

@override
void init(bool encrypting, CipherParameters? params) {
  _firstStep = true;
  _n3 = 0;
  _n4 = 0;

  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.setRange(offset, _iv.length, iv);
    } else {
      _iv.setRange(0, _iv.length, iv);
    }

    reset();

    // if params is null we reuse the current working key.
    if (ivParam.parameters != null) {
      _underlyingCipher.init(true, ivParam.parameters);
    }
  } else {
    // TODO: make this behave in a standard way (as the other modes of operation)
    reset();

    // if params is null we reuse the current working key.
    if (params != null) {
      _underlyingCipher.init(true, params);
    }
  }
}