Digest string helper function.
New function EVP_PKEY_CTX_md() which takes a string and passes a digest to a ctrl. Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/2177)
This commit is contained in:
parent
e5e04ee398
commit
410877bad2
4 changed files with 26 additions and 17 deletions
|
@ -50,6 +50,7 @@ static ERR_STRING_DATA EVP_str_functs[] = {
|
|||
{ERR_FUNC(EVP_F_EVP_PKEY_CTX_CTRL), "EVP_PKEY_CTX_ctrl"},
|
||||
{ERR_FUNC(EVP_F_EVP_PKEY_CTX_CTRL_STR), "EVP_PKEY_CTX_ctrl_str"},
|
||||
{ERR_FUNC(EVP_F_EVP_PKEY_CTX_DUP), "EVP_PKEY_CTX_dup"},
|
||||
{ERR_FUNC(EVP_F_EVP_PKEY_CTX_MD), "EVP_PKEY_CTX_md"},
|
||||
{ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT), "EVP_PKEY_decrypt"},
|
||||
{ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT_INIT), "EVP_PKEY_decrypt_init"},
|
||||
{ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT_OLD), "EVP_PKEY_decrypt_old"},
|
||||
|
|
|
@ -330,14 +330,9 @@ int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx,
|
|||
EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return -2;
|
||||
}
|
||||
if (strcmp(name, "digest") == 0) {
|
||||
const EVP_MD *md;
|
||||
if (value == NULL || (md = EVP_get_digestbyname(value)) == NULL) {
|
||||
EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_INVALID_DIGEST);
|
||||
return 0;
|
||||
}
|
||||
return EVP_PKEY_CTX_set_signature_md(ctx, md);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -367,6 +362,16 @@ int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex)
|
|||
OPENSSL_free(bin);
|
||||
return rv;
|
||||
}
|
||||
/* Pass a message digest to a ctrl */
|
||||
int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md)
|
||||
{
|
||||
const EVP_MD *m;
|
||||
if (md == NULL || (m = EVP_get_digestbyname(md)) == NULL) {
|
||||
EVPerr(EVP_F_EVP_PKEY_CTX_MD, EVP_R_INVALID_DIGEST);
|
||||
return 0;
|
||||
}
|
||||
return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, 0, (void *)m);
|
||||
}
|
||||
|
||||
int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx)
|
||||
{
|
||||
|
|
|
@ -572,14 +572,10 @@ static int pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx,
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (strcmp(type, "rsa_mgf1_md") == 0) {
|
||||
const EVP_MD *md;
|
||||
if ((md = EVP_get_digestbyname(value)) == NULL) {
|
||||
RSAerr(RSA_F_PKEY_RSA_CTRL_STR, RSA_R_INVALID_DIGEST);
|
||||
return 0;
|
||||
}
|
||||
return EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, md);
|
||||
}
|
||||
if (strcmp(type, "rsa_mgf1_md") == 0)
|
||||
return EVP_PKEY_CTX_md(ctx,
|
||||
EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT,
|
||||
EVP_PKEY_CTRL_RSA_MGF1_MD, value);
|
||||
|
||||
if (strcmp(type, "rsa_oaep_md") == 0) {
|
||||
const EVP_MD *md;
|
||||
|
@ -587,8 +583,12 @@ static int pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx,
|
|||
RSAerr(RSA_F_PKEY_RSA_CTRL_STR, RSA_R_INVALID_DIGEST);
|
||||
return 0;
|
||||
}
|
||||
return EVP_PKEY_CTX_set_rsa_oaep_md(ctx, md);
|
||||
}
|
||||
|
||||
if (strcmp(type, "rsa_oaep_md") == 0)
|
||||
return EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_TYPE_CRYPT,
|
||||
EVP_PKEY_CTRL_RSA_OAEP_MD, value);
|
||||
|
||||
if (strcmp(type, "rsa_oaep_label") == 0) {
|
||||
unsigned char *lab;
|
||||
long lablen;
|
||||
|
|
|
@ -1205,6 +1205,8 @@ int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
|
|||
int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str);
|
||||
int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex);
|
||||
|
||||
int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md);
|
||||
|
||||
int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx);
|
||||
void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen);
|
||||
|
||||
|
@ -1484,6 +1486,7 @@ int ERR_load_EVP_strings(void);
|
|||
# define EVP_F_EVP_PKEY_CTX_CTRL 137
|
||||
# define EVP_F_EVP_PKEY_CTX_CTRL_STR 150
|
||||
# define EVP_F_EVP_PKEY_CTX_DUP 156
|
||||
# define EVP_F_EVP_PKEY_CTX_MD 168
|
||||
# define EVP_F_EVP_PKEY_DECRYPT 104
|
||||
# define EVP_F_EVP_PKEY_DECRYPT_INIT 138
|
||||
# define EVP_F_EVP_PKEY_DECRYPT_OLD 151
|
||||
|
|
Loading…
Reference in a new issue