crypto: Make deleting NULL pointers noop

rsa-aes
Andri Yngvason 2023-09-05 08:46:11 +00:00
parent 7eb9882877
commit e7a24822a7
1 changed files with 6 additions and 0 deletions

View File

@ -143,6 +143,8 @@ struct crypto_key *crypto_key_new(int g, const uint8_t* p, uint32_t p_len,
void crypto_key_del(struct crypto_key* key) void crypto_key_del(struct crypto_key* key)
{ {
if (!key)
return;
mpz_clear(key->q); mpz_clear(key->q);
mpz_clear(key->p); mpz_clear(key->p);
free(key); free(key);
@ -558,6 +560,8 @@ struct crypto_rsa_pub_key *crypto_rsa_pub_key_new(void)
void crypto_rsa_pub_key_del(struct crypto_rsa_pub_key* self) void crypto_rsa_pub_key_del(struct crypto_rsa_pub_key* self)
{ {
if (!self)
return;
rsa_public_key_clear(&self->key); rsa_public_key_clear(&self->key);
free(self); free(self);
} }
@ -607,6 +611,8 @@ struct crypto_rsa_priv_key *crypto_rsa_priv_key_new(void)
void crypto_rsa_priv_key_del(struct crypto_rsa_priv_key* self) void crypto_rsa_priv_key_del(struct crypto_rsa_priv_key* self)
{ {
if (!self)
return;
rsa_private_key_clear(&self->key); rsa_private_key_clear(&self->key);
free(self); free(self);
} }