Params: add argument to the _from_text calls to indicate if the param exists.
authorPauli <paul.dale@oracle.com>
Mon, 10 Feb 2020 03:29:49 +0000 (13:29 +1000)
committerRichard Levitte <levitte@openssl.org>
Fri, 21 Feb 2020 12:04:25 +0000 (13:04 +0100)
The extra argument is a integer pointer and is optional.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/11049)

apps/lib/apps.c
crypto/evp/pkey_kdf.c
crypto/evp/pkey_mac.c
crypto/evp/pmeth_lib.c
crypto/params_from_text.c
doc/man3/OSSL_PARAM_allocate_from_text.pod
include/openssl/params.h
providers/fips/self_test_kats.c
test/evp_test.c

index bf20254463ff967893a55ef0801bf4c1b8634db3..3a9521f67e4539b7cd7ac763bb58f94d07a72143 100644 (file)
@@ -2708,7 +2708,7 @@ OSSL_PARAM *app_params_new_from_opts(STACK_OF(OPENSSL_STRING) *opts,
         /* Skip over the separator so that vmtp points to the value */
         vtmp++;
         if (!OSSL_PARAM_allocate_from_text(&params[params_n], paramdefs,
-                                           stmp, vtmp, strlen(vtmp)))
+                                           stmp, vtmp, strlen(vtmp), NULL))
             goto err;
         OPENSSL_free(stmp);
     }
index 818c89eab2c553568494a05d30262f1810b7e1dc..86c2fac612ad2271164d837df6bf45e660ab9c55 100644 (file)
@@ -224,7 +224,7 @@ static int pkey_kdf_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
         type = OSSL_KDF_PARAM_SCRYPT_N;
 
     if (!OSSL_PARAM_allocate_from_text(&params[0], defs, type,
-                                       value, strlen(value)))
+                                       value, strlen(value), NULL))
         return 0;
 
     /*
index 1c8f8785122435fb285232eeb731799947d0d456..ed3a075f888a1be24a705b57f59e2e7dcef48203 100644 (file)
@@ -453,7 +453,7 @@ static int pkey_mac_ctrl_str(EVP_PKEY_CTX *ctx,
 
     if (!OSSL_PARAM_allocate_from_text(&params[0],
                                        EVP_MAC_settable_ctx_params(mac),
-                                       type, value, strlen(value) + 1))
+                                       type, value, strlen(value) + 1, NULL))
         return 0;
     params[1] = OSSL_PARAM_construct_end();
     ok = EVP_MAC_CTX_set_params(hctx->ctx, params);
index 49af63845e5e7a95b1ead81d2a55ede6f133b8ec..20cbb08559aa58b01d8a197f35259dff868eb03d 100644 (file)
@@ -940,7 +940,7 @@ static int legacy_ctrl_str_to_param(EVP_PKEY_CTX *ctx, const char *name,
         int rv = 0;
 
         if (!OSSL_PARAM_allocate_from_text(&params[0], settable, name, value,
-                                           strlen(value)))
+                                           strlen(value), NULL))
             return 0;
         if (EVP_PKEY_CTX_set_params(ctx, params))
             rv = 1;
index 59cee5f1159bd2c6c1366ae3322d742c7c18b2d3..71fa8aef9226d765254ed9ccdb22d5d56b1b1852 100644 (file)
@@ -24,7 +24,7 @@ static int prepare_from_text(const OSSL_PARAM *paramdefs, const char *key,
                              const char *value, size_t value_n,
                              /* Output parameters */
                              const OSSL_PARAM **paramdef, int *ishex,
-                             size_t *buf_n, BIGNUM **tmpbn)
+                             size_t *buf_n, BIGNUM **tmpbn, int *found)
 {
     const OSSL_PARAM *p;
 
@@ -38,6 +38,8 @@ static int prepare_from_text(const OSSL_PARAM *paramdefs, const char *key,
         key += 3;
 
     p = *paramdef = OSSL_PARAM_locate_const(paramdefs, key);
+    if (found != NULL)
+        *found = p != NULL;
     if (p == NULL)
         return 0;
 
@@ -163,7 +165,7 @@ static int construct_from_text(OSSL_PARAM *to, const OSSL_PARAM *paramdef,
 int OSSL_PARAM_allocate_from_text(OSSL_PARAM *to,
                                   const OSSL_PARAM *paramdefs,
                                   const char *key, const char *value,
-                                  size_t value_n)
+                                  size_t value_n, int *found)
 {
     const OSSL_PARAM *paramdef = NULL;
     int ishex = 0;
@@ -176,7 +178,7 @@ int OSSL_PARAM_allocate_from_text(OSSL_PARAM *to,
         return 0;
 
     if (!prepare_from_text(paramdefs, key, value, value_n,
-                           &paramdef, &ishex, &buf_n, &tmpbn))
+                           &paramdef, &ishex, &buf_n, &tmpbn, found))
         return 0;
 
     if ((buf = OPENSSL_zalloc(buf_n > 0 ? buf_n : 1)) == NULL) {
index c16491e702ed5e0a6a4089dba5ca4a5f6c96b352..48dbfc75c529fc8b3a5cba87cd334c596611bca1 100644 (file)
@@ -12,7 +12,8 @@ OSSL_PARAM_allocate_from_text
  int OSSL_PARAM_allocate_from_text(OSSL_PARAM *to,
                                    const OSSL_PARAM *paramdefs,
                                    const char *key, const char *value,
-                                   size_t value_n);
+                                   size_t value_n,
+                                   int *found);
 
 =head1 DESCRIPTION
 
@@ -37,6 +38,9 @@ left untouched, allowing a caller to find out how large the buffer
 should be.
 I<buf> needs to be correctly aligned for the type of the B<OSSL_PARAM>
 I<key>.
+If <found> is not NULL, it is set to 1 if the parameter can be located and
+to 0 otherwise.
+
 The caller must remember to free the data of I<to> when it's not
 useful any more.
 
@@ -127,7 +131,7 @@ Can be written like this instead:
       *vtmp++ = '\0';
       if (!OSSL_PARAM_allocate_from_text(&params[params_n],
                                          paramdefs, stmp,
-                                         vtmp, strlen(vtmp)))
+                                         vtmp, strlen(vtmp), NULL))
           goto err;
   }
   params[params_n] = OSSL_PARAM_construct_end();
index a5d2fd4f41bba0f9a72c49a710bcdffaf4ecc456..cd0f7846d7e6818eece5e9c18cdfaf8438f4cbfb 100644 (file)
@@ -92,7 +92,7 @@ OSSL_PARAM OSSL_PARAM_construct_end(void);
 int OSSL_PARAM_allocate_from_text(OSSL_PARAM *to,
                                   const OSSL_PARAM *paramdefs,
                                   const char *key, const char *value,
-                                  size_t value_n);
+                                  size_t value_n, int *found);
 
 int OSSL_PARAM_get_int(const OSSL_PARAM *p, int *val);
 int OSSL_PARAM_get_uint(const OSSL_PARAM *p, unsigned int *val);
index f67f4f69c8fb3c93a8a0d331ec737eba5b54fa23..a383c0c36dc27d57fffc025d2015f38e44f448df 100644 (file)
@@ -167,7 +167,7 @@ static int self_test_kdf(const ST_KAT_KDF *t, OSSL_ST_EVENT *event,
         if (!OSSL_PARAM_allocate_from_text(&params[i], settables,
                                            t->ctrls[i].name,
                                            t->ctrls[i].value,
-                                           strlen(t->ctrls[i].value)))
+                                           strlen(t->ctrls[i].value), NULL))
             goto end;
     }
     if (!EVP_KDF_CTX_set_params(ctx, params))
index 87e901fdb43cf95e580bbb2c4b730a252db88869..63ae14492040889eafd62bb74a9b852db1510248 100644 (file)
@@ -1310,7 +1310,7 @@ static int mac_test_run_mac(EVP_TEST *t)
             || !OSSL_PARAM_allocate_from_text(&params[params_n],
                                               defined_params,
                                               tmpkey, tmpval,
-                                              strlen(tmpval))) {
+                                              strlen(tmpval), NULL)) {
             OPENSSL_free(tmpkey);
             t->err = "MAC_PARAM_ERROR";
             goto err;
@@ -2129,7 +2129,7 @@ static int kdf_test_ctrl(EVP_TEST *t, EVP_KDF_CTX *kctx,
         *p++ = '\0';
 
     rv = OSSL_PARAM_allocate_from_text(kdata->p, defs, name, p,
-                                       p != NULL ? strlen(p) : 0);
+                                       p != NULL ? strlen(p) : 0, NULL);
     *++kdata->p = OSSL_PARAM_construct_end();
     if (!rv) {
         t->err = "KDF_PARAM_ERROR";