]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/evp/evp_utils.c
Rename the field 'provctx and data' to 'algctx' inside some objects containing
[thirdparty/openssl.git] / crypto / evp / evp_utils.c
CommitLineData
13273237 1/*
7c14d0c1 2 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
13273237
RL
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>
706457b7
DMSP
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"
13273237 19
e870791a
SL
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) \
dc64dc2e
SL
28 if (obj == NULL) \
29 return 0; \
e870791a
SL
30 if (obj->prov == NULL) \
31 return EVP_CTRL_RET_UNSUPPORTED; \
32 if (obj->func == NULL) { \
33 errfunc(); \
34 return 0; \
35 }
36
37#define PARAM_FUNC(name, func, type, err) \
38int name (const type *obj, OSSL_PARAM params[]) \
39{ \
40 PARAM_CHECK(obj, func, err) \
41 return obj->func(params); \
42}
43
44#define PARAM_CTX_FUNC(name, func, type, err) \
7c14d0c1 45int name (const type *obj, void *algctx, OSSL_PARAM params[]) \
e870791a
SL
46{ \
47 PARAM_CHECK(obj, func, err) \
7c14d0c1 48 return obj->func(algctx, params); \
13273237
RL
49}
50
e870791a
SL
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 */
63static void geterr(void)
13273237 64{
9311d0c4 65 ERR_raise(ERR_LIB_EVP, EVP_R_CANNOT_GET_PARAMETERS);
13273237
RL
66}
67
e870791a 68static void seterr(void)
13273237 69{
9311d0c4 70 ERR_raise(ERR_LIB_EVP, EVP_R_CANNOT_SET_PARAMETERS);
13273237 71}
e870791a
SL
72
73PARAM_FUNCTIONS(EVP_CIPHER,
74 evp_do_ciph_getparams, get_params,
92d9d0ae
RL
75 evp_do_ciph_ctx_getparams, get_ctx_params,
76 evp_do_ciph_ctx_setparams, set_ctx_params)
e870791a 77
e870791a
SL
78PARAM_FUNCTIONS(EVP_MD,
79 evp_do_md_getparams, get_params,
92d9d0ae
RL
80 evp_do_md_ctx_getparams, get_ctx_params,
81 evp_do_md_ctx_setparams, set_ctx_params)