deriveSecretKey method

SecretKeyData deriveSecretKey({
  1. required SecretKeyData secretKey,
  2. required List<int> nonce,
})

Used by DartXchacha20Poly1305AeadMacAlgorithmSink.

Implementation

SecretKeyData deriveSecretKey({
  required SecretKeyData secretKey,
  required List<int> nonce,
}) {
  if (nonce.length != 12) {
    throw ArgumentError.value(
      nonce,
      'nonce',
      'Nonce must have 12 bytes, got ${nonce.length} bytes',
    );
  }
  List<int> newSecretKey = Uint8List(32);
  _chacha20State.initializeSync(
    isEncrypting: true,
    secretKey: secretKey,
    nonce: nonce,
  );
  newSecretKey = _chacha20State.convertSync(
    newSecretKey,
    possibleBuffer: newSecretKey is Uint8List ? newSecretKey : null,
  );
  return SecretKeyData(
    newSecretKey,
    overwriteWhenDestroyed: true,
  );
}