EVP_R_BAD_KEY_LENGTH:195:bad key length
EVP_R_BUFFER_TOO_SMALL:155:buffer too small
EVP_R_CAMELLIA_KEY_SETUP_FAILED:157:camellia key setup failed
+EVP_R_CANNOT_GET_PARAMETERS:197:cannot get parameters
+EVP_R_CANNOT_SET_PARAMETERS:198:cannot set parameters
EVP_R_CIPHER_NOT_GCM_MODE:184:cipher not gcm mode
EVP_R_CIPHER_PARAMETER_ERROR:122:cipher parameter error
EVP_R_COMMAND_NOT_SUPPORTED:147:command not supported
params[0] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_KEYLEN, &keylen);
ok = evp_do_ciph_ctx_setparams(c->cipher, c->provctx, params);
- if (ok != -2)
+ if (ok != EVP_CTRL_RET_UNSUPPORTED)
return ok;
/* TODO(3.0) legacy code follows */
int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
{
- int ret = -2; /* Unsupported */
+ int ret = EVP_CTRL_RET_UNSUPPORTED;
int set_params = 1;
size_t sz;
OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
case EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS: /* Used by DASYNC */
case EVP_CTRL_INIT: /* TODO(3.0) Purely legacy, no provider counterpart */
default:
- return -2; /* Unsupported */
+ return EVP_CTRL_RET_UNSUPPORTED;
case EVP_CTRL_GET_IV:
set_params = 0;
params[0] = OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_IV,
}
ret = ctx->cipher->ctrl(ctx, type, arg, ptr);
- if (ret == -1) {
+ if (ret == EVP_CTRL_RET_UNSUPPORTED) {
EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL,
EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED);
return 0;
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_BUFFER_TOO_SMALL), "buffer too small"},
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_CAMELLIA_KEY_SETUP_FAILED),
"camellia key setup failed"},
+ {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_CANNOT_GET_PARAMETERS),
+ "cannot get parameters"},
+ {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_CANNOT_SET_PARAMETERS),
+ "cannot set parameters"},
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_CIPHER_NOT_GCM_MODE),
"cipher not gcm mode"},
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_CIPHER_PARAMETER_ERROR),
params[0] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_BLOCK_SIZE, &v);
ok = evp_do_ciph_getparams(cipher, params);
- return ok != 0 ? v : -1;
+ return ok != 0 ? v : EVP_CTRL_RET_UNSUPPORTED;
}
int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
params[0] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_IVLEN, &v);
ok = evp_do_ciph_getparams(cipher, params);
- return ok != 0 ? v : -1;
+ return ok != 0 ? v : EVP_CTRL_RET_UNSUPPORTED;
}
int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx)
params[0] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_NUM, &v);
ok = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->provctx, params);
- return ok != 0 ? v : -1;
+ return ok != 0 ? v : EVP_CTRL_RET_UNSUPPORTED;
}
int EVP_CIPHER_CTX_set_num(EVP_CIPHER_CTX *ctx, int num)
params[0] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_KEYLEN, &v);
ok = evp_do_ciph_getparams(cipher, params);
- return ok != 0 ? v : -1;
+ return ok != 0 ? v : EVP_CTRL_RET_UNSUPPORTED;
}
int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx)
params[0] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_KEYLEN, &v);
ok = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->provctx, params);
- return ok != 0 ? v : -1;
+ return ok != 0 ? v : EVP_CTRL_RET_UNSUPPORTED;
}
int EVP_CIPHER_nid(const EVP_CIPHER *cipher)
#include <openssl/core_numbers.h>
+#define EVP_CTRL_RET_UNSUPPORTED -1
+
+
struct evp_md_ctx_st {
const EVP_MD *reqdigest; /* The original requested digest */
const EVP_MD *digest;
#include "internal/evp_int.h" /* evp_locl.h needs it */
#include "evp_locl.h"
-int evp_do_ciph_getparams(const EVP_CIPHER *ciph, OSSL_PARAM params[])
-{
- if (ciph->prov == NULL)
- return -2;
- if (ciph->get_params == NULL)
- return -1;
- return ciph->get_params(params);
+/*
+ * 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) \
+ 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) \
+int name (const type *obj, void *provctx, OSSL_PARAM params[]) \
+{ \
+ PARAM_CHECK(obj, func, err) \
+ return obj->func(provctx, params); \
}
-int evp_do_ciph_ctx_getparams(const EVP_CIPHER *ciph, void *provctx,
- OSSL_PARAM params[])
+#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)
{
- if (ciph->prov == NULL)
- return -2;
- if (ciph->ctx_get_params == NULL)
- return -1;
- return ciph->ctx_get_params(provctx, params);
+ EVPerr(0, EVP_R_CANNOT_GET_PARAMETERS);
}
-int evp_do_ciph_ctx_setparams(const EVP_CIPHER *ciph, void *provctx,
- OSSL_PARAM params[])
+static void seterr(void)
{
- if (ciph->prov == NULL)
- return -2;
- if (ciph->ctx_set_params == NULL)
- return -1;
- return ciph->ctx_set_params(provctx, params);
+ EVPerr(0, EVP_R_CANNOT_SET_PARAMETERS);
}
+
+PARAM_FUNCTIONS(EVP_CIPHER,
+ evp_do_ciph_getparams, get_params,
+ evp_do_ciph_ctx_getparams, ctx_get_params,
+ evp_do_ciph_ctx_setparams, ctx_set_params)
+
+#if 0
+PARAM_FUNCTIONS(EVP_MD,
+ evp_do_md_getparams, get_params,
+ evp_do_md_ctx_getparams, ctx_get_params,
+ evp_do_md_ctx_setparams, ctx_set_params)
+#endif
# define EVP_F_EVP_KDF_CTRL_STR 0
# define EVP_F_EVP_KDF_CTX_NEW 0
# define EVP_F_EVP_KDF_CTX_NEW_ID 0
+# define EVP_F_EVP_KEYEXCH_FETCH 0
+# define EVP_F_EVP_KEYEXCH_FROM_DISPATCH 0
# define EVP_F_EVP_MAC_CTRL 0
# define EVP_F_EVP_MAC_CTRL_STR 0
# define EVP_F_EVP_MAC_CTX_DUP 0
# define EVP_F_EVP_PKEY_DECRYPT_OLD 0
# define EVP_F_EVP_PKEY_DERIVE 0
# define EVP_F_EVP_PKEY_DERIVE_INIT 0
+# define EVP_F_EVP_PKEY_DERIVE_INIT_EX 0
# define EVP_F_EVP_PKEY_DERIVE_SET_PEER 0
# define EVP_F_EVP_PKEY_ENCRYPT 0
# define EVP_F_EVP_PKEY_ENCRYPT_INIT 0
# define EVP_R_BAD_KEY_LENGTH 195
# define EVP_R_BUFFER_TOO_SMALL 155
# define EVP_R_CAMELLIA_KEY_SETUP_FAILED 157
+# define EVP_R_CANNOT_GET_PARAMETERS 197
+# define EVP_R_CANNOT_SET_PARAMETERS 198
# define EVP_R_CIPHER_NOT_GCM_MODE 184
# define EVP_R_CIPHER_PARAMETER_ERROR 122
# define EVP_R_COMMAND_NOT_SUPPORTED 147