params: change OSSL_PARAM_set_unmodified() to operate on a params array
authorPauli <paul.dale@oracle.com>
Thu, 23 Apr 2020 10:23:48 +0000 (20:23 +1000)
committerPauli <paul.dale@oracle.com>
Sat, 25 Apr 2020 08:46:32 +0000 (18:46 +1000)
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/11601)

crypto/params.c
doc/man3/OSSL_PARAM_int.pod
include/openssl/params.h
test/params_api_test.c
util/libcrypto.num

index 98c83bbe426a5691ae574c6812b37db15328bd7a..32161d0533884c34cc4cf55702fc4ac96cb8dc9b 100644 (file)
@@ -45,10 +45,11 @@ int OSSL_PARAM_modified(const OSSL_PARAM *p)
     return p != NULL && p->return_size != OSSL_PARAM_UNMODIFIED;
 }
 
-void OSSL_PARAM_set_unmodified(OSSL_PARAM *p)
+void OSSL_PARAM_set_all_unmodified(OSSL_PARAM *p)
 {
     if (p != NULL)
-        p->return_size = OSSL_PARAM_UNMODIFIED;
+        while (p->key != NULL)
+            p++->return_size = OSSL_PARAM_UNMODIFIED;
 }
 
 int OSSL_PARAM_get_int(const OSSL_PARAM *p, int *val)
index b6faedb9111d52e43dcd4bb3d0fc19178432ede7..9126906883a9dac3f32b8eee5f34b9d3e0bc36ef 100644 (file)
@@ -93,8 +93,8 @@ OSSL_PARAM_set_octet_ptr, OSSL_PARAM_UNMODIFIED
  int OSSL_PARAM_set_octet_ptr(OSSL_PARAM *p, const void *val,
                               size_t used_len);
 
- int OSSL_PARAM_modified(const OSSL_PARAM *p);
- void OSSL_PARAM_set_unmodified(OSSL_PARAM *p);
+ int OSSL_PARAM_modified(const OSSL_PARAM *param);
+ void OSSL_PARAM_set_all_unmodified(OSSL_PARAM *params);
 
 =head1 DESCRIPTION
 
@@ -260,10 +260,11 @@ creation, via either the macros or construct calls, the I<return_size> field
 is set to this.  If the parameter is set using the calls defined herein, the
 I<return_size> field is changed.
 
-OSSL_PARAM_modified() queries if the parameter has been set or not using the
-calls defined herein.
+OSSL_PARAM_modified() queries if the parameter B<param> has been set or not
+using the calls defined herein.
 
-OSSL_PARAM_set_unmodified() is used to reset unused indicator.
+OSSL_PARAM_set_all_unmodified() resets the unused indicator for all parameters
+in the array B<params>.
 
 =head1 RETURN VALUES
 
index 9f6dcb49ac1005daab58351bd76bace0fac25301..993ee8188ecb8e2ce6091c75ccd74f990618ccb3 100644 (file)
@@ -138,7 +138,7 @@ int OSSL_PARAM_set_octet_ptr(OSSL_PARAM *p, const void *val,
                              size_t used_len);
 
 int OSSL_PARAM_modified(const OSSL_PARAM *p);
-void OSSL_PARAM_set_unmodified(OSSL_PARAM *p);
+void OSSL_PARAM_set_all_unmodified(OSSL_PARAM *p);
 
 # ifdef  __cplusplus
 }
index 43cdd755315323bf1ae3c67210eb1fbd248bbfff..110820c8d1183bbef3f158248bbd6fe3ac6855dc 100644 (file)
@@ -69,7 +69,11 @@ static int test_param_type_extra(OSSL_PARAM *param, const unsigned char *cmp,
     const int sizet = bit32 && sizeof(size_t) > sizeof(int32_t);
     const int signd = param->data_type == OSSL_PARAM_INTEGER;
 
-    OSSL_PARAM_set_unmodified(param);
+    /*
+     * Set the unmodified sentinal directly because there is no param array
+     * for these tests.
+     */
+    param->return_size = OSSL_PARAM_UNMODIFIED;
     if (signd) {
         if ((bit32 && !TEST_true(OSSL_PARAM_get_int32(param, &i32)))
             || !TEST_true(OSSL_PARAM_get_int64(param, &i64)))
@@ -568,6 +572,33 @@ err:
     return ret;
 }
 
+static int test_param_modified(void)
+{
+    OSSL_PARAM param[3] = { OSSL_PARAM_int("a", NULL),
+                            OSSL_PARAM_int("b", NULL),
+                            OSSL_PARAM_END };
+    int a, b;
+
+    param->data = &a;
+    param[1].data = &b;
+    if (!TEST_false(OSSL_PARAM_modified(param))
+            && !TEST_true(OSSL_PARAM_set_int32(param, 1234))
+            && !TEST_true(OSSL_PARAM_modified(param))
+            && !TEST_false(OSSL_PARAM_modified(param + 1))
+            && !TEST_true(OSSL_PARAM_set_int32(param + 1, 1))
+            && !TEST_true(OSSL_PARAM_modified(param + 1)))
+        return 0;
+    OSSL_PARAM_set_all_unmodified(param);
+    if (!TEST_false(OSSL_PARAM_modified(param))
+            && !TEST_true(OSSL_PARAM_set_int32(param, 4321))
+            && !TEST_true(OSSL_PARAM_modified(param))
+            && !TEST_false(OSSL_PARAM_modified(param + 1))
+            && !TEST_true(OSSL_PARAM_set_int32(param + 1, 2))
+            && !TEST_true(OSSL_PARAM_modified(param + 1)))
+        return 0;
+    return 1;
+}
+
 int setup_tests(void)
 {
     ADD_ALL_TESTS(test_param_int, OSSL_NELEM(raw_values));
@@ -582,5 +613,6 @@ int setup_tests(void)
     ADD_ALL_TESTS(test_param_bignum, OSSL_NELEM(raw_values));
     ADD_TEST(test_param_real);
     ADD_TEST(test_param_construct);
+    ADD_TEST(test_param_modified);
     return 1;
 }
index dbaea8c716863cc7f10325f29ce9e4eb7b2b400f..79f8fd86c0d47171fd05933b02d44555c555dee1 100644 (file)
@@ -5078,4 +5078,4 @@ X509_ALGOR_copy                         ? 3_0_0   EXIST::FUNCTION:
 X509_REQ_set0_signature                 ?      3_0_0   EXIST::FUNCTION:
 X509_REQ_set1_signature_algo            ?      3_0_0   EXIST::FUNCTION:
 OSSL_PARAM_modified                     ?      3_0_0   EXIST::FUNCTION:
-OSSL_PARAM_set_unmodified               ?      3_0_0   EXIST::FUNCTION:
+OSSL_PARAM_set_all_unmodified           ?      3_0_0   EXIST::FUNCTION: