decapsulate method
Recover the shared secret from ciphertext using secretKey.
Implementation
@override
Future<Uint8List> decapsulate(
Uint8List secretKey, Uint8List ciphertext) async {
if (secretKey.length != seedLength) {
throw ArgumentError.value(secretKey.length, 'secretKey',
'X-Wing secret key must be the $seedLength-byte seed');
}
if (ciphertext.length != ciphertextLength) {
throw ArgumentError.value(ciphertext.length, 'ciphertext',
'X-Wing ciphertext must be $ciphertextLength bytes');
}
final Uint8List ctM = ciphertext.sublist(0, _mlKemCiphertextLength);
final Uint8List ctX = ciphertext.sublist(_mlKemCiphertextLength);
final _Expanded e = await _expand(secretKey);
try {
final Uint8List ssM =
await _mlKem.decapsulate(e.mlKemKeyPair.secretKey, ctM);
final Uint8List ssX = await _x25519.dh(e.x25519Secret, ctX);
return _combine(ssM, ssX, ctX, e.x25519Public);
} finally {
_mlKem.releaseKeyPair(e.mlKemKeyPair);
}
}