mirror of
https://github.com/openssl/openssl.git
synced 2025-02-17 14:32:04 +08:00
EVP: Add support for delayed EVP_PKEY operation parameters
They get called "delayed parameters" because they may make it to the implementation at a later time than when they're given. This currently only covers the distinguished ID, as that's the only EVP_PKEY operation parameter so far that has been possible to give before the operation has been initialized. This includes a re-implementation of EVP_PKEY_CTX_set1_id(), EVP_PKEY_CTX_get1_id(), and EVP_PKEY_CTX_get1_id_len(). Also, the more rigorous controls of keytype and optype are restored. Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/12789)
This commit is contained in:
parent
ea0add4a82
commit
86df26b394
@ -443,4 +443,86 @@ int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid)
|
||||
|
||||
return EVP_PKEY_CTX_set_group_name(ctx, OBJ_nid2sn(nid));
|
||||
}
|
||||
|
||||
int evp_pkey_ctx_set1_id_prov(EVP_PKEY_CTX *ctx, const void *id, int len)
|
||||
{
|
||||
OSSL_PARAM params[2], *p = params;
|
||||
int ret;
|
||||
|
||||
if (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
/* Uses the same return values as EVP_PKEY_CTX_ctrl */
|
||||
return -2;
|
||||
}
|
||||
|
||||
*p++ = OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_DIST_ID,
|
||||
/*
|
||||
* Cast away the const. This is
|
||||
* read only so should be safe
|
||||
*/
|
||||
(void *)id, (size_t)len);
|
||||
*p++ = OSSL_PARAM_construct_end();
|
||||
|
||||
ret = evp_pkey_ctx_set_params_strict(ctx, params);
|
||||
if (ret == -2)
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int EVP_PKEY_CTX_set1_id(EVP_PKEY_CTX *ctx, const void *id, int len)
|
||||
{
|
||||
return EVP_PKEY_CTX_ctrl(ctx, -1, -1,
|
||||
EVP_PKEY_CTRL_SET1_ID, (int)len, (void*)(id));
|
||||
}
|
||||
|
||||
static int get1_id_data(EVP_PKEY_CTX *ctx, void *id, size_t *id_len)
|
||||
{
|
||||
int ret;
|
||||
void *tmp_id = NULL;
|
||||
OSSL_PARAM params[2], *p = params;
|
||||
|
||||
if (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
/* Uses the same return values as EVP_PKEY_CTX_ctrl */
|
||||
return -2;
|
||||
}
|
||||
|
||||
*p++ = OSSL_PARAM_construct_octet_ptr(OSSL_PKEY_PARAM_DIST_ID,
|
||||
&tmp_id, 0);
|
||||
*p++ = OSSL_PARAM_construct_end();
|
||||
|
||||
ret = evp_pkey_ctx_get_params_strict(ctx, params);
|
||||
if (ret == -2) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
} else if (ret > 0) {
|
||||
size_t tmp_id_len = params[0].return_size;
|
||||
|
||||
if (id != NULL)
|
||||
memcpy(id, tmp_id, tmp_id_len);
|
||||
if (id_len != NULL)
|
||||
*id_len = tmp_id_len;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int evp_pkey_ctx_get1_id_prov(EVP_PKEY_CTX *ctx, void *id)
|
||||
{
|
||||
return get1_id_data(ctx, id, NULL);
|
||||
}
|
||||
|
||||
int evp_pkey_ctx_get1_id_len_prov(EVP_PKEY_CTX *ctx, size_t *id_len)
|
||||
{
|
||||
return get1_id_data(ctx, NULL, id_len);
|
||||
}
|
||||
|
||||
int EVP_PKEY_CTX_get1_id(EVP_PKEY_CTX *ctx, void *id)
|
||||
{
|
||||
return EVP_PKEY_CTX_ctrl(ctx, -1, -1, EVP_PKEY_CTRL_GET1_ID, 0, (void*)id);
|
||||
}
|
||||
|
||||
int EVP_PKEY_CTX_get1_id_len(EVP_PKEY_CTX *ctx, size_t *id_len)
|
||||
{
|
||||
return EVP_PKEY_CTX_ctrl(ctx, -1, -1,
|
||||
EVP_PKEY_CTRL_GET1_ID_LEN, 0, (void*)id_len);
|
||||
}
|
||||
#endif
|
||||
|
@ -204,7 +204,8 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
mdname, provkey);
|
||||
}
|
||||
|
||||
return ret ? 1 : 0;
|
||||
goto end;
|
||||
|
||||
err:
|
||||
evp_pkey_ctx_free_old_ops(locpctx);
|
||||
locpctx->operation = EVP_PKEY_OP_UNDEFINED;
|
||||
@ -279,7 +280,15 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
if (ctx->pctx->pmeth->digest_custom != NULL)
|
||||
ctx->pctx->flag_call_digest_custom = 1;
|
||||
|
||||
return 1;
|
||||
ret = 1;
|
||||
|
||||
end:
|
||||
#ifndef FIPS_MODULE
|
||||
if (ret > 0)
|
||||
ret = evp_pkey_ctx_use_cached_data(locpctx);
|
||||
#endif
|
||||
|
||||
return ret > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
int EVP_DigestSignInit_with_libctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
|
@ -33,6 +33,14 @@
|
||||
|
||||
#ifndef FIPS_MODULE
|
||||
|
||||
static int evp_pkey_ctx_store_cached_data(EVP_PKEY_CTX *ctx,
|
||||
int keytype, int optype,
|
||||
int cmd, const char *name,
|
||||
const void *data, size_t data_len);
|
||||
static void evp_pkey_ctx_free_cached_data(EVP_PKEY_CTX *ctx,
|
||||
int cmd, const char *name);
|
||||
static void evp_pkey_ctx_free_all_cached_data(EVP_PKEY_CTX *ctx);
|
||||
|
||||
typedef const EVP_PKEY_METHOD *(*pmeth_fn)(void);
|
||||
typedef int sk_cmp_fn_type(const char *const *a, const char *const *b);
|
||||
|
||||
@ -122,6 +130,29 @@ EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags)
|
||||
return pmeth;
|
||||
}
|
||||
|
||||
/* Three possible states: */
|
||||
# define EVP_PKEY_STATE_UNKNOWN 0
|
||||
# define EVP_PKEY_STATE_LEGACY 1
|
||||
# define EVP_PKEY_STATE_PROVIDER 2
|
||||
|
||||
static int evp_pkey_ctx_state(EVP_PKEY_CTX *ctx)
|
||||
{
|
||||
if (ctx->operation == EVP_PKEY_OP_UNDEFINED)
|
||||
return EVP_PKEY_STATE_UNKNOWN;
|
||||
|
||||
if ((EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
|
||||
&& ctx->op.kex.exchprovctx != NULL)
|
||||
|| (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
|
||||
&& ctx->op.sig.sigprovctx != NULL)
|
||||
|| (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
|
||||
&& ctx->op.ciph.ciphprovctx != NULL)
|
||||
|| (EVP_PKEY_CTX_IS_GEN_OP(ctx)
|
||||
&& ctx->op.keymgmt.genctx != NULL))
|
||||
return EVP_PKEY_STATE_PROVIDER;
|
||||
|
||||
return EVP_PKEY_STATE_LEGACY;
|
||||
}
|
||||
|
||||
static void help_get_legacy_alg_type_from_keymgmt(const char *keytype,
|
||||
void *arg)
|
||||
{
|
||||
@ -388,6 +419,9 @@ void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
|
||||
ctx->pmeth->cleanup(ctx);
|
||||
|
||||
evp_pkey_ctx_free_old_ops(ctx);
|
||||
#ifndef FIPS_MODULE
|
||||
evp_pkey_ctx_free_all_cached_data(ctx);
|
||||
#endif
|
||||
EVP_KEYMGMT_free(ctx->keymgmt);
|
||||
|
||||
EVP_PKEY_free(ctx->pkey);
|
||||
@ -1068,6 +1102,15 @@ int EVP_PKEY_CTX_set_mac_key(EVP_PKEY_CTX *ctx, const unsigned char *key,
|
||||
static int legacy_ctrl_to_param(EVP_PKEY_CTX *ctx, int keytype, int optype,
|
||||
int cmd, int p1, void *p2)
|
||||
{
|
||||
switch (cmd) {
|
||||
case EVP_PKEY_CTRL_SET1_ID:
|
||||
return evp_pkey_ctx_set1_id_prov(ctx, p2, p1);
|
||||
case EVP_PKEY_CTRL_GET1_ID:
|
||||
return evp_pkey_ctx_get1_id_prov(ctx, p2);
|
||||
case EVP_PKEY_CTRL_GET1_ID_LEN:
|
||||
return evp_pkey_ctx_get1_id_len_prov(ctx, p2);
|
||||
}
|
||||
|
||||
# ifndef OPENSSL_NO_DH
|
||||
if (keytype == EVP_PKEY_DHX) {
|
||||
switch (cmd) {
|
||||
@ -1281,53 +1324,77 @@ static int legacy_ctrl_to_param(EVP_PKEY_CTX *ctx, int keytype, int optype,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int evp_pkey_ctx_ctrl_int(EVP_PKEY_CTX *ctx, int keytype, int optype,
|
||||
int cmd, int p1, void *p2)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (ctx == NULL) {
|
||||
EVPerr(0, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return -2;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the method has a |digest_custom| function, we can relax the
|
||||
* operation type check, since this can be called before the operation
|
||||
* is initialized.
|
||||
*/
|
||||
if (ctx->pmeth == NULL || ctx->pmeth->digest_custom == NULL) {
|
||||
if (ctx->operation == EVP_PKEY_OP_UNDEFINED) {
|
||||
EVPerr(0, EVP_R_NO_OPERATION_SET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((optype != -1) && !(ctx->operation & optype)) {
|
||||
EVPerr(0, EVP_R_INVALID_OPERATION);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
switch (evp_pkey_ctx_state(ctx)) {
|
||||
case EVP_PKEY_STATE_PROVIDER:
|
||||
return legacy_ctrl_to_param(ctx, keytype, optype, cmd, p1, p2);
|
||||
case EVP_PKEY_STATE_UNKNOWN:
|
||||
case EVP_PKEY_STATE_LEGACY:
|
||||
if (ctx->pmeth == NULL || ctx->pmeth->ctrl == NULL) {
|
||||
EVPerr(0, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return -2;
|
||||
}
|
||||
if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype))
|
||||
return -1;
|
||||
|
||||
ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
|
||||
|
||||
if (ret == -2)
|
||||
EVPerr(0, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
|
||||
int cmd, int p1, void *p2)
|
||||
{
|
||||
int ret;
|
||||
int ret = 0;
|
||||
|
||||
if (ctx == NULL) {
|
||||
EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return -2;
|
||||
/* If unsupported, we don't want that reported here */
|
||||
ERR_set_mark();
|
||||
ret = evp_pkey_ctx_store_cached_data(ctx, keytype, optype,
|
||||
cmd, NULL, p2, p1);
|
||||
if (ret == -2) {
|
||||
ERR_pop_to_mark();
|
||||
} else {
|
||||
ERR_clear_last_mark();
|
||||
/*
|
||||
* If there was an error, there was an error.
|
||||
* If the operation isn't initialized yet, we also return, as
|
||||
* the saved values will be used then anyway.
|
||||
*/
|
||||
if (ret < 1 || ctx->operation == EVP_PKEY_OP_UNDEFINED)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((EVP_PKEY_CTX_IS_DERIVE_OP(ctx) && ctx->op.kex.exchprovctx != NULL)
|
||||
|| (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
|
||||
&& ctx->op.sig.sigprovctx != NULL)
|
||||
|| (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
|
||||
&& ctx->op.ciph.ciphprovctx != NULL)
|
||||
|| (EVP_PKEY_CTX_IS_GEN_OP(ctx)
|
||||
&& ctx->op.keymgmt.genctx != NULL))
|
||||
return legacy_ctrl_to_param(ctx, keytype, optype, cmd, p1, p2);
|
||||
|
||||
if (ctx->pmeth == NULL || ctx->pmeth->ctrl == NULL) {
|
||||
EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return -2;
|
||||
}
|
||||
if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype))
|
||||
return -1;
|
||||
|
||||
/* Skip the operation checks since this is called in a very early stage */
|
||||
if (ctx->pmeth->digest_custom != NULL)
|
||||
goto doit;
|
||||
|
||||
if (ctx->operation == EVP_PKEY_OP_UNDEFINED) {
|
||||
EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_NO_OPERATION_SET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((optype != -1) && !(ctx->operation & optype)) {
|
||||
EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_INVALID_OPERATION);
|
||||
return -1;
|
||||
}
|
||||
|
||||
doit:
|
||||
ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
|
||||
|
||||
if (ret == -2)
|
||||
EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
|
||||
return ret;
|
||||
return evp_pkey_ctx_ctrl_int(ctx, keytype, optype, cmd, p1, p2);
|
||||
}
|
||||
|
||||
int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX *ctx, int keytype, int optype,
|
||||
@ -1429,31 +1496,152 @@ static int legacy_ctrl_str_to_param(EVP_PKEY_CTX *ctx, const char *name,
|
||||
}
|
||||
}
|
||||
|
||||
static int evp_pkey_ctx_ctrl_str_int(EVP_PKEY_CTX *ctx,
|
||||
const char *name, const char *value)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (ctx == NULL) {
|
||||
EVPerr(0, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return -2;
|
||||
}
|
||||
|
||||
switch (evp_pkey_ctx_state(ctx)) {
|
||||
case EVP_PKEY_STATE_PROVIDER:
|
||||
return legacy_ctrl_str_to_param(ctx, name, value);
|
||||
case EVP_PKEY_STATE_UNKNOWN:
|
||||
case EVP_PKEY_STATE_LEGACY:
|
||||
if (ctx == NULL || ctx->pmeth == NULL || ctx->pmeth->ctrl_str == NULL) {
|
||||
EVPerr(0, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return -2;
|
||||
}
|
||||
if (strcmp(name, "digest") == 0)
|
||||
ret = EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_TYPE_SIG,
|
||||
EVP_PKEY_CTRL_MD, value);
|
||||
else
|
||||
ret = ctx->pmeth->ctrl_str(ctx, name, value);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx,
|
||||
const char *name, const char *value)
|
||||
{
|
||||
if (ctx == NULL) {
|
||||
EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return -2;
|
||||
int ret = 0;
|
||||
|
||||
/* If unsupported, we don't want that reported here */
|
||||
ERR_set_mark();
|
||||
ret = evp_pkey_ctx_store_cached_data(ctx, -1, -1, -1,
|
||||
name, value, strlen(value) + 1);
|
||||
if (ret == -2) {
|
||||
ERR_pop_to_mark();
|
||||
} else {
|
||||
ERR_clear_last_mark();
|
||||
/*
|
||||
* If there was an error, there was an error.
|
||||
* If the operation isn't initialized yet, we also return, as
|
||||
* the saved values will be used then anyway.
|
||||
*/
|
||||
if (ret < 1 || ctx->operation == EVP_PKEY_OP_UNDEFINED)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((EVP_PKEY_CTX_IS_DERIVE_OP(ctx) && ctx->op.kex.exchprovctx != NULL)
|
||||
|| (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
|
||||
&& ctx->op.sig.sigprovctx != NULL)
|
||||
|| (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
|
||||
&& ctx->op.ciph.ciphprovctx != NULL)
|
||||
|| (EVP_PKEY_CTX_IS_GEN_OP(ctx)
|
||||
&& ctx->op.keymgmt.genctx != NULL))
|
||||
return legacy_ctrl_str_to_param(ctx, name, value);
|
||||
return evp_pkey_ctx_ctrl_str_int(ctx, name, value);
|
||||
}
|
||||
|
||||
if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) {
|
||||
EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return -2;
|
||||
static int decode_cmd(int cmd, const char *name)
|
||||
{
|
||||
if (cmd == -1) {
|
||||
/*
|
||||
* The consequence of the assertion not being true is that this
|
||||
* function will return -1, which will cause the calling functions
|
||||
* to signal that the command is unsupported... in non-debug mode.
|
||||
*/
|
||||
if (ossl_assert(name != NULL))
|
||||
if (strcmp(name, "distid") == 0 || strcmp(name, "hexdistid") == 0)
|
||||
cmd = EVP_PKEY_CTRL_SET1_ID;
|
||||
}
|
||||
if (strcmp(name, "digest") == 0)
|
||||
return EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_MD,
|
||||
value);
|
||||
return ctx->pmeth->ctrl_str(ctx, name, value);
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
static int evp_pkey_ctx_store_cached_data(EVP_PKEY_CTX *ctx,
|
||||
int keytype, int optype,
|
||||
int cmd, const char *name,
|
||||
const void *data, size_t data_len)
|
||||
{
|
||||
if ((keytype != -1 && ctx->pmeth->pkey_id != keytype)
|
||||
|| ((optype != -1) && !(ctx->operation & optype))) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_OPERATION);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd = decode_cmd(cmd, name);
|
||||
switch (cmd) {
|
||||
case EVP_PKEY_CTRL_SET1_ID:
|
||||
evp_pkey_ctx_free_cached_data(ctx, cmd, name);
|
||||
if (name != NULL) {
|
||||
ctx->cached_parameters.dist_id_name = OPENSSL_strdup(name);
|
||||
if (ctx->cached_parameters.dist_id_name == NULL) {
|
||||
ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (data_len > 0) {
|
||||
ctx->cached_parameters.dist_id = OPENSSL_memdup(data, data_len);
|
||||
if (ctx->cached_parameters.dist_id == NULL) {
|
||||
ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
ctx->cached_parameters.dist_id_set = 1;
|
||||
ctx->cached_parameters.dist_id_len = data_len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return -2;
|
||||
}
|
||||
|
||||
static void evp_pkey_ctx_free_cached_data(EVP_PKEY_CTX *ctx,
|
||||
int cmd, const char *name)
|
||||
{
|
||||
cmd = decode_cmd(cmd, name);
|
||||
switch (cmd) {
|
||||
case EVP_PKEY_CTRL_SET1_ID:
|
||||
OPENSSL_free(ctx->cached_parameters.dist_id);
|
||||
OPENSSL_free(ctx->cached_parameters.dist_id_name);
|
||||
ctx->cached_parameters.dist_id = NULL;
|
||||
ctx->cached_parameters.dist_id_name = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void evp_pkey_ctx_free_all_cached_data(EVP_PKEY_CTX *ctx)
|
||||
{
|
||||
evp_pkey_ctx_free_cached_data(ctx, EVP_PKEY_CTRL_SET1_ID, NULL);
|
||||
}
|
||||
|
||||
int evp_pkey_ctx_use_cached_data(EVP_PKEY_CTX *ctx)
|
||||
{
|
||||
int ret = 1;
|
||||
|
||||
if (ret && ctx->cached_parameters.dist_id_set) {
|
||||
const char *name = ctx->cached_parameters.dist_id_name;
|
||||
const void *val = ctx->cached_parameters.dist_id;
|
||||
size_t len = ctx->cached_parameters.dist_id_len;
|
||||
|
||||
if (name != NULL)
|
||||
ret = evp_pkey_ctx_ctrl_str_int(ctx, name, val);
|
||||
else
|
||||
ret = evp_pkey_ctx_ctrl_int(ctx, -1, ctx->operation,
|
||||
EVP_PKEY_CTRL_SET1_ID,
|
||||
(int)len, (void *)val);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Utility functions to send a string of hex string to a ctrl */
|
||||
|
@ -482,7 +482,7 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, int operation)
|
||||
ctx->op.sig.sigprovctx = NULL;
|
||||
goto err;
|
||||
}
|
||||
return 1;
|
||||
goto end;
|
||||
|
||||
legacy:
|
||||
/*
|
||||
@ -523,8 +523,13 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, int operation)
|
||||
}
|
||||
if (ret <= 0)
|
||||
goto err;
|
||||
return ret;
|
||||
end:
|
||||
#ifndef FIPS_MODULE
|
||||
if (ret > 0)
|
||||
ret = evp_pkey_ctx_use_cached_data(ctx);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
err:
|
||||
evp_pkey_ctx_free_old_ops(ctx);
|
||||
ctx->operation = EVP_PKEY_OP_UNDEFINED;
|
||||
|
@ -52,6 +52,21 @@ struct evp_pkey_ctx_st {
|
||||
} ciph;
|
||||
} op;
|
||||
|
||||
/*
|
||||
* Cached parameters. Inits of operations that depend on these should
|
||||
* call evp_pkey_ctx_use_delayed_data() when the operation has been set
|
||||
* up properly.
|
||||
*/
|
||||
struct {
|
||||
/* Distinguishing Identifier, ISO/IEC 15946-3, FIPS 196 */
|
||||
char *dist_id_name; /* The name used with EVP_PKEY_CTX_ctrl_str() */
|
||||
void *dist_id; /* The distinguishing ID itself */
|
||||
size_t dist_id_len; /* The length of the distinguishing ID */
|
||||
|
||||
/* Indicators of what has been set. Keep them together! */
|
||||
unsigned int dist_id_set : 1;
|
||||
} cached_parameters;
|
||||
|
||||
/* Application specific data, usually used by the callback */
|
||||
void *app_data;
|
||||
/* Keygen callback */
|
||||
@ -769,6 +784,12 @@ EVP_MD_CTX *evp_md_ctx_new_with_libctx(EVP_PKEY *pkey,
|
||||
const ASN1_OCTET_STRING *id,
|
||||
OPENSSL_CTX *libctx, const char *propq);
|
||||
int evp_pkey_name2type(const char *name);
|
||||
|
||||
int evp_pkey_ctx_set1_id_prov(EVP_PKEY_CTX *ctx, const void *id, int len);
|
||||
int evp_pkey_ctx_get1_id_prov(EVP_PKEY_CTX *ctx, void *id);
|
||||
int evp_pkey_ctx_get1_id_len_prov(EVP_PKEY_CTX *ctx, size_t *id_len);
|
||||
|
||||
int evp_pkey_ctx_use_cached_data(EVP_PKEY_CTX *ctx);
|
||||
#endif /* !defined(FIPS_MODULE) */
|
||||
void evp_method_store_flush(OPENSSL_CTX *libctx);
|
||||
int evp_set_default_properties_int(OPENSSL_CTX *libctx, const char *propq,
|
||||
|
@ -261,6 +261,7 @@ extern "C" {
|
||||
#define OSSL_PKEY_PARAM_MGF1_PROPERTIES "mgf1-properties"
|
||||
#define OSSL_PKEY_PARAM_TLS_ENCODED_PT "tls-encoded-pt"
|
||||
#define OSSL_PKEY_PARAM_GROUP_NAME "group"
|
||||
#define OSSL_PKEY_PARAM_DIST_ID "distid"
|
||||
#define OSSL_PKEY_PARAM_PUB_KEY "pub"
|
||||
#define OSSL_PKEY_PARAM_PRIV_KEY "priv"
|
||||
|
||||
|
@ -1492,17 +1492,9 @@ int EVP_PKEY_CTX_set0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char *ukm,
|
||||
int len);
|
||||
int EVP_PKEY_CTX_get0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char **ukm);
|
||||
|
||||
/* SM2 will skip the operation check so no need to pass operation here */
|
||||
# define EVP_PKEY_CTX_set1_id(ctx, id, id_len) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
|
||||
EVP_PKEY_CTRL_SET1_ID, (int)id_len, (void*)(id))
|
||||
# define EVP_PKEY_CTX_get1_id(ctx, id) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
|
||||
EVP_PKEY_CTRL_GET1_ID, 0, (void*)(id))
|
||||
|
||||
# define EVP_PKEY_CTX_get1_id_len(ctx, id_len) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
|
||||
EVP_PKEY_CTRL_GET1_ID_LEN, 0, (void*)(id_len))
|
||||
int EVP_PKEY_CTX_set1_id(EVP_PKEY_CTX *ctx, const void *id, int len);
|
||||
int EVP_PKEY_CTX_get1_id(EVP_PKEY_CTX *ctx, void *id);
|
||||
int EVP_PKEY_CTX_get1_id_len(EVP_PKEY_CTX *ctx, size_t *id_len);
|
||||
|
||||
# define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID (EVP_PKEY_ALG_CTRL + 1)
|
||||
# define EVP_PKEY_CTRL_EC_PARAM_ENC (EVP_PKEY_ALG_CTRL + 2)
|
||||
|
@ -5296,3 +5296,6 @@ asn1_d2i_read_bio ? 3_0_0 EXIST::FUNCTION:
|
||||
EVP_PKCS82PKEY_with_libctx ? 3_0_0 EXIST::FUNCTION:
|
||||
ossl_b2i ? 3_0_0 EXIST::FUNCTION:DSA
|
||||
ossl_b2i_bio ? 3_0_0 EXIST::FUNCTION:DSA
|
||||
EVP_PKEY_CTX_set1_id ? 3_0_0 EXIST::FUNCTION:EC
|
||||
EVP_PKEY_CTX_get1_id ? 3_0_0 EXIST::FUNCTION:EC
|
||||
EVP_PKEY_CTX_get1_id_len ? 3_0_0 EXIST::FUNCTION:EC
|
||||
|
Loading…
Reference in New Issue
Block a user