]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
rsa: made the padding and salt length parameter decoding more straightforward
authorPauli <ppzgs1@gmail.com>
Wed, 13 Aug 2025 02:26:22 +0000 (12:26 +1000)
committerPauli <ppzgs1@gmail.com>
Fri, 15 Aug 2025 01:13:19 +0000 (11:13 +1000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/28242)

providers/implementations/signature/rsa_sig.c.in

index ca4a9ba5f4d1a6d6aeea71c1b93338f68359a205..43d2e2506d67bf71c11c20b68b4c3d75ae6a5132 100644 (file)
@@ -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;
         }
 
         /*