CORE: query for operations only once per provider (unless no_store is true)
[openssl.git] / crypto / params.c
index 5d1fc6a6f2d1ea4290d172d593a7b7ab8bd17196..06ae1bc44f37b98276c6a87063b80c41391a4ca0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
  * Copyright (c) 2019, Oracle and/or its affiliates.  All rights reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
@@ -36,10 +36,22 @@ static OSSL_PARAM ossl_param_construct(const char *key, unsigned int data_type,
     res.data_type = data_type;
     res.data = data;
     res.data_size = data_size;
-    res.return_size = 0;
+    res.return_size = OSSL_PARAM_UNMODIFIED;
     return res;
 }
 
+int OSSL_PARAM_modified(const OSSL_PARAM *p)
+{
+    return p != NULL && p->return_size != OSSL_PARAM_UNMODIFIED;
+}
+
+void OSSL_PARAM_set_all_unmodified(OSSL_PARAM *p)
+{
+    if (p != NULL)
+        while (p->key != NULL)
+            p++->return_size = OSSL_PARAM_UNMODIFIED;
+}
+
 int OSSL_PARAM_get_int(const OSSL_PARAM *p, int *val)
 {
     switch (sizeof(int)) {
@@ -768,7 +780,7 @@ static int get_string_internal(const OSSL_PARAM *p, void **val, size_t max_len,
 {
     size_t sz;
 
-    if (val == NULL || p == NULL || p->data_type != type)
+    if ((val == NULL && used_len == NULL) || p == NULL || p->data_type != type)
         return 0;
 
     sz = p->data_size;
@@ -778,6 +790,11 @@ static int get_string_internal(const OSSL_PARAM *p, void **val, size_t max_len,
 
     if (sz == 0)
         return 1;
+    if (p->data == NULL)
+        return 0;
+
+    if (val == NULL)
+        return 1;
 
     if (*val == NULL) {
         char *const q = OPENSSL_malloc(sz);