2019-07-09 13:32:16 +08:00
|
|
|
/*
|
2021-05-14 11:08:42 +08:00
|
|
|
* Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2019-07-09 13:32:16 +08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Internal EVP utility functions */
|
|
|
|
|
|
|
|
#include <openssl/core.h>
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/err.h>
|
2019-09-28 06:45:40 +08:00
|
|
|
#include <openssl/asn1.h> /* evp_local.h needs it */
|
|
|
|
#include <openssl/safestack.h> /* evp_local.h needs it */
|
|
|
|
#include "crypto/evp.h" /* evp_local.h needs it */
|
|
|
|
#include "evp_local.h"
|
2019-07-09 13:32:16 +08:00
|
|
|
|
2019-07-31 18:34:26 +08:00
|
|
|
/*
|
|
|
|
* EVP_CTRL_RET_UNSUPPORTED = -1 is the returned value from any ctrl function
|
|
|
|
* where the control command isn't supported, and an alternative code path
|
|
|
|
* may be chosen.
|
|
|
|
* Since these functions are used to implement ctrl functionality, we
|
|
|
|
* use the same value, and other callers will have to compensate.
|
|
|
|
*/
|
|
|
|
#define PARAM_CHECK(obj, func, errfunc) \
|
2019-09-11 15:52:30 +08:00
|
|
|
if (obj == NULL) \
|
|
|
|
return 0; \
|
2019-07-31 18:34:26 +08:00
|
|
|
if (obj->prov == NULL) \
|
|
|
|
return EVP_CTRL_RET_UNSUPPORTED; \
|
|
|
|
if (obj->func == NULL) { \
|
|
|
|
errfunc(); \
|
|
|
|
return 0; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PARAM_FUNC(name, func, type, err) \
|
|
|
|
int name (const type *obj, OSSL_PARAM params[]) \
|
|
|
|
{ \
|
|
|
|
PARAM_CHECK(obj, func, err) \
|
|
|
|
return obj->func(params); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PARAM_CTX_FUNC(name, func, type, err) \
|
2021-05-14 11:08:42 +08:00
|
|
|
int name (const type *obj, void *algctx, OSSL_PARAM params[]) \
|
2019-07-31 18:34:26 +08:00
|
|
|
{ \
|
|
|
|
PARAM_CHECK(obj, func, err) \
|
2021-05-14 11:08:42 +08:00
|
|
|
return obj->func(algctx, params); \
|
2019-07-09 13:32:16 +08:00
|
|
|
}
|
|
|
|
|
2019-07-31 18:34:26 +08:00
|
|
|
#define PARAM_FUNCTIONS(type, \
|
|
|
|
getname, getfunc, \
|
|
|
|
getctxname, getctxfunc, \
|
|
|
|
setctxname, setctxfunc) \
|
|
|
|
PARAM_FUNC(getname, getfunc, type, geterr) \
|
|
|
|
PARAM_CTX_FUNC(getctxname, getctxfunc, type, geterr) \
|
|
|
|
PARAM_CTX_FUNC(setctxname, setctxfunc, type, seterr)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These error functions are a workaround for the error scripts, which
|
|
|
|
* currently require that XXXerr method appears inside a function (not a macro).
|
|
|
|
*/
|
|
|
|
static void geterr(void)
|
2019-07-09 13:32:16 +08:00
|
|
|
{
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, EVP_R_CANNOT_GET_PARAMETERS);
|
2019-07-09 13:32:16 +08:00
|
|
|
}
|
|
|
|
|
2019-07-31 18:34:26 +08:00
|
|
|
static void seterr(void)
|
2019-07-09 13:32:16 +08:00
|
|
|
{
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, EVP_R_CANNOT_SET_PARAMETERS);
|
2019-07-09 13:32:16 +08:00
|
|
|
}
|
2019-07-31 18:34:26 +08:00
|
|
|
|
|
|
|
PARAM_FUNCTIONS(EVP_CIPHER,
|
|
|
|
evp_do_ciph_getparams, get_params,
|
2019-08-16 15:04:29 +08:00
|
|
|
evp_do_ciph_ctx_getparams, get_ctx_params,
|
|
|
|
evp_do_ciph_ctx_setparams, set_ctx_params)
|
2019-07-31 18:34:26 +08:00
|
|
|
|
|
|
|
PARAM_FUNCTIONS(EVP_MD,
|
|
|
|
evp_do_md_getparams, get_params,
|
2019-08-16 15:04:29 +08:00
|
|
|
evp_do_md_ctx_getparams, get_ctx_params,
|
|
|
|
evp_do_md_ctx_setparams, set_ctx_params)
|