#include <openssl/objects.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
-#ifndef OPENSSL_NO_RSA
-# include <openssl/rsa.h>
-#endif
-#ifndef OPENSSL_NO_DSA
-# include <openssl/dsa.h>
-#endif
-#ifndef OPENSSL_NO_DH
-# include <openssl/dh.h>
-#endif
-
-#ifndef OPENSSL_NO_ENGINE
-# include <openssl/engine.h>
-#endif
+#include <openssl/rsa.h>
+#include <openssl/dsa.h>
+#include <openssl/dh.h>
+#include <openssl/engine.h>
#include "internal/asn1_int.h"
#include "internal/evp_int.h"
if (ret == NULL) {
EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE);
- return (NULL);
+ return NULL;
}
ret->type = EVP_PKEY_NONE;
ret->save_type = EVP_PKEY_NONE;
ret->references = 1;
ret->save_parameters = 1;
- return (ret);
+ ret->lock = CRYPTO_THREAD_lock_new();
+ if (ret->lock == NULL) {
+ EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE);
+ OPENSSL_free(ret);
+ return NULL;
+ }
+ return ret;
}
void EVP_PKEY_up_ref(EVP_PKEY *pkey)
{
- CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
+ int i;
+ CRYPTO_atomic_add(&pkey->references, 1, &i, pkey->lock);
}
/*
return 1;
#ifndef OPENSSL_NO_ENGINE
/* If we have an ENGINE release it */
- if (pkey->engine) {
- ENGINE_finish(pkey->engine);
- pkey->engine = NULL;
- }
+ ENGINE_finish(pkey->engine);
+ pkey->engine = NULL;
#endif
}
if (str)
else
ameth = EVP_PKEY_asn1_find(&e, type);
#ifndef OPENSSL_NO_ENGINE
- if (!pkey && e)
+ if (pkey == NULL)
ENGINE_finish(e);
#endif
- if (!ameth) {
+ if (ameth == NULL) {
EVPerr(EVP_F_PKEY_SET_TYPE, EVP_R_UNSUPPORTED_ALGORITHM);
return 0;
}
else
ret = NID_undef;
#ifndef OPENSSL_NO_ENGINE
- if (e)
- ENGINE_finish(e);
+ ENGINE_finish(e);
#endif
return ret;
}
if (x == NULL)
return;
- i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_EVP_PKEY);
+ CRYPTO_atomic_add(&x->references, -1, &i, x->lock);
REF_PRINT_COUNT("EVP_PKEY", x);
if (i > 0)
return;
x->pkey.ptr = NULL;
}
#ifndef OPENSSL_NO_ENGINE
- if (x->engine) {
- ENGINE_finish(x->engine);
- x->engine = NULL;
- }
+ ENGINE_finish(x->engine);
+ x->engine = NULL;
#endif
+ CRYPTO_THREAD_lock_free(x->lock);
}
static int unsup_alg(BIO *out, const EVP_PKEY *pkey, int indent,