Coverage Report

Created: 2023-09-25 06:41

/src/openssl/providers/implementations/include/prov/digestcommon.h
Line
Count
Source (jump to first uncovered line)
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
0
#define PROV_DIGEST_FLAG_XOF             0x0001
20
0
#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
0
static int name##_get_params(OSSL_PARAM params[])                              \
29
0
{                                                                              \
30
0
    return ossl_digest_default_get_params(params, blksize, dgstsize, flags);   \
31
0
}
Unexecuted instantiation: blake2_prov.c:blake2s256_get_params
Unexecuted instantiation: md5_prov.c:md5_get_params
Unexecuted instantiation: md5_sha1_prov.c:md5_sha1_get_params
Unexecuted instantiation: null_prov.c:nullmd_get_params
Unexecuted instantiation: ripemd_prov.c:ripemd160_get_params
Unexecuted instantiation: sha2_prov.c:sha1_get_params
Unexecuted instantiation: sha2_prov.c:sha224_get_params
Unexecuted instantiation: sha2_prov.c:sha256_get_params
Unexecuted instantiation: sha2_prov.c:sha256_192_get_params
Unexecuted instantiation: sha2_prov.c:sha384_get_params
Unexecuted instantiation: sha2_prov.c:sha512_get_params
Unexecuted instantiation: sha2_prov.c:sha512_224_get_params
Unexecuted instantiation: sha2_prov.c:sha512_256_get_params
Unexecuted instantiation: sha3_prov.c:sha3_224_get_params
Unexecuted instantiation: sha3_prov.c:sha3_256_get_params
Unexecuted instantiation: sha3_prov.c:sha3_384_get_params
Unexecuted instantiation: sha3_prov.c:sha3_512_get_params
Unexecuted instantiation: sha3_prov.c:keccak_224_get_params
Unexecuted instantiation: sha3_prov.c:keccak_256_get_params
Unexecuted instantiation: sha3_prov.c:keccak_384_get_params
Unexecuted instantiation: sha3_prov.c:keccak_512_get_params
Unexecuted instantiation: sha3_prov.c:shake_128_get_params
Unexecuted instantiation: sha3_prov.c:shake_256_get_params
Unexecuted instantiation: sha3_prov.c:keccak_kmac_128_get_params
Unexecuted instantiation: sha3_prov.c:keccak_kmac_256_get_params
Unexecuted instantiation: sm3_prov.c:sm3_get_params
32
33
#define PROV_DISPATCH_FUNC_DIGEST_GET_PARAMS(name)                             \
34
{ OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))name##_get_params },            \
35
{ OSSL_FUNC_DIGEST_GETTABLE_PARAMS,                                            \
36
  (void (*)(void))ossl_digest_default_gettable_params }
37
38
# define PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin)                           \
39
static OSSL_FUNC_digest_final_fn name##_internal_final;                        \
40
static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl,  \
41
0
                                 size_t outsz)                                 \
42
0
{                                                                              \
43
0
    if (ossl_prov_is_running() && outsz >= dgstsize && fin(out, ctx)) {        \
44
0
        *outl = dgstsize;                                                      \
45
0
        return 1;                                                              \
46
0
    }                                                                          \
47
0
    return 0;                                                                  \
48
0
}
Unexecuted instantiation: blake2_prov.c:blake2s256_internal_final
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
Unexecuted instantiation: sha2_prov.c:sha1_internal_final
Unexecuted instantiation: sha2_prov.c:sha224_internal_final
Unexecuted instantiation: sha2_prov.c:sha256_internal_final
Unexecuted instantiation: sha2_prov.c:sha256_192_internal_final
Unexecuted instantiation: sha2_prov.c:sha384_internal_final
Unexecuted instantiation: sha2_prov.c:sha512_internal_final
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
49
50
# define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(                            \
51
    name, CTX, blksize, dgstsize, flags, upd, fin)                             \
52
static OSSL_FUNC_digest_newctx_fn name##_newctx;                               \
53
static OSSL_FUNC_digest_freectx_fn name##_freectx;                             \
54
static OSSL_FUNC_digest_dupctx_fn name##_dupctx;                               \
55
0
static void *name##_newctx(void *prov_ctx)                                     \
56
0
{                                                                              \
57
0
    CTX *ctx = ossl_prov_is_running() ? OPENSSL_zalloc(sizeof(*ctx)) : NULL;   \
58
0
    return ctx;                                                                \
59
0
}                                                                              \
Unexecuted instantiation: blake2_prov.c:blake2s256_newctx
Unexecuted instantiation: md5_prov.c:md5_newctx
Unexecuted instantiation: md5_sha1_prov.c:md5_sha1_newctx
Unexecuted instantiation: null_prov.c:nullmd_newctx
Unexecuted instantiation: ripemd_prov.c:ripemd160_newctx
Unexecuted instantiation: sha2_prov.c:sha1_newctx
Unexecuted instantiation: sha2_prov.c:sha224_newctx
Unexecuted instantiation: sha2_prov.c:sha256_newctx
Unexecuted instantiation: sha2_prov.c:sha256_192_newctx
Unexecuted instantiation: sha2_prov.c:sha384_newctx
Unexecuted instantiation: sha2_prov.c:sha512_newctx
Unexecuted instantiation: sha2_prov.c:sha512_224_newctx
Unexecuted instantiation: sha2_prov.c:sha512_256_newctx
Unexecuted instantiation: sm3_prov.c:sm3_newctx
60
0
static void name##_freectx(void *vctx)                                         \
61
0
{                                                                              \
62
0
    CTX *ctx = (CTX *)vctx;                                                    \
63
0
    OPENSSL_clear_free(ctx,  sizeof(*ctx));                                    \
64
0
}                                                                              \
Unexecuted instantiation: blake2_prov.c:blake2s256_freectx
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
Unexecuted instantiation: sha2_prov.c:sha1_freectx
Unexecuted instantiation: sha2_prov.c:sha224_freectx
Unexecuted instantiation: sha2_prov.c:sha256_freectx
Unexecuted instantiation: sha2_prov.c:sha256_192_freectx
Unexecuted instantiation: sha2_prov.c:sha384_freectx
Unexecuted instantiation: sha2_prov.c:sha512_freectx
Unexecuted instantiation: sha2_prov.c:sha512_224_freectx
Unexecuted instantiation: sha2_prov.c:sha512_256_freectx
Unexecuted instantiation: sm3_prov.c:sm3_freectx
65
0
static void *name##_dupctx(void *ctx)                                          \
66
0
{                                                                              \
67
0
    CTX *in = (CTX *)ctx;                                                      \
68
0
    CTX *ret = ossl_prov_is_running() ? OPENSSL_malloc(sizeof(*ret)) : NULL;   \
69
0
    if (ret != NULL)                                                           \
70
0
        *ret = *in;                                                            \
71
0
    return ret;                                                                \
72
0
}                                                                              \
Unexecuted instantiation: blake2_prov.c:blake2s256_dupctx
Unexecuted instantiation: md5_prov.c:md5_dupctx
Unexecuted instantiation: md5_sha1_prov.c:md5_sha1_dupctx
Unexecuted instantiation: null_prov.c:nullmd_dupctx
Unexecuted instantiation: ripemd_prov.c:ripemd160_dupctx
Unexecuted instantiation: sha2_prov.c:sha1_dupctx
Unexecuted instantiation: sha2_prov.c:sha224_dupctx
Unexecuted instantiation: sha2_prov.c:sha256_dupctx
Unexecuted instantiation: sha2_prov.c:sha256_192_dupctx
Unexecuted instantiation: sha2_prov.c:sha384_dupctx
Unexecuted instantiation: sha2_prov.c:sha512_dupctx
Unexecuted instantiation: sha2_prov.c:sha512_224_dupctx
Unexecuted instantiation: sha2_prov.c:sha512_256_dupctx
Unexecuted instantiation: sm3_prov.c:sm3_dupctx
73
PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin)                                    \
74
PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags)                     \
75
const OSSL_DISPATCH ossl_##name##_functions[] = {                              \
76
    { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))name##_newctx },                \
77
    { OSSL_FUNC_DIGEST_UPDATE, (void (*)(void))upd },                          \
78
    { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))name##_internal_final },         \
79
    { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))name##_freectx },              \
80
    { OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))name##_dupctx },                \
81
    PROV_DISPATCH_FUNC_DIGEST_GET_PARAMS(name)
82
83
# define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END                               \
84
    { 0, NULL }                                                                \
85
};
86
87
# define IMPLEMENT_digest_functions(                                           \
88
    name, CTX, blksize, dgstsize, flags, init, upd, fin)                       \
89
static OSSL_FUNC_digest_init_fn name##_internal_init;                          \
90
static int name##_internal_init(void *ctx,                                     \
91
0
                                ossl_unused const OSSL_PARAM params[])         \
92
0
{                                                                              \
93
0
    return ossl_prov_is_running() && init(ctx);                                \
94
0
}                                                                              \
Unexecuted instantiation: blake2_prov.c:blake2s256_internal_init
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: sha2_prov.c:sha224_internal_init
Unexecuted instantiation: sha2_prov.c:sha256_internal_init
Unexecuted instantiation: sha2_prov.c:sha256_192_internal_init
Unexecuted instantiation: sha2_prov.c:sha384_internal_init
Unexecuted instantiation: sha2_prov.c:sha512_internal_init
Unexecuted instantiation: sha2_prov.c:sha512_224_internal_init
Unexecuted instantiation: sha2_prov.c:sha512_256_internal_init
Unexecuted instantiation: sm3_prov.c:sm3_internal_init
95
PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \
96
                                          upd, fin),                           \
97
    { OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init },           \
98
PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
99
100
# define IMPLEMENT_digest_functions_with_settable_ctx(                         \
101
    name, CTX, blksize, dgstsize, flags, init, upd, fin,                       \
102
    settable_ctx_params, set_ctx_params)                                       \
103
static OSSL_FUNC_digest_init_fn name##_internal_init;                          \
104
0
static int name##_internal_init(void *ctx, const OSSL_PARAM params[])          \
105
0
{                                                                              \
106
0
    return ossl_prov_is_running()                                              \
107
0
           && init(ctx)                                                        \
108
0
           && set_ctx_params(ctx, params);                                     \
109
0
}                                                                              \
Unexecuted instantiation: md5_sha1_prov.c:md5_sha1_internal_init
Unexecuted instantiation: sha2_prov.c:sha1_internal_init
110
PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \
111
                                          upd, fin),                           \
112
    { OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init },           \
113
    { OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, (void (*)(void))settable_ctx_params }, \
114
    { OSSL_FUNC_DIGEST_SET_CTX_PARAMS, (void (*)(void))set_ctx_params },       \
115
PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
116
117
118
const OSSL_PARAM *ossl_digest_default_gettable_params(void *provctx);
119
int ossl_digest_default_get_params(OSSL_PARAM params[], size_t blksz,
120
                                   size_t paramsz, unsigned long flags);
121
122
# ifdef __cplusplus
123
}
124
# endif
125
126
#endif /* OSSL_PROVIDERS_DIGESTCOMMON_H */