Coverage Report

Created: 2026-03-09 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/providers/implementations/include/prov/digestcommon.h
Line
Count
Source
1
/*
2
 * Copyright 2019-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
#ifndef OSSL_PROVIDERS_DIGESTCOMMON_H
11
#define OSSL_PROVIDERS_DIGESTCOMMON_H
12
13
#include <openssl/core_dispatch.h>
14
#include <openssl/core_names.h>
15
#include <openssl/params.h>
16
#include "prov/providercommon.h"
17
18
/* Internal flags that can be queried */
19
480
#define PROV_DIGEST_FLAG_XOF 0x0001
20
496
#define PROV_DIGEST_FLAG_ALGID_ABSENT 0x0002
21
22
#ifdef __cplusplus
23
extern "C" {
24
#endif
25
26
#define PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags)               \
27
    static OSSL_FUNC_digest_get_params_fn name##_get_params;                     \
28
    static int name##_get_params(OSSL_PARAM params[])                            \
29
432
    {                                                                            \
30
432
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
432
    }
cshake_prov.c:cshake_128_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
cshake_prov.c:cshake_256_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
md5_prov.c:md5_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
md5_sha1_prov.c:md5_sha1_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
null_prov.c:nullmd_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
ripemd_prov.c:ripemd160_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha2_prov.c:sha1_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha2_prov.c:sha224_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha2_prov.c:sha256_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha2_prov.c:sha256_192_internal_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha2_prov.c:sha384_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha2_prov.c:sha512_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha2_prov.c:sha512_224_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha2_prov.c:sha512_256_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha3_prov.c:sha3_224_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha3_prov.c:sha3_256_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha3_prov.c:sha3_384_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha3_prov.c:sha3_512_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha3_prov.c:keccak_224_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha3_prov.c:keccak_256_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha3_prov.c:keccak_384_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha3_prov.c:keccak_512_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha3_prov.c:shake_128_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha3_prov.c:shake_256_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha3_prov.c:cshake_keccak_128_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sha3_prov.c:cshake_keccak_256_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
sm3_prov.c:sm3_get_params
Line
Count
Source
29
16
    {                                                                            \
30
16
        return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
16
    }
32
33
#define PROV_DISPATCH_FUNC_DIGEST_GET_PARAMS(name)                      \
34
    { OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))name##_get_params }, \
35
    {                                                                   \
36
        OSSL_FUNC_DIGEST_GETTABLE_PARAMS,                               \
37
            (void (*)(void))ossl_digest_default_gettable_params         \
38
    }
39
40
#define PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin)                               \
41
    static OSSL_FUNC_digest_final_fn name##_internal_final;                       \
42
    static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \
43
        size_t outsz)                                                             \
44
97.9k
    {                                                                             \
45
97.9k
        if (ossl_prov_is_running() && outsz >= dgstsize && fin(out, ctx)) {       \
46
97.9k
            *outl = dgstsize;                                                     \
47
97.9k
            return 1;                                                             \
48
97.9k
        }                                                                         \
49
97.9k
        return 0;                                                                 \
50
97.9k
    }
Unexecuted instantiation: md5_prov.c:md5_internal_final
Unexecuted instantiation: md5_sha1_prov.c:md5_sha1_internal_final
Unexecuted instantiation: ripemd_prov.c:ripemd160_internal_final
sha2_prov.c:sha1_internal_final
Line
Count
Source
44
15.5k
    {                                                                             \
45
15.5k
        if (ossl_prov_is_running() && outsz >= dgstsize && fin(out, ctx)) {       \
46
15.5k
            *outl = dgstsize;                                                     \
47
15.5k
            return 1;                                                             \
48
15.5k
        }                                                                         \
49
15.5k
        return 0;                                                                 \
50
15.5k
    }
Unexecuted instantiation: sha2_prov.c:sha224_internal_final
sha2_prov.c:sha256_internal_final
Line
Count
Source
44
82.4k
    {                                                                             \
45
82.4k
        if (ossl_prov_is_running() && outsz >= dgstsize && fin(out, ctx)) {       \
46
82.4k
            *outl = dgstsize;                                                     \
47
82.4k
            return 1;                                                             \
48
82.4k
        }                                                                         \
49
82.4k
        return 0;                                                                 \
50
82.4k
    }
Unexecuted instantiation: sha2_prov.c:sha256_192_internal_internal_final
Unexecuted instantiation: sha2_prov.c:sha384_internal_final
sha2_prov.c:sha512_internal_final
Line
Count
Source
44
16
    {                                                                             \
45
16
        if (ossl_prov_is_running() && outsz >= dgstsize && fin(out, ctx)) {       \
46
16
            *outl = dgstsize;                                                     \
47
16
            return 1;                                                             \
48
16
        }                                                                         \
49
16
        return 0;                                                                 \
50
16
    }
Unexecuted instantiation: sha2_prov.c:sha512_224_internal_final
Unexecuted instantiation: sha2_prov.c:sha512_256_internal_final
Unexecuted instantiation: sm3_prov.c:sm3_internal_final
51
52
#if defined(FIPS_MODULE)
53
#include "internal/fips.h"
54
#include "prov/provider_ctx.h"
55
#define DIGEST_PROV_CHECK(provctx, name)                  \
56
    if (!ossl_prov_is_running())                          \
57
        return NULL;                                      \
58
    if (!ossl_deferred_self_test(PROV_LIBCTX_OF(provctx), \
59
            ST_ID_DIGEST_##name))                         \
60
    return NULL
61
#else
62
#define DIGEST_PROV_CHECK(_provctx, _name) \
63
97.9k
    if (!ossl_prov_is_running())           \
64
97.9k
    return NULL
65
#endif /* FIPS_MODULE && DIGEST_IS_FIPS */
66
67
#define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(                               \
68
    name, CTX, blksize, dgstsize, flags, upd, fin)                               \
69
    static OSSL_FUNC_digest_newctx_fn name##_newctx;                             \
70
    static OSSL_FUNC_digest_freectx_fn name##_freectx;                           \
71
    static OSSL_FUNC_digest_dupctx_fn name##_dupctx;                             \
72
    static void *name##_newctx(void *prov_ctx)                                   \
73
97.9k
    {                                                                            \
74
97.9k
        DIGEST_PROV_CHECK(prov_ctx, name);                                       \
75
97.9k
        return OPENSSL_zalloc(sizeof(CTX));                                      \
76
97.9k
    }                                                                            \
77
    static void name##_freectx(void *vctx)                                       \
78
97.9k
    {                                                                            \
79
97.9k
        CTX *ctx = (CTX *)vctx;                                                  \
80
97.9k
        OPENSSL_clear_free(ctx, sizeof(*ctx));                                   \
81
97.9k
    }                                                                            \
Unexecuted instantiation: md5_prov.c:md5_freectx
Unexecuted instantiation: md5_sha1_prov.c:md5_sha1_freectx
Unexecuted instantiation: null_prov.c:nullmd_freectx
Unexecuted instantiation: ripemd_prov.c:ripemd160_freectx
sha2_prov.c:sha1_freectx
Line
Count
Source
78
15.5k
    {                                                                            \
79
15.5k
        CTX *ctx = (CTX *)vctx;                                                  \
80
15.5k
        OPENSSL_clear_free(ctx, sizeof(*ctx));                                   \
81
15.5k
    }                                                                            \
Unexecuted instantiation: sha2_prov.c:sha224_freectx
sha2_prov.c:sha256_freectx
Line
Count
Source
78
82.4k
    {                                                                            \
79
82.4k
        CTX *ctx = (CTX *)vctx;                                                  \
80
82.4k
        OPENSSL_clear_free(ctx, sizeof(*ctx));                                   \
81
82.4k
    }                                                                            \
Unexecuted instantiation: sha2_prov.c:sha256_192_internal_freectx
Unexecuted instantiation: sha2_prov.c:sha384_freectx
sha2_prov.c:sha512_freectx
Line
Count
Source
78
16
    {                                                                            \
79
16
        CTX *ctx = (CTX *)vctx;                                                  \
80
16
        OPENSSL_clear_free(ctx, sizeof(*ctx));                                   \
81
16
    }                                                                            \
Unexecuted instantiation: sha2_prov.c:sha512_224_freectx
Unexecuted instantiation: sha2_prov.c:sha512_256_freectx
Unexecuted instantiation: sm3_prov.c:sm3_freectx
82
    static void *name##_dupctx(void *ctx)                                        \
83
0
    {                                                                            \
84
0
        CTX *in = (CTX *)ctx;                                                    \
85
0
        CTX *ret = ossl_prov_is_running() ? OPENSSL_malloc(sizeof(*ret)) : NULL; \
86
0
        if (ret != NULL)                                                         \
87
0
            *ret = *in;                                                          \
88
0
        return ret;                                                              \
89
0
    }                                                                            \
90
    static void name##_copyctx(void *voutctx, void *vinctx)                      \
91
0
    {                                                                            \
92
0
        CTX *outctx = (CTX *)voutctx;                                            \
93
0
        CTX *inctx = (CTX *)vinctx;                                              \
94
0
        *outctx = *inctx;                                                        \
95
0
    }                                                                            \
Unexecuted instantiation: md5_prov.c:md5_copyctx
Unexecuted instantiation: md5_sha1_prov.c:md5_sha1_copyctx
Unexecuted instantiation: null_prov.c:nullmd_copyctx
Unexecuted instantiation: ripemd_prov.c:ripemd160_copyctx
Unexecuted instantiation: sha2_prov.c:sha1_copyctx
Unexecuted instantiation: sha2_prov.c:sha224_copyctx
Unexecuted instantiation: sha2_prov.c:sha256_copyctx
Unexecuted instantiation: sha2_prov.c:sha256_192_internal_copyctx
Unexecuted instantiation: sha2_prov.c:sha384_copyctx
Unexecuted instantiation: sha2_prov.c:sha512_copyctx
Unexecuted instantiation: sha2_prov.c:sha512_224_copyctx
Unexecuted instantiation: sha2_prov.c:sha512_256_copyctx
Unexecuted instantiation: sm3_prov.c:sm3_copyctx
96
    PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin)                                  \
97
    PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags)                   \
98
    const OSSL_DISPATCH ossl_##name##_functions[] = {                            \
99
        { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))name##_newctx },              \
100
        { OSSL_FUNC_DIGEST_UPDATE, (void (*)(void))upd },                        \
101
        { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))name##_internal_final },       \
102
        { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))name##_freectx },            \
103
        { OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))name##_dupctx },              \
104
        { OSSL_FUNC_DIGEST_COPYCTX, (void (*)(void))name##_copyctx },            \
105
        PROV_DISPATCH_FUNC_DIGEST_GET_PARAMS(name)
106
107
#define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END \
108
    {                                           \
109
        0, NULL                                 \
110
    }                                           \
111
    }                                           \
112
    ;
113
114
#define IMPLEMENT_digest_functions(                                                \
115
    name, CTX, blksize, dgstsize, flags, init, upd, fin)                           \
116
    static OSSL_FUNC_digest_init_fn name##_internal_init;                          \
117
    static int name##_internal_init(void *ctx,                                     \
118
        ossl_unused const OSSL_PARAM params[])                                     \
119
0
    {                                                                              \
120
0
        return ossl_prov_is_running() && init(ctx);                                \
121
0
    }                                                                              \
Unexecuted instantiation: md5_prov.c:md5_internal_init
Unexecuted instantiation: null_prov.c:nullmd_internal_init
Unexecuted instantiation: ripemd_prov.c:ripemd160_internal_init
Unexecuted instantiation: sm3_prov.c:sm3_internal_init
122
    PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \
123
        upd, fin),                                                                 \
124
        { OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init },           \
125
        PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
126
127
#define IMPLEMENT_digest_functions_with_settable_ctx(                                  \
128
    name, CTX, blksize, dgstsize, flags, init, upd, fin,                               \
129
    settable_ctx_params, set_ctx_params)                                               \
130
    static OSSL_FUNC_digest_init_fn name##_internal_init;                              \
131
    static int name##_internal_init(void *ctx, const OSSL_PARAM params[])              \
132
15.5k
    {                                                                                  \
133
15.5k
        return ossl_prov_is_running()                                                  \
134
15.5k
            && init(ctx)                                                               \
135
15.5k
            && set_ctx_params(ctx, params);                                            \
136
15.5k
    }                                                                                  \
Unexecuted instantiation: md5_sha1_prov.c:md5_sha1_internal_init
sha2_prov.c:sha1_internal_init
Line
Count
Source
132
15.5k
    {                                                                                  \
133
15.5k
        return ossl_prov_is_running()                                                  \
134
15.5k
            && init(ctx)                                                               \
135
15.5k
            && set_ctx_params(ctx, params);                                            \
136
15.5k
    }                                                                                  \
137
    PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags,     \
138
        upd, fin),                                                                     \
139
        { OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init },               \
140
        { OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, (void (*)(void))settable_ctx_params }, \
141
        { OSSL_FUNC_DIGEST_SET_CTX_PARAMS, (void (*)(void))set_ctx_params },           \
142
        PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
143
144
#define IMPLEMENT_digest_functions_with_serialize(                                 \
145
    name, CTX, blksize, dgstsize, flags, init, upd, fin,                           \
146
    serialize, deserialize)                                                        \
147
    static OSSL_FUNC_digest_init_fn name##_internal_init;                          \
148
    static int name##_internal_init(void *ctx, const OSSL_PARAM params[])          \
149
82.4k
    {                                                                              \
150
82.4k
        return ossl_prov_is_running() && init(ctx);                                \
151
82.4k
    }                                                                              \
Unexecuted instantiation: sha2_prov.c:sha224_internal_init
sha2_prov.c:sha256_internal_init
Line
Count
Source
149
82.4k
    {                                                                              \
150
82.4k
        return ossl_prov_is_running() && init(ctx);                                \
151
82.4k
    }                                                                              \
Unexecuted instantiation: sha2_prov.c:sha256_192_internal_internal_init
Unexecuted instantiation: sha2_prov.c:sha384_internal_init
sha2_prov.c:sha512_internal_init
Line
Count
Source
149
16
    {                                                                              \
150
16
        return ossl_prov_is_running() && init(ctx);                                \
151
16
    }                                                                              \
Unexecuted instantiation: sha2_prov.c:sha512_224_internal_init
Unexecuted instantiation: sha2_prov.c:sha512_256_internal_init
152
    PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \
153
        upd, fin),                                                                 \
154
        { OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init },           \
155
        { OSSL_FUNC_DIGEST_SERIALIZE, (void (*)(void))serialize },                 \
156
        { OSSL_FUNC_DIGEST_DESERIALIZE, (void (*)(void))deserialize },             \
157
        PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
158
159
const OSSL_PARAM *ossl_digest_default_gettable_params(void *provctx);
160
int ossl_digest_default_get_params(OSSL_PARAM params[], size_t blksz,
161
    size_t paramsz, unsigned long flags);
162
163
#ifdef __cplusplus
164
}
165
#endif
166
167
#endif /* OSSL_PROVIDERS_DIGESTCOMMON_H */