]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
asym cipher: make the pad type decoding more straightforward
authorPauli <ppzgs1@gmail.com>
Tue, 12 Aug 2025 05:59:37 +0000 (15:59 +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/asymciphers/rsa_enc.c.in

index c1c4f3e9595eadaaec92c169acf03b3d993d32ab..27bae13a23383d0599bbbff49015c18f24a6364b 100644 (file)
@@ -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;
         }
 
         /*