/src/openssl30/providers/common/provider_seeding.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * Copyright 2020-2021 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 <openssl/core_dispatch.h> | 
| 11 |  | #include "prov/seeding.h" | 
| 12 |  |  | 
| 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; | 
| 17 |  |  | 
| 18 |  | int ossl_prov_seeding_from_dispatch(const OSSL_DISPATCH *fns) | 
| 19 | 16 | { | 
| 20 | 768 |     for (; fns->function_id != 0; fns++) { | 
| 21 |  |         /* | 
| 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. | 
| 25 |  |          */ | 
| 26 | 752 | #define set_func(c, f) \ | 
| 27 | 752 |     do { if (c == NULL) c = f; else if (c != f) return 0; } while (0) | 
| 28 | 752 |         switch (fns->function_id) { | 
| 29 | 16 |         case OSSL_FUNC_GET_ENTROPY: | 
| 30 | 16 |             set_func(c_get_entropy, OSSL_FUNC_get_entropy(fns)); | 
| 31 | 16 |             break; | 
| 32 | 16 |         case OSSL_FUNC_CLEANUP_ENTROPY: | 
| 33 | 16 |             set_func(c_cleanup_entropy, OSSL_FUNC_cleanup_entropy(fns)); | 
| 34 | 16 |             break; | 
| 35 | 16 |         case OSSL_FUNC_GET_NONCE: | 
| 36 | 16 |             set_func(c_get_nonce, OSSL_FUNC_get_nonce(fns)); | 
| 37 | 16 |             break; | 
| 38 | 16 |         case OSSL_FUNC_CLEANUP_NONCE: | 
| 39 | 16 |             set_func(c_cleanup_nonce, OSSL_FUNC_cleanup_nonce(fns)); | 
| 40 | 16 |             break; | 
| 41 | 752 |         } | 
| 42 | 752 | #undef set_func | 
| 43 | 752 |     } | 
| 44 | 16 |     return 1; | 
| 45 | 16 | } | 
| 46 |  |  | 
| 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) | 
| 49 | 0 | { | 
| 50 | 0 |     if (c_get_entropy == NULL) | 
| 51 | 0 |         return 0; | 
| 52 | 0 |     return c_get_entropy(ossl_prov_ctx_get0_handle(prov_ctx), | 
| 53 | 0 |                          pout, entropy, min_len, max_len); | 
| 54 | 0 | } | 
| 55 |  |  | 
| 56 |  | void ossl_prov_cleanup_entropy(PROV_CTX *prov_ctx, unsigned char *buf, | 
| 57 |  |                                size_t len) | 
| 58 | 0 | { | 
| 59 | 0 |     if (c_cleanup_entropy != NULL) | 
| 60 | 0 |         c_cleanup_entropy(ossl_prov_ctx_get0_handle(prov_ctx), buf, len); | 
| 61 | 0 | } | 
| 62 |  |  | 
| 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) | 
| 66 | 0 | { | 
| 67 | 0 |     if (c_get_nonce == NULL) | 
| 68 | 0 |         return 0; | 
| 69 | 0 |     return c_get_nonce(ossl_prov_ctx_get0_handle(prov_ctx), pout, | 
| 70 | 0 |                        min_len, max_len, salt, salt_len); | 
| 71 | 0 | } | 
| 72 |  |  | 
| 73 |  | void ossl_prov_cleanup_nonce(PROV_CTX *prov_ctx, unsigned char *buf, size_t len) | 
| 74 | 0 | { | 
| 75 | 0 |     if (c_cleanup_nonce != NULL) | 
| 76 | 0 |         c_cleanup_nonce(ossl_prov_ctx_get0_handle(prov_ctx), buf, len); | 
| 77 | 0 | } |