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/core.h>
11 #include <openssl/core_numbers.h>
12 #include "internal/core.h"
13 #include "internal/property.h"
14 #include "internal/provider.h"
16 struct algorithm_data_st {
18 int operation_id; /* May be zero for finding them all */
19 int (*pre)(OSSL_PROVIDER *, int operation_id, void *data, int *result);
20 void (*fn)(OSSL_PROVIDER *, const OSSL_ALGORITHM *, int no_store,
22 int (*post)(OSSL_PROVIDER *, int operation_id, int no_store, void *data,
27 static int algorithm_do_this(OSSL_PROVIDER *provider, void *cbdata)
29 struct algorithm_data_st *data = cbdata;
30 int no_store = 0; /* Assume caching is ok */
31 int first_operation = 1;
32 int last_operation = OSSL_OP__HIGHEST;
36 if (data->operation_id != 0)
37 first_operation = last_operation = data->operation_id;
39 for (cur_operation = first_operation;
40 cur_operation <= last_operation;
42 const OSSL_ALGORITHM *map = NULL;
45 /* Do we fulfill pre-conditions? */
46 if (data->pre == NULL) {
47 /* If there is no pre-condition function, assume "yes" */
50 if (!data->pre(provider, cur_operation, data->data, &ret))
51 /* Error, bail out! */
55 /* If pre-condition not fulfilled, go to the next operation */
59 map = ossl_provider_query_operation(provider, cur_operation,
64 while (map->algorithm_names != NULL) {
65 const OSSL_ALGORITHM *thismap = map++;
67 data->fn(provider, thismap, no_store, data->data);
70 /* Do we fulfill post-conditions? */
71 if (data->post == NULL) {
72 /* If there is no post-condition function, assume "yes" */
75 if (!data->post(provider, cur_operation, no_store, data->data,
77 /* Error, bail out! */
81 /* If post-condition fulfilled, set general success */
89 void ossl_algorithm_do_all(OPENSSL_CTX *libctx, int operation_id,
90 OSSL_PROVIDER *provider,
91 int (*pre)(OSSL_PROVIDER *, int operation_id,
92 void *data, int *result),
93 void (*fn)(OSSL_PROVIDER *provider,
94 const OSSL_ALGORITHM *algo,
95 int no_store, void *data),
96 int (*post)(OSSL_PROVIDER *, int operation_id,
97 int no_store, void *data, int *result),
100 struct algorithm_data_st cbdata = { 0, };
102 cbdata.libctx = libctx;
103 cbdata.operation_id = operation_id;
109 if (provider == NULL)
110 ossl_provider_forall_loaded(libctx, algorithm_do_this, &cbdata);
112 algorithm_do_this(provider, &cbdata);