The branch master has been updated via 76157664c1eb0f8d9f4e50c4bff8c521f7318b44 (commit) via fce102304a340ef1a90361a03c86bd2401f0b6c3 (commit) via fa95fc1eb5eb7e84523f09248c0ce7f771cfdf58 (commit) from 6a5f97a671de6d4d9f0cd6f6fc23ad89ca4ad69f (commit)
- Log ----------------------------------------------------------------- commit 76157664c1eb0f8d9f4e50c4bff8c521f7318b44 Author: Pauli <pa...@openssl.org> Date: Fri Jun 4 14:35:53 2021 +1000 property: move additional query functions to property_query.c Reviewed-by: Tomas Mraz <to...@openssl.org> Reviewed-by: Matt Caswell <m...@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15614) commit fce102304a340ef1a90361a03c86bd2401f0b6c3 Author: Pauli <pa...@openssl.org> Date: Fri Jun 4 14:25:14 2021 +1000 property: improve ossl_property_find_property() function This function searches a property list for a specific property and returns a pointer to the definition if found. The existing version was O(n) time, the improved O(log n). Reviewed-by: Tomas Mraz <to...@openssl.org> Reviewed-by: Matt Caswell <m...@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15614) commit fa95fc1eb5eb7e84523f09248c0ce7f771cfdf58 Author: Pauli <pa...@openssl.org> Date: Fri Jun 4 13:19:23 2021 +1000 Rename `n` field to `num_properties` in property definition structure. Reviewed-by: Tomas Mraz <to...@openssl.org> Reviewed-by: Matt Caswell <m...@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15614) ----------------------------------------------------------------------- Summary of changes: crypto/property/build.info | 1 - crypto/property/property_local.h | 4 ++- crypto/property/property_parse.c | 59 ++++++++-------------------------------- crypto/property/property_query.c | 39 ++++++++++++++++++++++---- 4 files changed, 49 insertions(+), 54 deletions(-) diff --git a/crypto/property/build.info b/crypto/property/build.info index dac9ab7a3b..12a6b8c9de 100644 --- a/crypto/property/build.info +++ b/crypto/property/build.info @@ -2,4 +2,3 @@ LIBS=../../libcrypto $COMMON=property_string.c property_parse.c property_query.c property.c defn_cache.c SOURCE[../../libcrypto]=$COMMON property_err.c SOURCE[../../providers/libfips.a]=$COMMON -SOURCE[../../providers/liblegacy.a]=$COMMON diff --git a/crypto/property/property_local.h b/crypto/property/property_local.h index db1b0a5ee4..46c5dbe3cc 100644 --- a/crypto/property/property_local.h +++ b/crypto/property/property_local.h @@ -29,11 +29,13 @@ struct ossl_property_definition_st { }; struct ossl_property_list_st { - int n; + int num_properties; unsigned int has_optional : 1; OSSL_PROPERTY_DEFINITION properties[1]; }; +extern OSSL_PROPERTY_IDX ossl_property_true, ossl_property_false; + /* Property string functions */ OSSL_PROPERTY_IDX ossl_property_name(OSSL_LIB_CTX *ctx, const char *s, int create); diff --git a/crypto/property/property_parse.c b/crypto/property/property_parse.c index 149e1956b7..21228b4a39 100644 --- a/crypto/property/property_parse.c +++ b/crypto/property/property_parse.c @@ -19,7 +19,7 @@ #include "property_local.h" #include "e_os.h" -static OSSL_PROPERTY_IDX ossl_property_true, ossl_property_false; +OSSL_PROPERTY_IDX ossl_property_true, ossl_property_false; DEFINE_STACK_OF(OSSL_PROPERTY_DEFINITION) @@ -295,7 +295,7 @@ stack_to_property_list(STACK_OF(OSSL_PROPERTY_DEFINITION) *sk) r->properties[i] = *sk_OSSL_PROPERTY_DEFINITION_value(sk, i); r->has_optional |= r->properties[i].optional; } - r->n = n; + r->num_properties = n; } return r; } @@ -422,41 +422,6 @@ err: return res; } -/* Does a property query have any optional clauses */ -int ossl_property_has_optional(const OSSL_PROPERTY_LIST *query) -{ - return query->has_optional ? 1 : 0; -} - -int ossl_property_is_enabled(OSSL_LIB_CTX *ctx, const char *property_name, - const OSSL_PROPERTY_LIST *prop_list) -{ - int i; - OSSL_PROPERTY_IDX name_id; - const OSSL_PROPERTY_DEFINITION *prop = NULL; - - if (prop_list == NULL) - return 0; - - if (!parse_name(ctx, &property_name, 0, &name_id)) - return 0; - - prop = prop_list->properties; - for (i = 0; i < prop_list->n; ++i) { - if (prop[i].name_idx == name_id) { - /* Do a separate check for override as it does not set type */ - if (prop[i].optional || prop[i].oper == OSSL_PROPERTY_OVERRIDE) - return 0; - return (prop[i].type == OSSL_PROPERTY_TYPE_STRING - && ((prop[i].oper == OSSL_PROPERTY_OPER_EQ - && prop[i].v.str_val == ossl_property_true) - || (prop[i].oper == OSSL_PROPERTY_OPER_NE - && prop[i].v.str_val != ossl_property_true))); - } - } - return 0; -} - /* * Compare a query against a definition. * Return the number of clauses matched or -1 if a mandatory clause is false. @@ -469,12 +434,12 @@ int ossl_property_match_count(const OSSL_PROPERTY_LIST *query, int i = 0, j = 0, matches = 0; OSSL_PROPERTY_OPER oper; - while (i < query->n) { + while (i < query->num_properties) { if ((oper = q[i].oper) == OSSL_PROPERTY_OVERRIDE) { i++; continue; } - if (j < defn->n) { + if (j < defn->num_properties) { if (q[i].name_idx > d[j].name_idx) { /* skip defn, not in query */ j++; continue; @@ -536,7 +501,7 @@ OSSL_PROPERTY_LIST *ossl_property_merge(const OSSL_PROPERTY_LIST *a, const OSSL_PROPERTY_DEFINITION *copy; OSSL_PROPERTY_LIST *r; int i, j, n; - const int t = a->n + b->n; + const int t = a->num_properties + b->num_properties; r = OPENSSL_malloc(sizeof(*r) + (t == 0 ? 0 : t - 1) * sizeof(r->properties[0])); @@ -544,10 +509,10 @@ OSSL_PROPERTY_LIST *ossl_property_merge(const OSSL_PROPERTY_LIST *a, return NULL; r->has_optional = 0; - for (i = j = n = 0; i < a->n || j < b->n; n++) { - if (i >= a->n) { + for (i = j = n = 0; i < a->num_properties || j < b->num_properties; n++) { + if (i >= a->num_properties) { copy = &bp[j++]; - } else if (j >= b->n) { + } else if (j >= b->num_properties) { copy = &ap[i++]; } else if (ap[i].name_idx <= bp[j].name_idx) { if (ap[i].name_idx == bp[j].name_idx) @@ -559,7 +524,7 @@ OSSL_PROPERTY_LIST *ossl_property_merge(const OSSL_PROPERTY_LIST *a, memcpy(r->properties + n, copy, sizeof(r->properties[0])); r->has_optional |= copy->optional; } - r->n = n; + r->num_properties = n; if (n != t) r = OPENSSL_realloc(r, sizeof(*r) + (n - 1) * sizeof(r->properties[0])); return r; @@ -672,9 +637,9 @@ size_t ossl_property_list_to_string(OSSL_LIB_CTX *ctx, *buf = '\0'; return 1; } - if (list->n != 0) - prop = &list->properties[list->n - 1]; - for (i = 0; i < list->n; i++, prop--) { + if (list->num_properties != 0) + prop = &list->properties[list->num_properties - 1]; + for (i = 0; i < list->num_properties; i++, prop--) { /* Skip invalid names */ if (prop->name_idx == 0) continue; diff --git a/crypto/property/property_query.c b/crypto/property/property_query.c index dfcb034042..1352bc009e 100644 --- a/crypto/property/property_query.c +++ b/crypto/property/property_query.c @@ -11,21 +11,27 @@ #include "internal/property.h" #include "property_local.h" +static int property_idx_cmp(const void *keyp, const void *compare) +{ + OSSL_PROPERTY_IDX key = *(const OSSL_PROPERTY_IDX *)keyp; + const OSSL_PROPERTY_DEFINITION *defn = + (const OSSL_PROPERTY_DEFINITION *)compare; + + return key - defn->name_idx; +} + const OSSL_PROPERTY_DEFINITION * ossl_property_find_property(const OSSL_PROPERTY_LIST *list, OSSL_LIB_CTX *libctx, const char *name) { OSSL_PROPERTY_IDX name_idx; - int i; if (list == NULL || name == NULL || (name_idx = ossl_property_name(libctx, name, 0)) == 0) return NULL; - for (i = 0; i < list->n; i++) - if (list->properties[i].name_idx == name_idx) - return &list->properties[i]; - return NULL; + return ossl_bsearch(&name_idx, list->properties, list->num_properties, + sizeof(*list->properties), &property_idx_cmp, 0); } OSSL_PROPERTY_TYPE ossl_property_get_type(const OSSL_PROPERTY_DEFINITION *prop) @@ -51,3 +57,26 @@ int64_t ossl_property_get_number_value(const OSSL_PROPERTY_DEFINITION *prop) value = prop->v.int_val; return value; } + +/* Does a property query have any optional clauses */ +int ossl_property_has_optional(const OSSL_PROPERTY_LIST *query) +{ + return query->has_optional ? 1 : 0; +} + +int ossl_property_is_enabled(OSSL_LIB_CTX *ctx, const char *property_name, + const OSSL_PROPERTY_LIST *prop_list) +{ + const OSSL_PROPERTY_DEFINITION *prop; + + prop = ossl_property_find_property(prop_list, ctx, property_name); + /* Do a separate check for override as it does not set type */ + if (prop == NULL || prop->optional || prop->oper == OSSL_PROPERTY_OVERRIDE) + return 0; + return (prop->type == OSSL_PROPERTY_TYPE_STRING + && ((prop->oper == OSSL_PROPERTY_OPER_EQ + && prop->v.str_val == ossl_property_true) + || (prop->oper == OSSL_PROPERTY_OPER_NE + && prop->v.str_val != ossl_property_true))); +} +