Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl30/providers/common/provider_seeding.c
Line
Count
Source
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
7
{
20
336
    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
329
#define set_func(c, f)   \
27
329
    do {                 \
28
28
        if (c == NULL)   \
29
28
            c = f;       \
30
28
        else if (c != f) \
31
0
            return 0;    \
32
28
    } while (0)
33
329
        switch (fns->function_id) {
34
7
        case OSSL_FUNC_GET_ENTROPY:
35
7
            set_func(c_get_entropy, OSSL_FUNC_get_entropy(fns));
36
7
            break;
37
7
        case OSSL_FUNC_CLEANUP_ENTROPY:
38
7
            set_func(c_cleanup_entropy, OSSL_FUNC_cleanup_entropy(fns));
39
7
            break;
40
7
        case OSSL_FUNC_GET_NONCE:
41
7
            set_func(c_get_nonce, OSSL_FUNC_get_nonce(fns));
42
7
            break;
43
7
        case OSSL_FUNC_CLEANUP_NONCE:
44
7
            set_func(c_cleanup_nonce, OSSL_FUNC_cleanup_nonce(fns));
45
7
            break;
46
329
        }
47
329
#undef set_func
48
329
    }
49
7
    return 1;
50
7
}
51
52
size_t ossl_prov_get_entropy(PROV_CTX *prov_ctx, unsigned char **pout,
53
    int entropy, size_t min_len, size_t max_len)
54
{
55
    if (c_get_entropy == NULL)
56
        return 0;
57
    return c_get_entropy(ossl_prov_ctx_get0_handle(prov_ctx),
58
        pout, entropy, min_len, max_len);
59
}
60
61
void ossl_prov_cleanup_entropy(PROV_CTX *prov_ctx, unsigned char *buf,
62
    size_t len)
63
{
64
    if (c_cleanup_entropy != NULL)
65
        c_cleanup_entropy(ossl_prov_ctx_get0_handle(prov_ctx), buf, len);
66
}
67
68
size_t ossl_prov_get_nonce(PROV_CTX *prov_ctx, unsigned char **pout,
69
    size_t min_len, size_t max_len,
70
    const void *salt, size_t salt_len)
71
{
72
    if (c_get_nonce == NULL)
73
        return 0;
74
    return c_get_nonce(ossl_prov_ctx_get0_handle(prov_ctx), pout,
75
        min_len, max_len, salt, salt_len);
76
}
77
78
void ossl_prov_cleanup_nonce(PROV_CTX *prov_ctx, unsigned char *buf, size_t len)
79
{
80
    if (c_cleanup_nonce != NULL)
81
        c_cleanup_nonce(ossl_prov_ctx_get0_handle(prov_ctx), buf, len);
82
}