2 * Copyright 2020 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_dispatch.h>
11 #include "prov/seeding.h"
13 static OSSL_FUNC_get_entropy_fn *c_get_entropy = NULL;
14 static OSSL_FUNC_cleanup_entropy_fn *c_cleanup_entropy = NULL;
15 static OSSL_FUNC_get_nonce_fn *c_get_nonce = NULL;
16 static OSSL_FUNC_cleanup_nonce_fn *c_cleanup_nonce = NULL;
18 int ossl_prov_seeding_from_dispatch(const OSSL_DISPATCH *fns)
20 for (; fns->function_id != 0; fns++) {
22 * We do not support the scenario of an application linked against
23 * multiple versions of libcrypto (e.g. one static and one dynamic), but
24 * sharing a single fips.so. We do a simple sanity check here.
26 #define set_func(c, f) \
27 do { if (c == NULL) c = f; else if (c != f) return 0; } while (0)
28 switch (fns->function_id) {
29 case OSSL_FUNC_GET_ENTROPY:
30 set_func(c_get_entropy, OSSL_FUNC_get_entropy(fns));
32 case OSSL_FUNC_CLEANUP_ENTROPY:
33 set_func(c_cleanup_entropy, OSSL_FUNC_cleanup_entropy(fns));
35 case OSSL_FUNC_GET_NONCE:
36 set_func(c_get_nonce, OSSL_FUNC_get_nonce(fns));
38 case OSSL_FUNC_CLEANUP_NONCE:
39 set_func(c_cleanup_nonce, OSSL_FUNC_cleanup_nonce(fns));
47 size_t ossl_prov_get_entropy(PROV_CTX *prov_ctx, unsigned char **pout,
48 int entropy, size_t min_len, size_t max_len)
50 if (c_get_entropy == NULL)
52 return c_get_entropy(ossl_prov_ctx_get0_handle(prov_ctx),
53 pout, entropy, min_len, max_len);
56 void ossl_prov_cleanup_entropy(PROV_CTX *prov_ctx, unsigned char *buf,
59 if (c_cleanup_entropy != NULL)
60 c_cleanup_entropy(ossl_prov_ctx_get0_handle(prov_ctx), buf, len);
63 size_t ossl_prov_get_nonce(PROV_CTX *prov_ctx, unsigned char **pout,
64 size_t min_len, size_t max_len,
65 const void *salt,size_t salt_len)
67 if (c_get_nonce == NULL)
69 return c_get_nonce(ossl_prov_ctx_get0_handle(prov_ctx), pout,
70 min_len, max_len, salt, salt_len);
73 void ossl_prov_cleanup_nonce(PROV_CTX *prov_ctx, unsigned char *buf, size_t len)
75 if (c_cleanup_nonce != NULL)
76 c_cleanup_nonce(ossl_prov_ctx_get0_handle(prov_ctx), buf, len);