deriveMessageKeys function

Map<String, Uint8List> deriveMessageKeys(
  1. Uint8List conversationKey,
  2. Uint8List nonce
)

Implementation

Map<String, Uint8List> deriveMessageKeys(
    Uint8List conversationKey, Uint8List nonce) {
  if (conversationKey.length != 32) {
    throw FormatException('Invalid conversation key length');
  }
  if (nonce.length != 32) {
    throw FormatException('Invalid nonce length');
  }

  final hkdfOutput = hkdfExpand(
    prk: conversationKey,
    info: nonce,
    length: 76,
  );

  return {
    'chachaKey': hkdfOutput.sublist(0, 32),
    'chachaNonce': hkdfOutput.sublist(32, 44), // Should be 12 bytes
    'hmacKey': hkdfOutput.sublist(44, 76),
  };
}