]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/core_fetch.c
CORE & EVP: Specify OP_query_operation_name() for KEYMGMT
[thirdparty/openssl.git] / crypto / core_fetch.c
CommitLineData
9e11fe0d
RL
1/*
2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
10#include <stddef.h>
11
12#include <openssl/core.h>
13#include "internal/cryptlib.h"
14#include "internal/core.h"
15#include "internal/property.h"
16#include "internal/provider.h"
17
18struct construct_data_st {
19 OPENSSL_CTX *libctx;
20 OSSL_METHOD_STORE *store;
21 int operation_id;
22 int force_store;
23 OSSL_METHOD_CONSTRUCT_METHOD *mcm;
24 void *mcm_data;
25};
26
84d167f6
RL
27static void ossl_method_construct_this(OSSL_PROVIDER *provider,
28 const OSSL_ALGORITHM *algo,
29 int no_store, void *cbdata)
9e11fe0d
RL
30{
31 struct construct_data_st *data = cbdata;
84d167f6 32 void *method = NULL;
9e11fe0d 33
36fa4d8a
RL
34 if ((method = data->mcm->construct(algo, provider, data->mcm_data))
35 == NULL)
84d167f6
RL
36 return;
37
38 /*
39 * Note regarding putting the method in stores:
40 *
41 * we don't need to care if it actually got in or not here.
42 * If it didn't get in, it will simply not be available when
43 * ossl_method_construct() tries to get it from the store.
44 *
45 * It is *expected* that the put function increments the refcnt
46 * of the passed method.
47 */
48
49 if (data->force_store || !no_store) {
a3830831 50 /*
84d167f6
RL
51 * If we haven't been told not to store,
52 * add to the global store
a3830831 53 */
c1d56231 54 data->mcm->put(data->libctx, NULL, method, provider,
695d195b 55 data->operation_id, algo->algorithm_names,
84d167f6 56 algo->property_definition, data->mcm_data);
9e11fe0d
RL
57 }
58
c1d56231 59 data->mcm->put(data->libctx, data->store, method, provider,
695d195b 60 data->operation_id, algo->algorithm_names,
c1d56231 61 algo->property_definition, data->mcm_data);
84d167f6
RL
62
63 /* refcnt-- because we're dropping the reference */
64 data->mcm->destruct(method, data->mcm_data);
9e11fe0d
RL
65}
66
67void *ossl_method_construct(OPENSSL_CTX *libctx, int operation_id,
9e11fe0d
RL
68 int force_store,
69 OSSL_METHOD_CONSTRUCT_METHOD *mcm, void *mcm_data)
70{
71 void *method = NULL;
72
f7c16d48 73 if ((method = mcm->get(libctx, NULL, mcm_data)) == NULL) {
9e11fe0d
RL
74 struct construct_data_st cbdata;
75
76 /*
77 * We have a temporary store to be able to easily search among new
78 * items, or items that should find themselves in the global store.
79 */
1aedc35f 80 if ((cbdata.store = mcm->alloc_tmp_store(libctx)) == NULL)
9e11fe0d
RL
81 goto fin;
82
83 cbdata.libctx = libctx;
84 cbdata.operation_id = operation_id;
85 cbdata.force_store = force_store;
86 cbdata.mcm = mcm;
87 cbdata.mcm_data = mcm_data;
84d167f6
RL
88 ossl_algorithm_do_all(libctx, operation_id, NULL,
89 ossl_method_construct_this, &cbdata);
9e11fe0d 90
f7c16d48 91 method = mcm->get(libctx, cbdata.store, mcm_data);
9e11fe0d
RL
92 mcm->dealloc_tmp_store(cbdata.store);
93 }
94
95 fin:
96 return method;
97}