From: Pauli Date: Tue, 12 Aug 2025 05:59:37 +0000 (+1000) Subject: asym cipher: make the pad type decoding more straightforward X-Git-Tag: openssl-3.6.0-alpha1~104 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e676a87a279573b536e2f8cdd810abcf561dfd13;p=thirdparty%2Fopenssl.git asym cipher: make the pad type 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/asymciphers/rsa_enc.c.in b/providers/implementations/asymciphers/rsa_enc.c.in index c1c4f3e9595..27bae13a233 100644 --- a/providers/implementations/asymciphers/rsa_enc.c.in +++ b/providers/implementations/asymciphers/rsa_enc.c.in @@ -383,35 +383,30 @@ static int rsa_get_ctx_params(void *vprsactx, OSSL_PARAM *params) if (prsactx == NULL || !rsa_get_ctx_params_decoder(params, &p)) return 0; - if (p.pad != NULL) - switch (p.pad->data_type) { - case OSSL_PARAM_INTEGER: /* Support for legacy pad mode number */ + if (p.pad != NULL) { + if (p.pad->data_type != OSSL_PARAM_UTF8_STRING) { + /* Support for legacy pad mode number */ if (!OSSL_PARAM_set_int(p.pad, prsactx->pad_mode)) return 0; - break; - case OSSL_PARAM_UTF8_STRING: - { - 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; - } - } + } else { + int i; + const char *word = NULL; - if (word != NULL) { - if (!OSSL_PARAM_set_utf8_string(p.pad, word)) - return 0; - } else { - ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR); + for (i = 0; padding_item[i].id != 0; i++) { + if (prsactx->pad_mode == (int)padding_item[i].id) { + word = padding_item[i].ptr; + break; } } - break; - default: - return 0; + + 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 (p.oaep != NULL && !OSSL_PARAM_set_utf8_string(p.oaep, prsactx->oaep_md == NULL ? "" @@ -510,28 +505,22 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[]) if (p.pad != NULL) { int pad_mode = 0; - switch (p.pad->data_type) { - case OSSL_PARAM_INTEGER: /* Support for legacy pad mode number */ + if (p.pad->data_type != OSSL_PARAM_UTF8_STRING) { + /* Support for legacy pad mode as a 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; - default: - return 0; } /*