]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/core_fetch.c
Implement DSA in the default provider
[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
84d167f6
RL
34 if ((method = data->mcm->construct(algo->algorithm_name,
35 algo->implementation, provider,
36 data->mcm_data)) == NULL)
37 return;
38
39 /*
40 * Note regarding putting the method in stores:
41 *
42 * we don't need to care if it actually got in or not here.
43 * If it didn't get in, it will simply not be available when
44 * ossl_method_construct() tries to get it from the store.
45 *
46 * It is *expected* that the put function increments the refcnt
47 * of the passed method.
48 */
49
50 if (data->force_store || !no_store) {
a3830831 51 /*
84d167f6
RL
52 * If we haven't been told not to store,
53 * add to the global store
a3830831 54 */
c1d56231
RL
55 data->mcm->put(data->libctx, NULL, method, provider,
56 data->operation_id, algo->algorithm_name,
84d167f6 57 algo->property_definition, data->mcm_data);
9e11fe0d
RL
58 }
59
c1d56231
RL
60 data->mcm->put(data->libctx, data->store, method, provider,
61 data->operation_id, algo->algorithm_name,
62 algo->property_definition, data->mcm_data);
84d167f6
RL
63
64 /* refcnt-- because we're dropping the reference */
65 data->mcm->destruct(method, data->mcm_data);
9e11fe0d
RL
66}
67
68void *ossl_method_construct(OPENSSL_CTX *libctx, int operation_id,
69 const char *name, const char *propquery,
70 int force_store,
71 OSSL_METHOD_CONSTRUCT_METHOD *mcm, void *mcm_data)
72{
73 void *method = NULL;
74
2e49c054 75 if ((method =
2ccb1b4e
RL
76 mcm->get(libctx, NULL, operation_id, name, propquery, mcm_data))
77 == NULL) {
9e11fe0d
RL
78 struct construct_data_st cbdata;
79
80 /*
81 * We have a temporary store to be able to easily search among new
82 * items, or items that should find themselves in the global store.
83 */
1aedc35f 84 if ((cbdata.store = mcm->alloc_tmp_store(libctx)) == NULL)
9e11fe0d
RL
85 goto fin;
86
87 cbdata.libctx = libctx;
88 cbdata.operation_id = operation_id;
89 cbdata.force_store = force_store;
90 cbdata.mcm = mcm;
91 cbdata.mcm_data = mcm_data;
84d167f6
RL
92 ossl_algorithm_do_all(libctx, operation_id, NULL,
93 ossl_method_construct_this, &cbdata);
9e11fe0d 94
2ccb1b4e
RL
95 method = mcm->get(libctx, cbdata.store, operation_id, name,
96 propquery, mcm_data);
9e11fe0d
RL
97 mcm->dealloc_tmp_store(cbdata.store);
98 }
99
100 fin:
101 return method;
102}