For SHAKE algorithms we now return 0 from EVP_MD_size().
So all the places that check for < 0 needed to change to <= 0
(Otherwise the behaviour will be to digest nothing in most cases).
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25285)
EVP_MD_CTX *md_ctx = NULL;
md_value_len = EVP_MD_get_size(md);
- if (md_value_len < 0)
+ if (md_value_len <= 0)
return 0;
if (input != NULL) {
md_size = EVP_MD_get_size(digest);
md_data = EVP_MD_CTX_get0_md_data(md);
+ if (md_size <= 0)
+ goto berr;
if (ctx->buf_len + 2 * md_size > OK_BLOCK_SIZE)
return 1;
if ((md = ctx->md) == NULL)
goto berr;
digest = EVP_MD_CTX_get0_md(md);
- if ((md_size = EVP_MD_get_size(digest)) < 0)
+ if ((md_size = EVP_MD_get_size(digest)) <= 0)
goto berr;
md_data = EVP_MD_CTX_get0_md_data(md);
md = ctx->md;
digest = EVP_MD_CTX_get0_md(md);
md_size = EVP_MD_get_size(digest);
+ if (md_size <= 0)
+ goto berr;
tl = ctx->buf_len - OK_BLOCK_BLOCK;
ctx->buf[0] = (unsigned char)(tl >> 24);
ctx = BIO_get_data(b);
md = ctx->md;
md_size = EVP_MD_get_size(EVP_MD_CTX_get0_md(md));
- if (md_size < 0)
+ if (md_size <= 0)
goto berr;
assert(sizeof(tl) >= OK_BLOCK_BLOCK); /* always true */
} else {
int s = EVP_MD_get_size(ctx->digest);
- if (s < 0 || EVP_PKEY_sign(pctx, sigret, siglen, NULL, s) <= 0)
+ if (s <= 0 || EVP_PKEY_sign(pctx, sigret, siglen, NULL, s) <= 0)
return 0;
}
}
passlen = strlen(pass);
mdsize = EVP_MD_get_size(md);
- if (mdsize < 0)
+ if (mdsize <= 0)
goto err;
kdf = EVP_KDF_fetch(libctx, OSSL_KDF_NAME_PBKDF1, propq);
unsigned char *pmd;
OSSL_LIB_CTX *libctx = ossl_bn_get_libctx(ctx);
+ if (mdsize <= 0)
+ goto err;
+
/* find q */
for (;;) {
if (!BN_GENCB_call(cb, 0, m++))
* The HMAC construction is not allowed to be used with the
* extendable-output functions (XOF) shake128 and shake256.
*/
- if ((EVP_MD_get_flags(md) & EVP_MD_FLAG_XOF) != 0)
+ if (EVP_MD_xof(md))
return 0;
#ifdef OPENSSL_HMAC_S390X
size_t temp_md_len = 0;
unsigned char *ret = NULL;
- if (size >= 0) {
+ if (size > 0) {
ret = EVP_Q_mac(NULL, "HMAC", NULL, EVP_MD_get0_name(evp_md), NULL,
key, key_len, data, data_len,
md == NULL ? static_md : md, size, &temp_md_len);
(void)ERR_pop_to_mark();
mdlen = EVP_MD_get_size(dgst);
- if (mdlen < 0) {
+ if (mdlen <= 0) {
ERR_raise(ERR_LIB_OCSP, OCSP_R_DIGEST_SIZE_ERR);
goto end;
}
keylen = EVP_MD_get_size(md);
md_nid = EVP_MD_get_type(md);
- if (keylen < 0)
+ if (keylen <= 0)
goto err;
/* For PBMAC1 we use a special keygen callback if not provided (e.g. on verification) */
mgf1Hash = Hash;
hLen = EVP_MD_get_size(Hash);
- if (hLen < 0)
+ if (hLen <= 0)
goto err;
/*-
* Negative sLen has special meanings:
mgf1Hash = Hash;
hLen = EVP_MD_get_size(Hash);
- if (hLen < 0)
+ if (hLen <= 0)
goto err;
/*-
* Negative sLen has special meanings:
const int md_size = EVP_MD_get_size(digest);
size_t sz;
- if (field_size == 0 || md_size < 0)
+ if (field_size == 0 || md_size <= 0)
return 0;
/* Integer and string are simple type; set constructed = 0, means primitive and definite length encoding. */
OSSL_LIB_CTX *libctx = ossl_ec_key_get_libctx(key);
const char *propq = ossl_ec_key_get0_propq(key);
- if (md_size < 0) {
+ if (md_size <= 0) {
ERR_raise(ERR_LIB_SM2, SM2_R_INVALID_DIGEST);
goto done;
}
(void)ERR_pop_to_mark();
length = EVP_MD_get_size(md);
- if (length < 0)
+ if (length <= 0)
goto err;
*imprint_len = length;
if ((*imprint = OPENSSL_malloc(*imprint_len)) == NULL)
return 0;
}
sz = EVP_MD_get_size(md);
- if (sz < 0)
+ if (sz <= 0)
return 0;
return sz;
return 0;
md = ossl_prov_digest_md(&ctx->digest);
- if ((EVP_MD_get_flags(md) & EVP_MD_FLAG_XOF) != 0) {
+ if (EVP_MD_xof(md)) {
ERR_raise(ERR_LIB_PROV, PROV_R_XOF_DIGESTS_NOT_ALLOWED);
return 0;
}
size_t prk_len;
sz = EVP_MD_get_size(evp_md);
- if (sz < 0)
+ if (sz <= 0)
return 0;
prk_len = (size_t)sz;
{
int sz = EVP_MD_get_size(evp_md);
- if (sz < 0)
+ if (sz <= 0)
return 0;
if (prk_len != (size_t)sz) {
ERR_raise(ERR_LIB_PROV, PROV_R_WRONG_OUTPUT_BUFFER_SIZE);
|| !EVP_DigestFinal_ex(ctx, md_tmp, NULL))
goto err;
mdsize = EVP_MD_size(md_type);
- if (mdsize < 0)
+ if (mdsize <= 0)
goto err;
if (n > (size_t)mdsize) {
ERR_raise(ERR_LIB_PROV, PROV_R_LENGTH_TOO_LARGE);
if (tmpmd != NULL) {
imac_size = EVP_MD_get_size(tmpmd);
- if (!ossl_assert(imac_size >= 0 && imac_size <= EVP_MAX_MD_SIZE)) {
+ if (!ossl_assert(imac_size > 0 && imac_size <= EVP_MAX_MD_SIZE)) {
RLAYERfatal(rl, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB);
return 0;
}
if ((EVP_CIPHER_get_flags(ciph) & EVP_CIPH_FLAG_AEAD_CIPHER) == 0
&& !rl->use_etm)
imacsize = EVP_MD_get_size(md);
- if (imacsize >= 0)
+ if (imacsize > 0)
macsize = (size_t)imacsize;
*pprm++ = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_TLS_VERSION,
if (tmpmd != NULL) {
imac_size = EVP_MD_get_size(tmpmd);
- if (!ossl_assert(imac_size >= 0 && imac_size <= EVP_MAX_MD_SIZE)) {
+ if (!ossl_assert(imac_size > 0 && imac_size <= EVP_MAX_MD_SIZE)) {
RLAYERfatal(rl, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB);
return OSSL_RECORD_RETURN_FATAL;
}
p = s->s3.tmp.key_block;
mdi = EVP_MD_get_size(md);
- if (mdi < 0) {
+ if (mdi <= 0) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
goto err;
}
#endif
num = EVP_MD_get_size(hash);
- if (num < 0)
+ if (num <= 0)
return 0;
num = EVP_CIPHER_get_key_length(c) + num + EVP_CIPHER_get_iv_length(c);
ctx->disabled_mac_mask |= t->mask;
} else {
int tmpsize = EVP_MD_get_size(md);
- if (!ossl_assert(tmpsize >= 0))
+
+ if (!ossl_assert(tmpsize > 0))
return 0;
ctx->ssl_mac_secret_size[i] = tmpsize;
}
SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
/* Ensure cast to size_t is safe */
- if (!ossl_assert(hashsizei >= 0)) {
+ if (!ossl_assert(hashsizei > 0)) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
goto err;
}
static const unsigned char nonce_label[] = "resumption";
/* Ensure cast to size_t is safe */
- if (!ossl_assert(hashleni >= 0)) {
+ if (!ossl_assert(hashleni > 0)) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
goto err;
}
int hashleni = EVP_MD_get_size(md);
/* Ensure cast to size_t is safe */
- if (!ossl_assert(hashleni >= 0)) {
+ if (!ossl_assert(hashleni > 0)) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
goto err;
}
mdleni = EVP_MD_get_size(md);
/* Ensure cast to size_t is safe */
- if (!ossl_assert(mdleni >= 0)) {
+ if (!ossl_assert(mdleni > 0)) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
EVP_KDF_CTX_free(kctx);
return 0;
int mode, mac_mdleni;
/* Ensure cast to size_t is safe */
- if (!ossl_assert(hashleni >= 0)) {
+ if (!ossl_assert(hashleni > 0)) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB);
return 0;
}
&& mac_type == NID_hmac) {
mac_mdleni = EVP_MD_get_size(mac_md);
- if (mac_mdleni < 0) {
+ if (mac_mdleni <= 0) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return 0;
}
EVP_PKEY_verify_message_update ? 3_4_0 EXIST::FUNCTION:
EVP_PKEY_verify_message_final ? 3_4_0 EXIST::FUNCTION:
EVP_PKEY_verify_recover_init_ex2 ? 3_4_0 EXIST::FUNCTION:
+EVP_MD_xof ? 3_4_0 EXIST::FUNCTION:
+EVP_MD_CTX_get_size_ex ? 3_4_0 EXIST::FUNCTION:
EVP_CIPHER_CTX_set_algor_params ? 3_4_0 EXIST::FUNCTION:
EVP_CIPHER_CTX_get_algor_params ? 3_4_0 EXIST::FUNCTION:
EVP_CIPHER_CTX_get_algor ? 3_4_0 EXIST::FUNCTION: