2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/evp.h>
11 #include <openssl/core_names.h>
12 #include "internal/provider_util.h"
14 void ossl_prov_cipher_reset(PROV_CIPHER *pc)
16 EVP_CIPHER_free(pc->alloc_cipher);
17 pc->alloc_cipher = NULL;
23 int ossl_prov_cipher_copy(PROV_CIPHER *dst, const PROV_CIPHER *src)
25 if (src->alloc_cipher != NULL && !EVP_CIPHER_up_ref(src->alloc_cipher))
27 dst->engine = src->engine;
28 dst->cipher = src->cipher;
29 dst->alloc_cipher = src->alloc_cipher;
30 OPENSSL_strlcpy(dst->name, src->name, sizeof(dst->name));
34 static int load_common(const OSSL_PARAM params[], const char **propquery,
40 p = OSSL_PARAM_locate_const(params, OSSL_ALG_PARAM_PROPERTIES);
42 if (p->data_type != OSSL_PARAM_UTF8_STRING)
48 /* TODO legacy stuff, to be removed */
49 /* Inside the FIPS module, we don't support legacy ciphers */
50 #if !defined(FIPS_MODE) && !defined(OPENSSL_NO_ENGINE)
51 p = OSSL_PARAM_locate_const(params, OSSL_ALG_PARAM_ENGINE);
53 if (p->data_type != OSSL_PARAM_UTF8_STRING)
55 ENGINE_finish(*engine);
56 *engine = ENGINE_by_id(p->data);
64 int ossl_prov_cipher_load_from_params(PROV_CIPHER *pc,
65 const OSSL_PARAM params[],
69 const char *propquery;
71 if (!load_common(params, &propquery, &pc->engine))
74 p = OSSL_PARAM_locate_const(params, OSSL_ALG_PARAM_CIPHER);
77 if (p->data_type != OSSL_PARAM_UTF8_STRING)
80 EVP_CIPHER_free(pc->alloc_cipher);
81 pc->cipher = pc->alloc_cipher = EVP_CIPHER_fetch(ctx, p->data, propquery);
82 OPENSSL_strlcpy(pc->name, p->data, sizeof(pc->name));
83 /* TODO legacy stuff, to be removed */
84 #ifndef FIPS_MODE /* Inside the FIPS module, we don't support legacy ciphers */
85 if (pc->cipher == NULL)
86 pc->cipher = EVP_get_cipherbyname(p->data);
88 return pc->cipher != NULL;
91 const EVP_CIPHER *ossl_prov_cipher_cipher(const PROV_CIPHER *pc)
96 ENGINE *ossl_prov_cipher_engine(const PROV_CIPHER *pc)
101 const char *ossl_prov_cipher_name(const PROV_CIPHER *pc)
106 void ossl_prov_digest_reset(PROV_DIGEST *pd)
108 EVP_MD_free(pd->alloc_md);
115 int ossl_prov_digest_copy(PROV_DIGEST *dst, const PROV_DIGEST *src)
117 if (src->alloc_md != NULL && !EVP_MD_up_ref(src->alloc_md))
119 dst->engine = src->engine;
121 dst->alloc_md = src->alloc_md;
122 OPENSSL_strlcpy(dst->name, src->name, sizeof(dst->name));
126 int ossl_prov_digest_load_from_params(PROV_DIGEST *pd,
127 const OSSL_PARAM params[],
131 const char *propquery;
133 if (!load_common(params, &propquery, &pd->engine))
137 p = OSSL_PARAM_locate_const(params, OSSL_ALG_PARAM_DIGEST);
140 if (p->data_type != OSSL_PARAM_UTF8_STRING)
143 EVP_MD_free(pd->alloc_md);
144 pd->md = pd->alloc_md = EVP_MD_fetch(ctx, p->data, propquery);
145 OPENSSL_strlcpy(pd->name, p->data, sizeof(pd->name));
146 /* TODO legacy stuff, to be removed */
147 #ifndef FIPS_MODE /* Inside the FIPS module, we don't support legacy digests */
149 pd->md = EVP_get_digestbyname(p->data);
151 return pd->md != NULL;
154 const EVP_MD *ossl_prov_digest_md(const PROV_DIGEST *pd)
159 ENGINE *ossl_prov_digest_engine(const PROV_DIGEST *pd)
164 const char *ossl_prov_digest_name(const PROV_DIGEST *pd)