void DSA_free(DSA *dsa) { if (dsa == NULL) { return; } if (!CRYPTO_refcount_dec_and_test_zero(&dsa->references)) { return; } if (dsa->meth->finish) { dsa->meth->finish(dsa); } METHOD_unref(dsa->meth); CRYPTO_free_ex_data(&g_ex_data_class, dsa, &dsa->ex_data); BN_clear_free(dsa->p); BN_clear_free(dsa->q); BN_clear_free(dsa->g); BN_clear_free(dsa->pub_key); BN_clear_free(dsa->priv_key); BN_clear_free(dsa->kinv); BN_clear_free(dsa->r); CRYPTO_MUTEX_cleanup(&dsa->method_mont_p_lock); OPENSSL_free(dsa); }
int asn1_refcount_dec_and_test_zero(ASN1_VALUE **pval, const ASN1_ITEM *it) { CRYPTO_refcount_t *references = asn1_get_references(pval, it); if (references != NULL) { return CRYPTO_refcount_dec_and_test_zero(references); } return 1; }
void X509_STORE_free(X509_STORE *vfy) { size_t j; STACK_OF(X509_LOOKUP) *sk; X509_LOOKUP *lu; if (vfy == NULL) return; if (!CRYPTO_refcount_dec_and_test_zero(&vfy->references)) { return; } CRYPTO_MUTEX_cleanup(&vfy->objs_lock); sk = vfy->get_cert_methods; for (j = 0; j < sk_X509_LOOKUP_num(sk); j++) { lu = sk_X509_LOOKUP_value(sk, j); X509_LOOKUP_shutdown(lu); X509_LOOKUP_free(lu); } sk_X509_LOOKUP_free(sk); sk_X509_OBJECT_pop_free(vfy->objs, cleanup); if (vfy->param) X509_VERIFY_PARAM_free(vfy->param); OPENSSL_free(vfy); }
void DH_free(DH *dh) { if (dh == NULL) { return; } if (!CRYPTO_refcount_dec_and_test_zero(&dh->references)) { return; } if (dh->meth->finish) { dh->meth->finish(dh); } METHOD_unref(dh->meth); CRYPTO_free_ex_data(&g_ex_data_class, dh, &dh->ex_data); if (dh->method_mont_p) BN_MONT_CTX_free(dh->method_mont_p); if (dh->p != NULL) BN_clear_free(dh->p); if (dh->g != NULL) BN_clear_free(dh->g); if (dh->q != NULL) BN_clear_free(dh->q); if (dh->j != NULL) BN_clear_free(dh->j); if (dh->seed) OPENSSL_free(dh->seed); if (dh->counter != NULL) BN_clear_free(dh->counter); if (dh->pub_key != NULL) BN_clear_free(dh->pub_key); if (dh->priv_key != NULL) BN_clear_free(dh->priv_key); CRYPTO_MUTEX_cleanup(&dh->method_mont_p_lock); OPENSSL_free(dh); }
MONO_API int mono_btls_ssl_ctx_free (MonoBtlsSslCtx *ctx) { if (!CRYPTO_refcount_dec_and_test_zero (&ctx->references)) return 0; SSL_CTX_free (ctx->ctx); ctx->instance = NULL; OPENSSL_free (ctx); return 1; }
void EVP_PKEY_free(EVP_PKEY *pkey) { if (pkey == NULL) { return; } if (!CRYPTO_refcount_dec_and_test_zero(&pkey->references)) { return; } free_it(pkey); OPENSSL_free(pkey); }
void EC_KEY_free(EC_KEY *r) { if (r == NULL) { return; } if (!CRYPTO_refcount_dec_and_test_zero(&r->references)) { return; } EC_POINT_free(r->pub_key); BN_clear_free(r->priv_key); OPENSSL_cleanse((void *)r, sizeof(EC_KEY)); OPENSSL_free(r); }
void CRYPTO_BUFFER_free(CRYPTO_BUFFER *buf) { if (buf == NULL) { return; } CRYPTO_BUFFER_POOL *const pool = buf->pool; if (pool == NULL) { if (CRYPTO_refcount_dec_and_test_zero(&buf->references)) { // If a reference count of zero is observed, there cannot be a reference // from any pool to this buffer and thus we are able to free this // buffer. OPENSSL_free(buf->data); OPENSSL_free(buf); } return; } CRYPTO_MUTEX_lock_write(&pool->lock); if (!CRYPTO_refcount_dec_and_test_zero(&buf->references)) { CRYPTO_MUTEX_unlock_write(&buf->pool->lock); return; } // We have an exclusive lock on the pool, therefore no concurrent lookups can // find this buffer and increment the reference count. Thus, if the count is // zero there are and can never be any more references and thus we can free // this buffer. void *found = lh_CRYPTO_BUFFER_delete(pool->bufs, buf); assert(found != NULL); assert(found == buf); (void)found; CRYPTO_MUTEX_unlock_write(&buf->pool->lock); OPENSSL_free(buf->data); OPENSSL_free(buf); }
void SSL_SESSION_free(SSL_SESSION *session) { if (session == NULL || !CRYPTO_refcount_dec_and_test_zero(&session->references)) { return; } CRYPTO_free_ex_data(&g_ex_data_class, session, &session->ex_data); OPENSSL_cleanse(session->master_key, sizeof(session->master_key)); OPENSSL_cleanse(session->session_id, sizeof(session->session_id)); X509_free(session->peer); sk_X509_pop_free(session->cert_chain, X509_free); OPENSSL_free(session->tlsext_hostname); OPENSSL_free(session->tlsext_tick); OPENSSL_free(session->tlsext_signed_cert_timestamp_list); OPENSSL_free(session->ocsp_response); OPENSSL_free(session->psk_identity); OPENSSL_cleanse(session, sizeof(*session)); OPENSSL_free(session); }
MONO_API int mono_btls_x509_lookup_free (MonoBtlsX509Lookup *lookup) { if (!CRYPTO_refcount_dec_and_test_zero (&lookup->references)) return 0; if (lookup->store) { mono_btls_x509_store_free (lookup->store); lookup->store = NULL; } if (lookup->lookup) { if (lookup->owns_lookup) X509_LOOKUP_free (lookup->lookup); lookup->lookup = NULL; } OPENSSL_free (lookup); return 1; }
void RSA_free(RSA *rsa) { unsigned u; if (rsa == NULL) { return; } if (!CRYPTO_refcount_dec_and_test_zero(&rsa->references)) { return; } if (rsa->meth->finish) { rsa->meth->finish(rsa); } METHOD_unref(rsa->meth); CRYPTO_free_ex_data(g_rsa_ex_data_class_bss_get(), rsa, &rsa->ex_data); BN_free(rsa->n); BN_free(rsa->e); BN_free(rsa->d); BN_free(rsa->p); BN_free(rsa->q); BN_free(rsa->dmp1); BN_free(rsa->dmq1); BN_free(rsa->iqmp); BN_MONT_CTX_free(rsa->mont_n); BN_MONT_CTX_free(rsa->mont_p); BN_MONT_CTX_free(rsa->mont_q); BN_free(rsa->d_fixed); BN_free(rsa->dmp1_fixed); BN_free(rsa->dmq1_fixed); BN_free(rsa->inv_small_mod_large_mont); for (u = 0; u < rsa->num_blindings; u++) { BN_BLINDING_free(rsa->blindings[u]); } OPENSSL_free(rsa->blindings); OPENSSL_free(rsa->blindings_inuse); CRYPTO_MUTEX_cleanup(&rsa->lock); OPENSSL_free(rsa); }
void RSA_free(RSA *rsa) { unsigned u; if (rsa == NULL) { return; } if (!CRYPTO_refcount_dec_and_test_zero(&rsa->references)) { return; } if (rsa->meth->finish) { rsa->meth->finish(rsa); } METHOD_unref(rsa->meth); CRYPTO_free_ex_data(&g_ex_data_class, rsa, &rsa->ex_data); BN_clear_free(rsa->n); BN_clear_free(rsa->e); BN_clear_free(rsa->d); BN_clear_free(rsa->p); BN_clear_free(rsa->q); BN_clear_free(rsa->dmp1); BN_clear_free(rsa->dmq1); BN_clear_free(rsa->iqmp); BN_MONT_CTX_free(rsa->mont_n); BN_MONT_CTX_free(rsa->mont_p); BN_MONT_CTX_free(rsa->mont_q); for (u = 0; u < rsa->num_blindings; u++) { BN_BLINDING_free(rsa->blindings[u]); } OPENSSL_free(rsa->blindings); OPENSSL_free(rsa->blindings_inuse); if (rsa->additional_primes != NULL) { sk_RSA_additional_prime_pop_free(rsa->additional_primes, RSA_additional_prime_free); } CRYPTO_MUTEX_cleanup(&rsa->lock); OPENSSL_free(rsa); }