Coverage Report

Created: 2025-06-13 06:58

/src/openssl30/crypto/evp/evp_utils.c
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
/* Internal EVP utility functions */
11
12
#include <openssl/core.h>
13
#include <openssl/evp.h>
14
#include <openssl/err.h>
15
#include <openssl/asn1.h>        /* evp_local.h needs it */
16
#include <openssl/safestack.h>   /* evp_local.h needs it */
17
#include "crypto/evp.h"    /* evp_local.h needs it */
18
#include "evp_local.h"
19
20
/*
21
 * EVP_CTRL_RET_UNSUPPORTED = -1 is the returned value from any ctrl function
22
 * where the control command isn't supported, and an alternative code path
23
 * may be chosen.
24
 * Since these functions are used to implement ctrl functionality, we
25
 * use the same value, and other callers will have to compensate.
26
 */
27
#define PARAM_CHECK(obj, func, errfunc)                                        \
28
2.33M
    if (obj == NULL)                                                           \
29
2.33M
        return 0;                                                              \
30
2.33M
    if (obj->prov == NULL)                                                     \
31
2.33M
        return EVP_CTRL_RET_UNSUPPORTED;                                       \
32
2.33M
    if (obj->func == NULL) {                                                   \
33
0
        errfunc();                                                             \
34
0
        return 0;                                                              \
35
0
    }
36
37
#define PARAM_FUNC(name, func, type, err)                                      \
38
4.31k
int name (const type *obj, OSSL_PARAM params[])                                \
39
4.31k
{                                                                              \
40
8.62k
    PARAM_CHECK(obj, func, err)                                                \
41
8.62k
    return obj->func(params);                                                  \
42
8.62k
}
evp_do_ciph_getparams
Line
Count
Source
38
3.22k
int name (const type *obj, OSSL_PARAM params[])                                \
39
3.22k
{                                                                              \
40
6.44k
    PARAM_CHECK(obj, func, err)                                                \
41
6.44k
    return obj->func(params);                                                  \
42
6.44k
}
evp_do_md_getparams
Line
Count
Source
38
1.09k
int name (const type *obj, OSSL_PARAM params[])                                \
39
1.09k
{                                                                              \
40
2.18k
    PARAM_CHECK(obj, func, err)                                                \
41
2.18k
    return obj->func(params);                                                  \
42
2.18k
}
43
44
#define PARAM_CTX_FUNC(name, func, type, err)                                  \
45
2.32M
int name (const type *obj, void *algctx, OSSL_PARAM params[])                  \
46
2.32M
{                                                                              \
47
4.65M
    PARAM_CHECK(obj, func, err)                                                \
48
4.65M
    return obj->func(algctx, params);                                          \
49
4.65M
}
evp_do_ciph_ctx_getparams
Line
Count
Source
45
1.60M
int name (const type *obj, void *algctx, OSSL_PARAM params[])                  \
46
1.60M
{                                                                              \
47
3.21M
    PARAM_CHECK(obj, func, err)                                                \
48
3.21M
    return obj->func(algctx, params);                                          \
49
3.21M
}
evp_do_ciph_ctx_setparams
Line
Count
Source
45
723k
int name (const type *obj, void *algctx, OSSL_PARAM params[])                  \
46
723k
{                                                                              \
47
1.44M
    PARAM_CHECK(obj, func, err)                                                \
48
1.44M
    return obj->func(algctx, params);                                          \
49
1.44M
}
Unexecuted instantiation: evp_do_md_ctx_getparams
Unexecuted instantiation: evp_do_md_ctx_setparams
50
51
#define PARAM_FUNCTIONS(type,                                                  \
52
                        getname, getfunc,                                      \
53
                        getctxname, getctxfunc,                                \
54
                        setctxname, setctxfunc)                                \
55
    PARAM_FUNC(getname, getfunc, type, geterr)                                 \
56
    PARAM_CTX_FUNC(getctxname, getctxfunc, type, geterr)                       \
57
    PARAM_CTX_FUNC(setctxname, setctxfunc, type, seterr)
58
59
/*
60
 * These error functions are a workaround for the error scripts, which
61
 * currently require that XXXerr method appears inside a function (not a macro).
62
 */
63
static void geterr(void)
64
0
{
65
0
    ERR_raise(ERR_LIB_EVP, EVP_R_CANNOT_GET_PARAMETERS);
66
0
}
67
68
static void seterr(void)
69
0
{
70
0
    ERR_raise(ERR_LIB_EVP, EVP_R_CANNOT_SET_PARAMETERS);
71
0
}
72
73
PARAM_FUNCTIONS(EVP_CIPHER,
74
                evp_do_ciph_getparams, get_params,
75
                evp_do_ciph_ctx_getparams, get_ctx_params,
76
                evp_do_ciph_ctx_setparams, set_ctx_params)
77
78
PARAM_FUNCTIONS(EVP_MD,
79
                evp_do_md_getparams, get_params,
80
                evp_do_md_ctx_getparams, get_ctx_params,
81
                evp_do_md_ctx_setparams, set_ctx_params)