From: Pauli Date: Wed, 13 Aug 2025 02:26:22 +0000 (+1000) Subject: rsa: made the padding and salt length parameter decoding more straightforward X-Git-Tag: openssl-3.6.0-alpha1~102 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18f822f6a6d7c4f2792387cea76142d051fdcad7;p=thirdparty%2Fopenssl.git rsa: made the padding and salt length parameter decoding more straightforward Reviewed-by: Tomas Mraz Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/28242) --- diff --git a/providers/implementations/signature/rsa_sig.c.in b/providers/implementations/signature/rsa_sig.c.in index ca4a9ba5f4d..43d2e2506d6 100644 --- a/providers/implementations/signature/rsa_sig.c.in +++ b/providers/implementations/signature/rsa_sig.c.in @@ -1417,33 +1417,29 @@ static int rsa_get_ctx_params(void *vprsactx, OSSL_PARAM *params) return 0; } - if (p.pad != NULL) - switch (p.pad->data_type) { - default: + if (p.pad != NULL) { + if (p.pad->data_type != OSSL_PARAM_UTF8_STRING) { if (!OSSL_PARAM_set_int(p.pad, prsactx->pad_mode)) return 0; - break; - case OSSL_PARAM_UTF8_STRING: - { - int i; - const char *word = NULL; + } else { + int i; + const char *word = NULL; - for (i = 0; padding_item[i].id != 0; i++) { - if (prsactx->pad_mode == (int)padding_item[i].id) { - word = padding_item[i].ptr; - break; - } + for (i = 0; padding_item[i].id != 0; i++) { + if (prsactx->pad_mode == (int)padding_item[i].id) { + word = padding_item[i].ptr; + break; } + } - if (word != NULL) { - if (!OSSL_PARAM_set_utf8_string(p.pad, word)) - return 0; - } else { - ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR); - } + if (word != NULL) { + if (!OSSL_PARAM_set_utf8_string(p.pad, word)) + return 0; + } else { + ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR); } - break; } + } if (p.digest != NULL && !OSSL_PARAM_set_utf8_string(p.digest, prsactx->mdname)) return 0; @@ -1613,26 +1609,22 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[]) if (p.pad != NULL) { const char *err_extra_text = NULL; - switch (p.pad->data_type) { - default: /* Support for legacy pad mode number */ + if (p.pad->data_type != OSSL_PARAM_UTF8_STRING) { + /* Support for legacy pad mode number */ if (!OSSL_PARAM_get_int(p.pad, &pad_mode)) return 0; - break; - case OSSL_PARAM_UTF8_STRING: - { - int i; + } else { + int i; - if (p.pad->data == NULL) - return 0; + if (p.pad->data == NULL) + return 0; - for (i = 0; padding_item[i].id != 0; i++) { - if (strcmp(p.pad->data, padding_item[i].ptr) == 0) { - pad_mode = padding_item[i].id; - break; - } + for (i = 0; padding_item[i].id != 0; i++) { + if (strcmp(p.pad->data, padding_item[i].ptr) == 0) { + pad_mode = padding_item[i].id; + break; } } - break; } switch (pad_mode) { @@ -1696,12 +1688,11 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[]) return 0; } - switch (p.slen->data_type) { - default: /* Support for legacy pad mode number */ + if (p.slen->data_type != OSSL_PARAM_UTF8_STRING) { + /* Support for legacy pad mode number */ if (!OSSL_PARAM_get_int(p.slen, &saltlen)) return 0; - break; - case OSSL_PARAM_UTF8_STRING: + } else { if (strcmp(p.slen->data, OSSL_PKEY_RSA_PSS_SALT_LEN_DIGEST) == 0) saltlen = RSA_PSS_SALTLEN_DIGEST; else if (strcmp(p.slen->data, OSSL_PKEY_RSA_PSS_SALT_LEN_MAX) == 0) @@ -1712,7 +1703,6 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[]) saltlen = RSA_PSS_SALTLEN_AUTO_DIGEST_MAX; else saltlen = atoi(p.slen->data); - break; } /*