cryptoKdfDeriveFromKey static method

Uint8List cryptoKdfDeriveFromKey(
  1. int subkeyLen,
  2. int subkeyId,
  3. Uint8List ctx,
  4. Uint8List key,
)

Implementation

static Uint8List cryptoKdfDeriveFromKey(
    int subkeyLen, int subkeyId, Uint8List ctx, Uint8List key) {
  RangeError.checkValueInInterval(
      subkeyLen, cryptoKdfBytesMin, cryptoKdfBytesMax, 'subkeyLen');
  RangeError.checkValueInInterval(subkeyId, 0, (2 ^ 64) - 1, 'subkeyId');
  RangeError.checkValueInInterval(ctx.length, cryptoKdfContextbytes,
      cryptoKdfContextbytes, 'ctx', 'Invalid length');
  RangeError.checkValueInInterval(key.length, cryptoKdfKeybytes,
      cryptoKdfKeybytes, 'key', 'Invalid length');

  final _subkey = calloc<Uint8>(subkeyLen);
  final _ctx = ctx.toPointer();
  final _key = key.toPointer();

  try {
    _cryptoKdf
        .crypto_kdf_derive_from_key(_subkey, subkeyLen, subkeyId, _ctx, _key)
        .mustSucceed('crypto_kdf_derive_from_key');
    return _subkey.toList(subkeyLen);
  } finally {
    calloc.free(_subkey);
    calloc.free(_ctx);
    calloc.free(_key);
  }
}