diff options
author | Richard Levitte <levitte@openssl.org> | 2019-07-10 23:11:27 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-07-23 06:34:09 +0200 |
commit | a883c02faa2549c98256577fd881af17b95444cf (patch) | |
tree | 1bcae7a34e61f8f10cda832bf52fa3eb3d0e1957 /crypto/core_algorithm.c | |
parent | Add OSSL_PROVIDER_name() (diff) | |
download | openssl-a883c02faa2549c98256577fd881af17b95444cf.tar.xz openssl-a883c02faa2549c98256577fd881af17b95444cf.zip |
Add internal function ossl_algorithm_do_all()
This function is used to traverse all the implementations provided by
one provider, or all implementation for a specific operation across
all loaded providers, or both, and execute a given function for each
occurence.
This will be used by ossl_method_construct(), but also by information
processing functions.
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9356)
Diffstat (limited to 'crypto/core_algorithm.c')
-rw-r--r-- | crypto/core_algorithm.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/crypto/core_algorithm.c b/crypto/core_algorithm.c new file mode 100644 index 0000000000..f88a0458ec --- /dev/null +++ b/crypto/core_algorithm.c @@ -0,0 +1,75 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include <openssl/core.h> +#include <openssl/core_numbers.h> +#include "internal/core.h" +#include "internal/property.h" +#include "internal/provider.h" + +struct algorithm_data_st { + OPENSSL_CTX *libctx; + int operation_id; /* May be zero for finding them all */ + void (*fn)(OSSL_PROVIDER *, const OSSL_ALGORITHM *, int no_store, + void *data); + void *data; +}; + +static int algorithm_do_this(OSSL_PROVIDER *provider, void *cbdata) +{ + struct algorithm_data_st *data = cbdata; + int no_store = 0; /* Assume caching is ok */ + int first_operation = 1; + int last_operation = OSSL_OP__HIGHEST; + int cur_operation; + int ok = 0; + + if (data->operation_id != 0) + first_operation = last_operation = data->operation_id; + + for (cur_operation = first_operation; + cur_operation <= last_operation; + cur_operation++) { + const OSSL_ALGORITHM *map = + ossl_provider_query_operation(provider, data->operation_id, + &no_store); + + if (map == NULL) + break; + + ok = 1; /* As long as we've found *something* */ + while (map->algorithm_name != NULL) { + const OSSL_ALGORITHM *thismap = map++; + + data->fn(provider, thismap, no_store, data->data); + } + } + + return ok; +} + +void ossl_algorithm_do_all(OPENSSL_CTX *libctx, int operation_id, + OSSL_PROVIDER *provider, + void (*fn)(OSSL_PROVIDER *provider, + const OSSL_ALGORITHM *algo, + int no_store, void *data), + void *data) +{ + struct algorithm_data_st cbdata; + + cbdata.libctx = libctx; + cbdata.operation_id = operation_id; + cbdata.fn = fn; + cbdata.data = data; + + if (provider == NULL) + ossl_provider_forall_loaded(libctx, algorithm_do_this, &cbdata); + else + algorithm_do_this(provider, &cbdata); +} |