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++) {
21 switch (fns->function_id) {
22 case OSSL_FUNC_GET_ENTROPY:
23 if (c_get_entropy == NULL)
24 c_get_entropy = OSSL_FUNC_get_entropy(fns);
26 case OSSL_FUNC_CLEANUP_ENTROPY:
27 if (c_cleanup_entropy == NULL)
28 c_cleanup_entropy = OSSL_FUNC_cleanup_entropy(fns);
30 case OSSL_FUNC_GET_NONCE:
31 if (c_get_nonce == NULL)
32 c_get_nonce = OSSL_FUNC_get_nonce(fns);
34 case OSSL_FUNC_CLEANUP_NONCE:
35 if (c_cleanup_nonce == NULL)
36 c_cleanup_nonce = OSSL_FUNC_cleanup_nonce(fns);
43 size_t ossl_prov_get_entropy(PROV_CTX *prov_ctx, unsigned char **pout,
44 int entropy, size_t min_len, size_t max_len)
46 if (c_get_entropy == NULL)
48 return c_get_entropy(ossl_prov_ctx_get0_handle(prov_ctx),
49 pout, entropy, min_len, max_len);
52 void ossl_prov_cleanup_entropy(PROV_CTX *prov_ctx, unsigned char *buf,
55 if (c_cleanup_entropy != NULL)
56 c_cleanup_entropy(ossl_prov_ctx_get0_handle(prov_ctx), buf, len);
59 size_t ossl_prov_get_nonce(PROV_CTX *prov_ctx, unsigned char **pout,
60 size_t min_len, size_t max_len,
61 const void *salt,size_t salt_len)
63 if (c_get_nonce == NULL)
65 return c_get_nonce(ossl_prov_ctx_get0_handle(prov_ctx), pout,
66 min_len, max_len, salt, salt_len);
69 void ossl_prov_cleanup_nonce(PROV_CTX *prov_ctx, unsigned char *buf, size_t len)
71 if (c_cleanup_nonce != NULL)
72 c_cleanup_nonce(ossl_prov_ctx_get0_handle(prov_ctx), buf, len);