pkcs11: Move shared secret calculation to get_shared_secret()

This commit is contained in:
Tobias Brunner
2022-06-29 10:28:50 +02:00
parent d95082ce0d
commit 26ca0c9f70
+12 -3
View File
@@ -60,6 +60,11 @@ struct private_pkcs11_dh_t {
*/ */
chunk_t pub_key; chunk_t pub_key;
/**
* Public value provided by peer
*/
chunk_t other;
/** /**
* Shared secret * Shared secret
*/ */
@@ -122,6 +127,7 @@ METHOD(key_exchange_t, set_public_key, bool,
return FALSE; return FALSE;
} }
chunk_clear(&this->other);
switch (this->group) switch (this->group)
{ {
case ECP_192_BIT: case ECP_192_BIT:
@@ -140,13 +146,14 @@ METHOD(key_exchange_t, set_public_key, bool,
pubkey.len, pubkey.len,
pubkey.ptr, pubkey.ptr,
}; };
value = chunk_from_thing(params); this->other = chunk_clone(chunk_from_thing(params));
break; break;
} }
default: default:
this->other = chunk_clone(value);
break; break;
} }
return derive_secret(this, value); return TRUE;
} }
METHOD(key_exchange_t, get_public_key, bool, METHOD(key_exchange_t, get_public_key, bool,
@@ -159,7 +166,8 @@ METHOD(key_exchange_t, get_public_key, bool,
METHOD(key_exchange_t, get_shared_secret, bool, METHOD(key_exchange_t, get_shared_secret, bool,
private_pkcs11_dh_t *this, chunk_t *secret) private_pkcs11_dh_t *this, chunk_t *secret)
{ {
if (!this->secret.ptr) if (!this->secret.ptr &&
!derive_secret(this, this->other))
{ {
return FALSE; return FALSE;
} }
@@ -179,6 +187,7 @@ METHOD(key_exchange_t, destroy, void,
this->lib->f->C_CloseSession(this->session); this->lib->f->C_CloseSession(this->session);
chunk_clear(&this->pub_key); chunk_clear(&this->pub_key);
chunk_clear(&this->secret); chunk_clear(&this->secret);
chunk_clear(&this->other);
free(this); free(this);
} }