/*
- * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
#include <stdio.h>
#include <openssl/bn.h>
-#include <openssl/engine.h>
+#ifndef FIPS_MODULE
+# include <openssl/engine.h>
+#endif
#include <openssl/obj_mac.h>
#include <openssl/core_names.h>
#include "internal/cryptlib.h"
return 1;
}
-const DH_METHOD *dh_get_method(const DH *dh)
+const DH_METHOD *ossl_dh_get_method(const DH *dh)
{
return dh->meth;
}
}
#endif /* !FIPS_MODULE */
-DH *dh_new_ex(OSSL_LIB_CTX *libctx)
+DH *ossl_dh_new_ex(OSSL_LIB_CTX *libctx)
{
return dh_new_intern(NULL, libctx);
}
{
DH *ret = OPENSSL_zalloc(sizeof(*ret));
- if (ret == NULL) {
- ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE);
+ if (ret == NULL)
return NULL;
- }
- ret->references = 1;
ret->lock = CRYPTO_THREAD_lock_new();
if (ret->lock == NULL) {
- ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_DH, ERR_R_CRYPTO_LIB);
+ OPENSSL_free(ret);
+ return NULL;
+ }
+
+ if (!CRYPTO_NEW_REF(&ret->references, 1)) {
+ CRYPTO_THREAD_lock_free(ret->lock);
OPENSSL_free(ret);
return NULL;
}
goto err;
#endif /* FIPS_MODULE */
+ ossl_ffc_params_init(&ret->params);
+
if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
ERR_raise(ERR_LIB_DH, ERR_R_INIT_FAIL);
goto err;
if (r == NULL)
return;
- CRYPTO_DOWN_REF(&r->references, &i, r->lock);
+ CRYPTO_DOWN_REF(&r->references, &i);
REF_PRINT_COUNT("DH", r);
if (i > 0)
return;
#endif
CRYPTO_THREAD_lock_free(r->lock);
+ CRYPTO_FREE_REF(&r->references);
ossl_ffc_params_cleanup(&r->params);
BN_clear_free(r->pub_key);
{
int i;
- if (CRYPTO_UP_REF(&r->references, &i, r->lock) <= 0)
+ if (CRYPTO_UP_REF(&r->references, &i) <= 0)
return 0;
REF_PRINT_COUNT("DH", r);
int DH_security_bits(const DH *dh)
{
int N;
+
if (dh->params.q != NULL)
N = BN_num_bits(dh->params.q);
else if (dh->length)
return 0;
ossl_ffc_params_set0_pqg(&dh->params, p, q, g);
- dh_cache_named_group(dh);
+ ossl_dh_cache_named_group(dh);
dh->dirty_cnt++;
return 1;
}
}
#endif /*FIPS_MODULE */
-FFC_PARAMS *dh_get0_params(DH *dh)
+FFC_PARAMS *ossl_dh_get0_params(DH *dh)
{
return &dh->params;
}
-int dh_get0_nid(const DH *dh)
+int ossl_dh_get0_nid(const DH *dh)
{
return dh->params.nid;
}