|
@@ -35,7 +35,7 @@ int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx)
|
|
|
ctx->provctx = NULL;
|
|
|
}
|
|
|
if (ctx->fetched_cipher != NULL)
|
|
|
- EVP_CIPHER_meth_free(ctx->fetched_cipher);
|
|
|
+ EVP_CIPHER_free(ctx->fetched_cipher);
|
|
|
memset(ctx, 0, sizeof(*ctx));
|
|
|
|
|
|
return 1;
|
|
@@ -133,7 +133,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
|
|
|| impl != NULL) {
|
|
|
if (ctx->cipher == ctx->fetched_cipher)
|
|
|
ctx->cipher = NULL;
|
|
|
- EVP_CIPHER_meth_free(ctx->fetched_cipher);
|
|
|
+ EVP_CIPHER_free(ctx->fetched_cipher);
|
|
|
ctx->fetched_cipher = NULL;
|
|
|
goto legacy;
|
|
|
}
|
|
@@ -274,7 +274,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
|
|
return 0;
|
|
|
}
|
|
|
cipher = provciph;
|
|
|
- EVP_CIPHER_meth_free(ctx->fetched_cipher);
|
|
|
+ EVP_CIPHER_free(ctx->fetched_cipher);
|
|
|
ctx->fetched_cipher = provciph;
|
|
|
#endif
|
|
|
}
|
|
@@ -1244,6 +1244,21 @@ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+EVP_CIPHER *evp_cipher_new(void)
|
|
|
+{
|
|
|
+ EVP_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_CIPHER));
|
|
|
+
|
|
|
+ if (cipher != NULL) {
|
|
|
+ cipher->lock = CRYPTO_THREAD_lock_new();
|
|
|
+ if (cipher->lock == NULL) {
|
|
|
+ OPENSSL_free(cipher);
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+ cipher->refcnt = 1;
|
|
|
+ }
|
|
|
+ return cipher;
|
|
|
+}
|
|
|
+
|
|
|
static void *evp_cipher_from_dispatch(const char *name,
|
|
|
const OSSL_DISPATCH *fns,
|
|
|
OSSL_PROVIDER *prov,
|
|
@@ -1252,9 +1267,9 @@ static void *evp_cipher_from_dispatch(const char *name,
|
|
|
EVP_CIPHER *cipher = NULL;
|
|
|
int fnciphcnt = 0, fnctxcnt = 0;
|
|
|
|
|
|
- if ((cipher = EVP_CIPHER_meth_new(0, 0, 0)) == NULL
|
|
|
+ if ((cipher = evp_cipher_new()) == NULL
|
|
|
|| (cipher->name = OPENSSL_strdup(name)) == NULL) {
|
|
|
- EVP_CIPHER_meth_free(cipher);
|
|
|
+ EVP_CIPHER_free(cipher);
|
|
|
EVPerr(0, ERR_R_MALLOC_FAILURE);
|
|
|
return NULL;
|
|
|
}
|
|
@@ -1361,7 +1376,7 @@ static void *evp_cipher_from_dispatch(const char *name,
|
|
|
* functions, or a single "cipher" function. In all cases we need both
|
|
|
* the "newctx" and "freectx" functions.
|
|
|
*/
|
|
|
- EVP_CIPHER_meth_free(cipher);
|
|
|
+ EVP_CIPHER_free(cipher);
|
|
|
EVPerr(EVP_F_EVP_CIPHER_FROM_DISPATCH, EVP_R_INVALID_PROVIDER_FUNCTIONS);
|
|
|
return NULL;
|
|
|
}
|
|
@@ -1379,7 +1394,7 @@ static int evp_cipher_up_ref(void *cipher)
|
|
|
|
|
|
static void evp_cipher_free(void *cipher)
|
|
|
{
|
|
|
- EVP_CIPHER_meth_free(cipher);
|
|
|
+ EVP_CIPHER_free(cipher);
|
|
|
}
|
|
|
|
|
|
EVP_CIPHER *EVP_CIPHER_fetch(OPENSSL_CTX *ctx, const char *algorithm,
|
|
@@ -1393,6 +1408,30 @@ EVP_CIPHER *EVP_CIPHER_fetch(OPENSSL_CTX *ctx, const char *algorithm,
|
|
|
return cipher;
|
|
|
}
|
|
|
|
|
|
+int EVP_CIPHER_up_ref(EVP_CIPHER *cipher)
|
|
|
+{
|
|
|
+ int ref = 0;
|
|
|
+
|
|
|
+ CRYPTO_UP_REF(&cipher->refcnt, &ref, cipher->lock);
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
+void EVP_CIPHER_free(EVP_CIPHER *cipher)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+
|
|
|
+ if (cipher == NULL)
|
|
|
+ return;
|
|
|
+
|
|
|
+ CRYPTO_DOWN_REF(&cipher->refcnt, &i, cipher->lock);
|
|
|
+ if (i > 0)
|
|
|
+ return;
|
|
|
+ ossl_provider_free(cipher->prov);
|
|
|
+ OPENSSL_free(cipher->name);
|
|
|
+ CRYPTO_THREAD_lock_free(cipher->lock);
|
|
|
+ OPENSSL_free(cipher);
|
|
|
+}
|
|
|
+
|
|
|
void EVP_CIPHER_do_all_ex(OPENSSL_CTX *libctx,
|
|
|
void (*fn)(EVP_CIPHER *mac, void *arg),
|
|
|
void *arg)
|