decaps static method
Recovers the shared secret from ciphertext with privateKey, which may
be either the 2400-byte expanded key or the 64-byte seed.
Implementation
static Uint8List decaps(List<int> privateKey, List<int> ciphertext) =>
using((arena) {
final pkey = privateKey.length == seedLength
? keyFromOctetParam(arena, algorithm, 'seed', privateKey)
: rawPrivateKey(arena, algorithm, privateKey);
final ctx = checkNotNull(
ssl.EVP_PKEY_CTX_new_from_pkey(nullptr, pkey, nullptr),
'EVP_PKEY_CTX_new_from_pkey',
);
arena.using(ctx, ssl.EVP_PKEY_CTX_free);
checkOne(
ssl.EVP_PKEY_decapsulate_init(ctx, nullptr),
'EVP_PKEY_decapsulate_init',
);
final ssLen = arena<Size>()..value = sharedSecretLength;
final ss = secretBuffer(arena, sharedSecretLength);
checkOne(
ssl.EVP_PKEY_decapsulate(
ctx,
ss,
ssLen,
toNative(arena, ciphertext),
ciphertext.length,
),
'EVP_PKEY_decapsulate',
);
return fromNative(ss, ssLen.value);
});