Make sure KEM implementations don't return an empty shared secret

If `set_public_key` is never called we won't have a shared secret to
return.  This aligns the implementations with the one in the openssl
plugin.
This commit is contained in:
Tobias Brunner
2026-07-24 08:47:38 +02:00
parent 455b3e2298
commit 889d83b997
3 changed files with 18 additions and 6 deletions
+6 -2
View File
@@ -281,8 +281,12 @@ METHOD(key_exchange_t, set_public_key, bool,
METHOD(key_exchange_t, get_shared_secret, bool,
private_key_exchange_t *this, chunk_t *secret)
{
*secret = chunk_clone(this->shared_secret);
return TRUE;
if (this->shared_secret.ptr != NULL)
{
*secret = chunk_clone(this->shared_secret);
return TRUE;
}
return FALSE;
}
METHOD(key_exchange_t, get_method, key_exchange_method_t,
+6 -2
View File
@@ -942,8 +942,12 @@ METHOD(key_exchange_t, get_method, key_exchange_method_t,
METHOD(key_exchange_t, get_shared_secret, bool,
private_key_exchange_t *this, chunk_t *secret)
{
*secret = chunk_clone(this->shared_secret);
return TRUE;
if (this->shared_secret.ptr != NULL)
{
*secret = chunk_clone(this->shared_secret);
return TRUE;
}
return FALSE;
}
#ifdef TESTABLE_KE
@@ -241,8 +241,12 @@ METHOD(key_exchange_t, set_public_key, bool,
METHOD(key_exchange_t, get_shared_secret, bool,
private_key_exchange_t *this, chunk_t *secret)
{
*secret = chunk_clone(this->shared_secret);
return TRUE;
if (this->shared_secret.ptr != NULL)
{
*secret = chunk_clone(this->shared_secret);
return TRUE;
}
return FALSE;
}
METHOD(key_exchange_t, get_method, key_exchange_method_t,