decapsulate method
Implementation
@override
Uint8List decapsulate(Uint8List ciphertext, Uint8List secretKey) {
if (ciphertext.length != _params.ciphertextBytes) {
throw MLKEMCiphertextWrongLengthException();
}
if (secretKey.length != _params.secretKeyBytes) {
throw MLKEMSecretKeyWrongLengthException();
}
final ct = calloc<ffi.Uint8>(_params.ciphertextBytes);
ct.asTypedList(_params.ciphertextBytes).setAll(0, ciphertext);
final sk = calloc<ffi.Uint8>(_params.secretKeyBytes);
sk.asTypedList(_params.secretKeyBytes).setAll(0, secretKey);
final ss = calloc<ffi.Uint8>(_params.sharedBytes);
final result = _params.dec(ss, ct, sk);
if (result != 0) {
calloc.free(ct);
calloc.free(sk);
calloc.free(ss);
throw MLKEMDecapsulationFailedException(result);
}
final ssBytes = Uint8List.fromList(ss.asTypedList(_params.sharedBytes));
calloc.free(ct);
calloc.free(sk);
calloc.free(ss);
return ssBytes;
}