mirror of
https://github.com/QuasarApp/openssl.git
synced 2025-05-07 23:19:39 +00:00
libcrypto: Eliminate as much use of EVP_PKEY_size() as possible
Some uses were going against documented recommendations. Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/10798)
This commit is contained in:
parent
0a054d2a0b
commit
9767a3dca7
@ -216,7 +216,12 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
inl = buf_len;
|
inl = buf_len;
|
||||||
outll = outl = EVP_PKEY_size(pkey);
|
if (!EVP_DigestSign(ctx, NULL, &outll, buf_in, inl)) {
|
||||||
|
outl = 0;
|
||||||
|
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
outl = outll;
|
||||||
buf_out = OPENSSL_malloc(outll);
|
buf_out = OPENSSL_malloc(outll);
|
||||||
if (buf_in == NULL || buf_out == NULL) {
|
if (buf_in == NULL || buf_out == NULL) {
|
||||||
outl = 0;
|
outl = 0;
|
||||||
|
@ -589,6 +589,7 @@ static RSA_PSS_PARAMS *rsa_ctx_to_pss(EVP_PKEY_CTX *pkctx)
|
|||||||
{
|
{
|
||||||
const EVP_MD *sigmd, *mgf1md;
|
const EVP_MD *sigmd, *mgf1md;
|
||||||
EVP_PKEY *pk = EVP_PKEY_CTX_get0_pkey(pkctx);
|
EVP_PKEY *pk = EVP_PKEY_CTX_get0_pkey(pkctx);
|
||||||
|
RSA *rsa = EVP_PKEY_get0_RSA(pk);
|
||||||
int saltlen;
|
int saltlen;
|
||||||
|
|
||||||
if (EVP_PKEY_CTX_get_signature_md(pkctx, &sigmd) <= 0)
|
if (EVP_PKEY_CTX_get_signature_md(pkctx, &sigmd) <= 0)
|
||||||
@ -600,7 +601,7 @@ static RSA_PSS_PARAMS *rsa_ctx_to_pss(EVP_PKEY_CTX *pkctx)
|
|||||||
if (saltlen == -1) {
|
if (saltlen == -1) {
|
||||||
saltlen = EVP_MD_size(sigmd);
|
saltlen = EVP_MD_size(sigmd);
|
||||||
} else if (saltlen == -2 || saltlen == -3) {
|
} else if (saltlen == -2 || saltlen == -3) {
|
||||||
saltlen = EVP_PKEY_size(pk) - EVP_MD_size(sigmd) - 2;
|
saltlen = RSA_size(rsa) - EVP_MD_size(sigmd) - 2;
|
||||||
if ((EVP_PKEY_bits(pk) & 0x7) == 1)
|
if ((EVP_PKEY_bits(pk) & 0x7) == 1)
|
||||||
saltlen--;
|
saltlen--;
|
||||||
if (saltlen < 0)
|
if (saltlen < 0)
|
||||||
|
@ -104,7 +104,7 @@ static int setup_tbuf(RSA_PKEY_CTX *ctx, EVP_PKEY_CTX *pk)
|
|||||||
{
|
{
|
||||||
if (ctx->tbuf != NULL)
|
if (ctx->tbuf != NULL)
|
||||||
return 1;
|
return 1;
|
||||||
if ((ctx->tbuf = OPENSSL_malloc(EVP_PKEY_size(pk->pkey))) == NULL) {
|
if ((ctx->tbuf = OPENSSL_malloc(RSA_size(pk->pkey->pkey.rsa))) == NULL) {
|
||||||
RSAerr(RSA_F_SETUP_TBUF, ERR_R_MALLOC_FAILURE);
|
RSAerr(RSA_F_SETUP_TBUF, ERR_R_MALLOC_FAILURE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ static int pkey_rsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig,
|
|||||||
return ret;
|
return ret;
|
||||||
ret = sltmp;
|
ret = sltmp;
|
||||||
} else if (rctx->pad_mode == RSA_X931_PADDING) {
|
} else if (rctx->pad_mode == RSA_X931_PADDING) {
|
||||||
if ((size_t)EVP_PKEY_size(ctx->pkey) < tbslen + 1) {
|
if ((size_t)RSA_size(rsa) < tbslen + 1) {
|
||||||
RSAerr(RSA_F_PKEY_RSA_SIGN, RSA_R_KEY_SIZE_TOO_SMALL);
|
RSAerr(RSA_F_PKEY_RSA_SIGN, RSA_R_KEY_SIZE_TOO_SMALL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user