Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

swh:1:snp:dc2a5002442a00b1c0eda7c65d04ea7455e166cd
  • Code
  • Branches (204)
  • Releases (207)
    • Branches
    • Releases
    • HEAD
    • refs/heads/OpenSSL-engine-0_9_6-stable
    • refs/heads/OpenSSL-fips-0_9_7-stable
    • refs/heads/OpenSSL-fips-0_9_8-stable
    • refs/heads/OpenSSL-fips-1_2-stable
    • refs/heads/OpenSSL-fips-2_0-dev
    • refs/heads/OpenSSL-fips-2_0-stable
    • refs/heads/OpenSSL-fips2-0_9_7-stable
    • refs/heads/OpenSSL_0_9_6-stable
    • refs/heads/OpenSSL_0_9_7-stable
    • refs/heads/OpenSSL_0_9_8-stable
    • refs/heads/OpenSSL_0_9_8fg-stable
    • refs/heads/OpenSSL_1_0_0-stable
    • refs/heads/OpenSSL_1_0_1-stable
    • refs/heads/OpenSSL_1_0_2-stable
    • refs/heads/OpenSSL_1_1_0-stable
    • refs/heads/OpenSSL_1_1_1-stable
    • refs/heads/SSLeay
    • refs/heads/feature/dtls-1.3
    • refs/heads/feature/ech
    • refs/heads/feature/quic-server
    • refs/heads/master
    • refs/heads/openssl-3.0
    • refs/heads/openssl-3.1
    • refs/heads/openssl-3.2
    • refs/heads/openssl-3.3
    • refs/heads/openssl-3.4
    • refs/heads/tls1.3-draft-18
    • refs/heads/tls1.3-draft-19
    • refs/tags/AFTER_COMPAQ_PATCH
    • refs/tags/BEFORE_COMPAQ_PATCH
    • refs/tags/BEFORE_engine
    • refs/tags/BEN_FIPS_TEST_1
    • refs/tags/BEN_FIPS_TEST_2
    • refs/tags/BEN_FIPS_TEST_3
    • refs/tags/BEN_FIPS_TEST_4
    • refs/tags/BEN_FIPS_TEST_5
    • refs/tags/BEN_FIPS_TEST_6
    • refs/tags/BEN_FIPS_TEST_7
    • refs/tags/BEN_FIPS_TEST_8
    • refs/tags/FIPS_098_TEST_1
    • refs/tags/FIPS_098_TEST_2
    • refs/tags/FIPS_098_TEST_3
    • refs/tags/FIPS_098_TEST_4
    • refs/tags/FIPS_098_TEST_5
    • refs/tags/FIPS_098_TEST_6
    • refs/tags/FIPS_098_TEST_7
    • refs/tags/FIPS_098_TEST_8
    • refs/tags/FIPS_TEST_10
    • refs/tags/FIPS_TEST_9
    • refs/tags/LEVITTE_after_const
    • refs/tags/LEVITTE_before_const
    • refs/tags/OpenSSL-engine-0_9_6
    • refs/tags/OpenSSL-engine-0_9_6-beta1
    • refs/tags/OpenSSL-engine-0_9_6-beta2
    • refs/tags/OpenSSL-engine-0_9_6-beta3
    • refs/tags/OpenSSL-engine-0_9_6a
    • refs/tags/OpenSSL-engine-0_9_6a-beta1
    • refs/tags/OpenSSL-engine-0_9_6a-beta2
    • refs/tags/OpenSSL-engine-0_9_6a-beta3
    • refs/tags/OpenSSL-engine-0_9_6b
    • refs/tags/OpenSSL-engine-0_9_6c
    • refs/tags/OpenSSL-engine-0_9_6d
    • refs/tags/OpenSSL-engine-0_9_6d-beta1
    • refs/tags/OpenSSL-engine-0_9_6e
    • refs/tags/OpenSSL-engine-0_9_6f
    • refs/tags/OpenSSL-engine-0_9_6g
    • refs/tags/OpenSSL-engine-0_9_6h
    • refs/tags/OpenSSL-engine-0_9_6i
    • refs/tags/OpenSSL-engine-0_9_6j
    • refs/tags/OpenSSL-engine-0_9_6k
    • refs/tags/OpenSSL-engine-0_9_6l
    • refs/tags/OpenSSL-engine-0_9_6m
    • refs/tags/OpenSSL-fips-1_2_0
    • refs/tags/OpenSSL-fips-1_2_1
    • refs/tags/OpenSSL-fips-1_2_2
    • refs/tags/OpenSSL-fips-1_2_3
    • refs/tags/OpenSSL-fips-2_0
    • refs/tags/OpenSSL-fips-2_0-pl1
    • refs/tags/OpenSSL-fips-2_0-rc1
    • refs/tags/OpenSSL-fips-2_0-rc2
    • refs/tags/OpenSSL-fips-2_0-rc3
    • refs/tags/OpenSSL-fips-2_0-rc4
    • refs/tags/OpenSSL-fips-2_0-rc5
    • refs/tags/OpenSSL-fips-2_0-rc6
    • refs/tags/OpenSSL-fips-2_0-rc7
    • refs/tags/OpenSSL-fips-2_0-rc8
    • refs/tags/OpenSSL-fips-2_0-rc9
    • refs/tags/OpenSSL-fips-2_0_1
    • refs/tags/OpenSSL_0_9_1c
    • refs/tags/OpenSSL_0_9_2b
    • refs/tags/OpenSSL_0_9_3
    • refs/tags/OpenSSL_0_9_3a
    • refs/tags/OpenSSL_0_9_3beta1
    • refs/tags/OpenSSL_0_9_3beta2
    • refs/tags/OpenSSL_0_9_4
    • refs/tags/OpenSSL_0_9_5
    • refs/tags/OpenSSL_0_9_5a
    • refs/tags/OpenSSL_0_9_5a-beta1
    • refs/tags/OpenSSL_0_9_5a-beta2
    • refs/tags/OpenSSL_0_9_5beta1
    • refs/tags/OpenSSL_0_9_5beta2
    • refs/tags/OpenSSL_0_9_6
    • refs/tags/OpenSSL_0_9_6-beta1
    • refs/tags/OpenSSL_0_9_6-beta2
    • refs/tags/OpenSSL_0_9_6-beta3
    • refs/tags/OpenSSL_0_9_6a
    • refs/tags/OpenSSL_0_9_6a-beta1
    • refs/tags/OpenSSL_0_9_6a-beta2
    • refs/tags/OpenSSL_0_9_6a-beta3
    • refs/tags/OpenSSL_0_9_6b
    • refs/tags/OpenSSL_0_9_6c
    • refs/tags/OpenSSL_0_9_6d
    • refs/tags/OpenSSL_0_9_6d-beta1
    • refs/tags/OpenSSL_0_9_6e
    • refs/tags/OpenSSL_0_9_6f
    • refs/tags/OpenSSL_0_9_6g
    • refs/tags/OpenSSL_0_9_6h
    • refs/tags/OpenSSL_0_9_6i
    • refs/tags/OpenSSL_0_9_6j
    • refs/tags/OpenSSL_0_9_6k
    • refs/tags/OpenSSL_0_9_6l
    • refs/tags/OpenSSL_0_9_6m
    • refs/tags/OpenSSL_0_9_7
    • refs/tags/OpenSSL_0_9_7-beta1
    • refs/tags/OpenSSL_0_9_7-beta2
    • refs/tags/OpenSSL_0_9_7-beta3
    • refs/tags/OpenSSL_0_9_7-beta4
    • refs/tags/OpenSSL_0_9_7-beta5
    • refs/tags/OpenSSL_0_9_7-beta6
    • refs/tags/OpenSSL_0_9_7a
    • refs/tags/OpenSSL_0_9_7b
    • refs/tags/OpenSSL_0_9_7c
    • refs/tags/OpenSSL_0_9_7d
    • refs/tags/OpenSSL_0_9_7e
    • refs/tags/OpenSSL_0_9_7f
    • refs/tags/OpenSSL_0_9_7g
    • refs/tags/OpenSSL_0_9_7h
    • refs/tags/OpenSSL_0_9_7i
    • refs/tags/OpenSSL_0_9_7j
    • refs/tags/OpenSSL_0_9_7k
    • refs/tags/OpenSSL_0_9_7l
    • refs/tags/OpenSSL_0_9_7m
    • refs/tags/OpenSSL_0_9_8
    • refs/tags/OpenSSL_0_9_8-beta1
    • refs/tags/OpenSSL_0_9_8-beta2
    • refs/tags/OpenSSL_0_9_8-beta3
    • refs/tags/OpenSSL_0_9_8-beta4
    • refs/tags/OpenSSL_0_9_8-beta5
    • refs/tags/OpenSSL_0_9_8-beta6
    • refs/tags/OpenSSL_0_9_8a
    • refs/tags/OpenSSL_0_9_8b
    • refs/tags/OpenSSL_0_9_8c
    • refs/tags/OpenSSL_0_9_8d
    • refs/tags/OpenSSL_0_9_8e
    • refs/tags/OpenSSL_0_9_8f
    • refs/tags/OpenSSL_0_9_8g
    • refs/tags/OpenSSL_0_9_8h
    • refs/tags/OpenSSL_0_9_8i
    • refs/tags/OpenSSL_0_9_8j
    • refs/tags/OpenSSL_0_9_8k
    • refs/tags/OpenSSL_0_9_8l
    • refs/tags/OpenSSL_0_9_8m
    • refs/tags/OpenSSL_0_9_8m-beta1
    • refs/tags/OpenSSL_0_9_8n
    • refs/tags/OpenSSL_0_9_8o
    • refs/tags/OpenSSL_0_9_8p
    • refs/tags/OpenSSL_0_9_8q
    • refs/tags/OpenSSL_0_9_8r
    • refs/tags/OpenSSL_0_9_8s
    • refs/tags/OpenSSL_0_9_8t
    • refs/tags/OpenSSL_0_9_8u
    • refs/tags/OpenSSL_0_9_8v
    • refs/tags/OpenSSL_0_9_8w
    • refs/tags/OpenSSL_0_9_8x
    • refs/tags/OpenSSL_1_0_0
    • refs/tags/OpenSSL_1_0_0-beta1
    • refs/tags/OpenSSL_1_0_0-beta2
    • refs/tags/OpenSSL_1_0_0-beta3
    • refs/tags/OpenSSL_1_0_0-beta4
    • refs/tags/OpenSSL_1_0_0-beta5
    • refs/tags/OpenSSL_1_0_0a
    • refs/tags/OpenSSL_1_0_0b
    • refs/tags/OpenSSL_1_0_0c
    • refs/tags/OpenSSL_1_0_0d
    • refs/tags/OpenSSL_1_0_0e
    • refs/tags/OpenSSL_1_0_0f
    • refs/tags/OpenSSL_1_0_0g
    • refs/tags/OpenSSL_1_0_0h
    • refs/tags/OpenSSL_1_0_0i
    • refs/tags/OpenSSL_1_0_0j
    • refs/tags/OpenSSL_1_0_1
    • refs/tags/OpenSSL_1_0_1-beta1
    • refs/tags/OpenSSL_1_0_1-beta2
    • refs/tags/OpenSSL_1_0_1-beta3
    • refs/tags/OpenSSL_1_0_1a
    • refs/tags/OpenSSL_1_0_1b
    • refs/tags/OpenSSL_1_0_1c
    • refs/tags/OpenSSL_FIPS_1_0
    • refs/tags/SSLeay_0_8_1b
    • refs/tags/SSLeay_0_9_0b
    • refs/tags/SSLeay_0_9_1b
    • refs/tags/STATE_after_zlib
    • refs/tags/STATE_before_zlib
    • refs/tags/rsaref
    • openssl-3.4.0-alpha1
    • openssl-3.3.2
    • openssl-3.3.1
    • openssl-3.3.0-beta1
    • openssl-3.3.0-alpha1
    • openssl-3.3.0
    • openssl-3.2.3
    • openssl-3.2.2
    • openssl-3.2.1
    • openssl-3.2.0-beta1
    • openssl-3.2.0-alpha2
    • openssl-3.2.0-alpha1
    • openssl-3.2.0
    • openssl-3.1.7
    • openssl-3.1.6
    • openssl-3.1.5
    • openssl-3.1.4
    • openssl-3.1.3
    • openssl-3.1.2
    • openssl-3.1.1
    • openssl-3.1.0-beta1
    • openssl-3.1.0-alpha1
    • openssl-3.1.0
    • openssl-3.0.9
    • openssl-3.0.8
    • openssl-3.0.7
    • openssl-3.0.6
    • openssl-3.0.5
    • openssl-3.0.4
    • openssl-3.0.3
    • openssl-3.0.2
    • openssl-3.0.15
    • openssl-3.0.14
    • openssl-3.0.13
    • openssl-3.0.12
    • openssl-3.0.11
    • openssl-3.0.10
    • openssl-3.0.1
    • openssl-3.0.0-beta2
    • openssl-3.0.0-beta1
    • openssl-3.0.0-alpha9
    • openssl-3.0.0-alpha8
    • openssl-3.0.0-alpha7
    • openssl-3.0.0-alpha6
    • openssl-3.0.0-alpha5
    • openssl-3.0.0-alpha4
    • openssl-3.0.0-alpha3
    • openssl-3.0.0-alpha2
    • openssl-3.0.0-alpha17
    • openssl-3.0.0-alpha16
    • openssl-3.0.0-alpha15
    • openssl-3.0.0-alpha14
    • openssl-3.0.0-alpha13
    • openssl-3.0.0-alpha12
    • openssl-3.0.0-alpha11
    • openssl-3.0.0-alpha10
    • openssl-3.0.0-alpha1
    • openssl-3.0.0
    • master-pre-reformat
    • master-pre-auto-reformat
    • master-post-reformat
    • master-post-auto-reformat
    • OpenSSL_1_1_1w
    • OpenSSL_1_1_1v
    • OpenSSL_1_1_1u
    • OpenSSL_1_1_1t
    • OpenSSL_1_1_1s
    • OpenSSL_1_1_1r
    • OpenSSL_1_1_1q
    • OpenSSL_1_1_1p
    • OpenSSL_1_1_1o
    • OpenSSL_1_1_1n
    • OpenSSL_1_1_1m
    • OpenSSL_1_1_1l
    • OpenSSL_1_1_1k
    • OpenSSL_1_1_1j
    • OpenSSL_1_1_1i
    • OpenSSL_1_1_1h
    • OpenSSL_1_1_1g
    • OpenSSL_1_1_1f
    • OpenSSL_1_1_1e
    • OpenSSL_1_1_1d
    • OpenSSL_1_1_1c
    • OpenSSL_1_1_1b
    • OpenSSL_1_1_1a
    • OpenSSL_1_1_1-pre9
    • OpenSSL_1_1_1-pre8
    • OpenSSL_1_1_1-pre7
    • OpenSSL_1_1_1-pre6
    • OpenSSL_1_1_1-pre5
    • OpenSSL_1_1_1-pre4
    • OpenSSL_1_1_1-pre3
    • OpenSSL_1_1_1-pre2
    • OpenSSL_1_1_1-pre1
    • OpenSSL_1_1_1
    • OpenSSL_1_1_0l
    • OpenSSL_1_1_0k
    • OpenSSL_1_1_0j
    • OpenSSL_1_1_0i
    • OpenSSL_1_1_0h
    • OpenSSL_1_1_0g
    • OpenSSL_1_1_0f
    • OpenSSL_1_1_0e
    • OpenSSL_1_1_0d
    • OpenSSL_1_1_0c
    • OpenSSL_1_1_0b
    • OpenSSL_1_1_0a
    • OpenSSL_1_1_0-pre6
    • OpenSSL_1_1_0-pre5
    • OpenSSL_1_1_0-pre4
    • OpenSSL_1_1_0-pre3
    • OpenSSL_1_1_0-pre2
    • OpenSSL_1_1_0-pre1
    • OpenSSL_1_1_0
    • OpenSSL_1_0_2u
    • OpenSSL_1_0_2t
    • OpenSSL_1_0_2s
    • OpenSSL_1_0_2r
    • OpenSSL_1_0_2q
    • OpenSSL_1_0_2p
    • OpenSSL_1_0_2o
    • OpenSSL_1_0_2n
    • OpenSSL_1_0_2m
    • OpenSSL_1_0_2l
    • OpenSSL_1_0_2k
    • OpenSSL_1_0_2j
    • OpenSSL_1_0_2i
    • OpenSSL_1_0_2h
    • OpenSSL_1_0_2g
    • OpenSSL_1_0_2f
    • OpenSSL_1_0_2e
    • OpenSSL_1_0_2d
    • OpenSSL_1_0_2c
    • OpenSSL_1_0_2b
    • OpenSSL_1_0_2a
    • OpenSSL_1_0_2-pre-reformat
    • OpenSSL_1_0_2-pre-auto-reformat
    • OpenSSL_1_0_2-post-reformat
    • OpenSSL_1_0_2-post-auto-reformat
    • OpenSSL_1_0_2-beta3
    • OpenSSL_1_0_2-beta2
    • OpenSSL_1_0_2-beta1
    • OpenSSL_1_0_2
    • OpenSSL_1_0_1u
    • OpenSSL_1_0_1t
    • OpenSSL_1_0_1s
    • OpenSSL_1_0_1r
    • OpenSSL_1_0_1q
    • OpenSSL_1_0_1p
    • OpenSSL_1_0_1o
    • OpenSSL_1_0_1n
    • OpenSSL_1_0_1m
    • OpenSSL_1_0_1l
    • OpenSSL_1_0_1k
    • OpenSSL_1_0_1j
    • OpenSSL_1_0_1i
    • OpenSSL_1_0_1h
    • OpenSSL_1_0_1g
    • OpenSSL_1_0_1f
    • OpenSSL_1_0_1e
    • OpenSSL_1_0_1d
    • OpenSSL_1_0_1-pre-reformat
    • OpenSSL_1_0_1-pre-auto-reformat
    • OpenSSL_1_0_1-post-reformat
    • OpenSSL_1_0_1-post-auto-reformat
    • OpenSSL_1_0_0t
    • OpenSSL_1_0_0s
    • OpenSSL_1_0_0r
    • OpenSSL_1_0_0q
    • OpenSSL_1_0_0p
    • OpenSSL_1_0_0o
    • OpenSSL_1_0_0n
    • OpenSSL_1_0_0m
    • OpenSSL_1_0_0l
    • OpenSSL_1_0_0k
    • OpenSSL_1_0_0-pre-reformat
    • OpenSSL_1_0_0-pre-auto-reformat
    • OpenSSL_1_0_0-post-reformat
    • OpenSSL_1_0_0-post-auto-reformat
    • OpenSSL_0_9_8zh
    • OpenSSL_0_9_8zg
    • OpenSSL_0_9_8zf
    • OpenSSL_0_9_8ze
    • OpenSSL_0_9_8zd
    • OpenSSL_0_9_8zc
    • OpenSSL_0_9_8zb
    • OpenSSL_0_9_8za
    • OpenSSL_0_9_8y
    • OpenSSL_0_9_8-pre-reformat
    • OpenSSL_0_9_8-pre-auto-reformat
    • OpenSSL_0_9_8-post-reformat
    • OpenSSL_0_9_8-post-auto-reformat
    • OpenSSL-fips-2_0_9
    • OpenSSL-fips-2_0_8
    • OpenSSL-fips-2_0_7
    • OpenSSL-fips-2_0_6
    • OpenSSL-fips-2_0_5
    • OpenSSL-fips-2_0_4
    • OpenSSL-fips-2_0_3
    • OpenSSL-fips-2_0_2
    • OpenSSL-fips-2_0_16
    • OpenSSL-fips-2_0_15
    • OpenSSL-fips-2_0_14
    • OpenSSL-fips-2_0_13
    • OpenSSL-fips-2_0_12
    • OpenSSL-fips-2_0_11
    • OpenSSL-fips-2_0_10
  • 59e02e5
  • /
  • test
  • /
  • property_test.c
Raw File
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
content badge Iframe embedding
swh:1:cnt:18f8cc8740e0d3d2236a33d8579ac9e55a64e0b7
directory badge Iframe embedding
swh:1:dir:20de198b0d9346a12082acdbeebb0b7299d2b27a
revision badge
swh:1:rev:0fdf965bf0b1f87d4a5d52c71994ffdda5235718
snapshot badge
swh:1:snp:dc2a5002442a00b1c0eda7c65d04ea7455e166cd
Tip revision: 0fdf965bf0b1f87d4a5d52c71994ffdda5235718 authored by Neil Horman on 11 September 2024, 13:53:49 UTC
review fixups for quic-hq-interop
Tip revision: 0fdf965
property_test.c
/*
 * Copyright 2019-2023 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
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#include <stdarg.h>
#include <openssl/evp.h>
#include "testutil.h"
#include "internal/nelem.h"
#include "internal/property.h"
#include "../crypto/property/property_local.h"

/*
 * We make our OSSL_PROVIDER for testing purposes.  All we really need is
 * a pointer.  We know that as long as we don't try to use the method
 * cache flush functions, the provider pointer is merely a pointer being
 * passed around, and used as a tag of sorts.
 */
struct ossl_provider_st {
    int x;
};

static int add_property_names(const char *n, ...)
{
    va_list args;
    int res = 1;

    va_start(args, n);
    do {
        if (!TEST_int_ne(ossl_property_name(NULL, n, 1), 0))
            res = 0;
    } while ((n = va_arg(args, const char *)) != NULL);
    va_end(args);
    return res;
}

static int up_ref(void *p)
{
    return 1;
}

static void down_ref(void *p)
{
}

static int test_property_string(void)
{
    OSSL_LIB_CTX *ctx;
    OSSL_METHOD_STORE *store = NULL;
    int res = 0;
    OSSL_PROPERTY_IDX i, j;

    /*-
     * Use our own library context because we depend on ordering from a
     * pristine state.
     */
    if (TEST_ptr(ctx = OSSL_LIB_CTX_new())
        && TEST_ptr(store = ossl_method_store_new(ctx))
        && TEST_int_eq(ossl_property_name(ctx, "fnord", 0), 0)
        && TEST_int_ne(ossl_property_name(ctx, "fnord", 1), 0)
        && TEST_int_ne(ossl_property_name(ctx, "name", 1), 0)
        /* Pre loaded names */
        && TEST_str_eq(ossl_property_name_str(ctx, 1), "provider")
        && TEST_str_eq(ossl_property_name_str(ctx, 2), "version")
        && TEST_str_eq(ossl_property_name_str(ctx, 3), "fips")
        && TEST_str_eq(ossl_property_name_str(ctx, 4), "output")
        && TEST_str_eq(ossl_property_name_str(ctx, 5), "input")
        && TEST_str_eq(ossl_property_name_str(ctx, 6), "structure")
        /* The names we added */
        && TEST_str_eq(ossl_property_name_str(ctx, 7), "fnord")
        && TEST_str_eq(ossl_property_name_str(ctx, 8), "name")
        /* Out of range */
        && TEST_ptr_null(ossl_property_name_str(ctx, 0))
        && TEST_ptr_null(ossl_property_name_str(ctx, 9))
        /* Property value checks */
        && TEST_int_eq(ossl_property_value(ctx, "fnord", 0), 0)
        && TEST_int_ne(i = ossl_property_value(ctx, "no", 0), 0)
        && TEST_int_ne(j = ossl_property_value(ctx, "yes", 0), 0)
        && TEST_int_ne(i, j)
        && TEST_int_eq(ossl_property_value(ctx, "yes", 1), j)
        && TEST_int_eq(ossl_property_value(ctx, "no", 1), i)
        && TEST_int_ne(i = ossl_property_value(ctx, "illuminati", 1), 0)
        && TEST_int_eq(j = ossl_property_value(ctx, "fnord", 1), i + 1)
        && TEST_int_eq(ossl_property_value(ctx, "fnord", 1), j)
        /* Pre loaded values */
        && TEST_str_eq(ossl_property_value_str(ctx, 1), "yes")
        && TEST_str_eq(ossl_property_value_str(ctx, 2), "no")
        /* The value we added */
        && TEST_str_eq(ossl_property_value_str(ctx, 3), "illuminati")
        && TEST_str_eq(ossl_property_value_str(ctx, 4), "fnord")
        /* Out of range */
        && TEST_ptr_null(ossl_property_value_str(ctx, 0))
        && TEST_ptr_null(ossl_property_value_str(ctx, 5))
        /* Check name and values are distinct */
        && TEST_int_eq(ossl_property_value(ctx, "cold", 0), 0)
        && TEST_int_ne(ossl_property_name(ctx, "fnord", 0),
                       ossl_property_value(ctx, "fnord", 0)))
        res = 1;
    ossl_method_store_free(store);
    OSSL_LIB_CTX_free(ctx);
    return res;
}

static const struct {
    const char *defn;
    const char *query;
    int e;
} parser_tests[] = {
    { "", "sky=blue", -1 },
    { "", "sky!=blue", 1 },
    { "groan", "", 0 },
    { "cold=yes", "cold=yes", 1 },
    { "cold=yes", "cold", 1 },
    { "cold=yes", "cold!=no", 1 },
    { "groan", "groan=yes", 1 },
    { "groan", "groan=no", -1 },
    { "groan", "groan!=yes", -1 },
    { "cold=no", "cold", -1 },
    { "cold=no", "?cold", 0 },
    { "cold=no", "cold=no", 1 },
    { "groan", "cold", -1 },
    { "groan", "cold=no", 1 },
    { "groan", "cold!=yes", 1 },
    { "groan=blue", "groan=yellow", -1 },
    { "groan=blue", "?groan=yellow", 0 },
    { "groan=blue", "groan!=yellow", 1 },
    { "groan=blue", "?groan!=yellow", 1 },
    { "today=monday, tomorrow=3", "today!=2", 1 },
    { "today=monday, tomorrow=3", "today!='monday'", -1 },
    { "today=monday, tomorrow=3", "tomorrow=3", 1 },
    { "n=0x3", "n=3", 1 },
    { "n=0x3", "n=-3", -1 },
    { "n=0x33", "n=51", 1 },
    { "n=0x123456789abcdef", "n=0x123456789abcdef", 1 },
    { "n=0x7fffffffffffffff", "n=0x7fffffffffffffff", 1 },   /* INT64_MAX */
    { "n=9223372036854775807", "n=9223372036854775807", 1 }, /* INT64_MAX */
    { "n=0777777777777777777777", "n=0777777777777777777777", 1 }, /* INT64_MAX */
    { "n=033", "n=27", 1 },
    { "n=0", "n=00", 1 },
    { "n=0x0", "n=0", 1 },
    { "n=0, sky=blue", "?n=0, sky=blue", 2 },
    { "n=1, sky=blue", "?n=0, sky=blue", 1 },
};

static int test_property_parse(int n)
{
    OSSL_METHOD_STORE *store;
    OSSL_PROPERTY_LIST *p = NULL, *q = NULL;
    int r = 0;

    if (TEST_ptr(store = ossl_method_store_new(NULL))
        && add_property_names("sky", "groan", "cold", "today", "tomorrow", "n",
                              NULL)
        && TEST_ptr(p = ossl_parse_property(NULL, parser_tests[n].defn))
        && TEST_ptr(q = ossl_parse_query(NULL, parser_tests[n].query, 0))
        && TEST_int_eq(ossl_property_match_count(q, p), parser_tests[n].e))
        r = 1;
    ossl_property_free(p);
    ossl_property_free(q);
    ossl_method_store_free(store);
    return r;
}

static int test_property_query_value_create(void)
{
    OSSL_METHOD_STORE *store;
    OSSL_PROPERTY_LIST *p = NULL, *q = NULL, *o = NULL;
    int r = 0;

    /* The property value used here must not be used in other test cases */
    if (TEST_ptr(store = ossl_method_store_new(NULL))
        && add_property_names("wood", NULL)
        && TEST_ptr(p = ossl_parse_query(NULL, "wood=oak", 0)) /* undefined */
        && TEST_ptr(q = ossl_parse_query(NULL, "wood=oak", 1)) /* creates */
        && TEST_ptr(o = ossl_parse_query(NULL, "wood=oak", 0)) /* defined */
        && TEST_int_eq(ossl_property_match_count(q, p), -1)
        && TEST_int_eq(ossl_property_match_count(q, o), 1))
        r = 1;
    ossl_property_free(o);
    ossl_property_free(p);
    ossl_property_free(q);
    ossl_method_store_free(store);
    return r;
}

static const struct {
    int query;
    const char *ps;
} parse_error_tests[] = {
    { 0, "n=1, n=1" },          /* duplicate name */
    { 0, "n=1, a=hi, n=1" },    /* duplicate name */
    { 1, "n=1, a=bye, ?n=0" },  /* duplicate name */
    { 0, "a=abc,#@!, n=1" },    /* non-ASCII character located */
    { 1, "a='Hello" },          /* Unterminated string */
    { 0, "a=\"World" },         /* Unterminated string */
    { 0, "a=_abd_" },           /* Unquoted string not starting with alphabetic */
    { 1, "a=2, n=012345678" },  /* Bad octal digit */
    { 0, "n=0x28FG, a=3" },     /* Bad hex digit */
    { 0, "n=145d, a=2" },       /* Bad decimal digit */
    { 0, "n=0x8000000000000000, a=3" },     /* Hex overflow */
    { 0, "n=922337203000000000d, a=2" },    /* Decimal overflow */
    { 0, "a=2, n=1000000000000000000000" }, /* Octal overflow */
    { 1, "@='hello'" },         /* Invalid name */
    { 1, "n0123456789012345678901234567890123456789"
         "0123456789012345678901234567890123456789"
         "0123456789012345678901234567890123456789"
         "0123456789012345678901234567890123456789=yes" }, /* Name too long */
    { 0, ".n=3" },              /* Invalid name */
    { 1, "fnord.fnord.=3" }     /* Invalid name */
};

static int test_property_parse_error(int n)
{
    OSSL_METHOD_STORE *store;
    OSSL_PROPERTY_LIST *p = NULL;
    int r = 0;
    const char *ps;

    if (!TEST_ptr(store = ossl_method_store_new(NULL))
        || !add_property_names("a", "n", NULL))
        goto err;
    ps = parse_error_tests[n].ps;
    if (parse_error_tests[n].query) {
        if (!TEST_ptr_null(p = ossl_parse_query(NULL, ps, 1)))
            goto err;
    } else if (!TEST_ptr_null(p = ossl_parse_property(NULL, ps))) {
        goto err;
    }
    r = 1;
 err:
    ossl_property_free(p);
    ossl_method_store_free(store);
    return r;
}

static const struct {
    const char *q_global;
    const char *q_local;
    const char *prop;
} merge_tests[] = {
    { "", "colour=blue", "colour=blue" },
    { "colour=blue", "", "colour=blue" },
    { "colour=red", "colour=blue", "colour=blue" },
    { "clouds=pink, urn=red", "urn=blue, colour=green",
        "urn=blue, colour=green, clouds=pink" },
    { "pot=gold", "urn=blue", "pot=gold, urn=blue" },
    { "night", "day", "day=yes, night=yes" },
    { "day", "night", "day=yes, night=yes" },
    { "", "", "" },
    /*
     * The following four leave 'day' unspecified in the query, and will match
     * any definition
     */
    { "day=yes", "-day", "day=no" },
    { "day=yes", "-day", "day=yes" },
    { "day=yes", "-day", "day=arglebargle" },
    { "day=yes", "-day", "pot=sesquioxidizing" },
    { "day, night", "-night, day", "day=yes, night=no" },
    { "-day", "day=yes", "day=yes" },
};

static int test_property_merge(int n)
{
    OSSL_METHOD_STORE *store;
    OSSL_PROPERTY_LIST *q_global = NULL, *q_local = NULL;
    OSSL_PROPERTY_LIST *q_combined = NULL, *prop = NULL;
    int r = 0;

    if (TEST_ptr(store = ossl_method_store_new(NULL))
        && add_property_names("colour", "urn", "clouds", "pot", "day", "night",
                              NULL)
        && TEST_ptr(prop = ossl_parse_property(NULL, merge_tests[n].prop))
        && TEST_ptr(q_global = ossl_parse_query(NULL, merge_tests[n].q_global,
                                                0))
        && TEST_ptr(q_local = ossl_parse_query(NULL, merge_tests[n].q_local, 0))
        && TEST_ptr(q_combined = ossl_property_merge(q_local, q_global))
        && TEST_int_ge(ossl_property_match_count(q_combined, prop), 0))
        r = 1;
    ossl_property_free(q_global);
    ossl_property_free(q_local);
    ossl_property_free(q_combined);
    ossl_property_free(prop);
    ossl_method_store_free(store);
    return r;
}

static int test_property_defn_cache(void)
{
    OSSL_METHOD_STORE *store;
    OSSL_PROPERTY_LIST *red = NULL, *blue = NULL, *blue2 = NULL;
    int r;

    r = TEST_ptr(store = ossl_method_store_new(NULL))
        && add_property_names("red", "blue", NULL)
        && TEST_ptr(red = ossl_parse_property(NULL, "red"))
        && TEST_ptr(blue = ossl_parse_property(NULL, "blue"))
        && TEST_ptr_ne(red, blue)
        && TEST_true(ossl_prop_defn_set(NULL, "red", &red));

    if (!r)  {
        ossl_property_free(red);
        red = NULL;
        ossl_property_free(blue);
        blue = NULL;
    }

    r = r && TEST_true(ossl_prop_defn_set(NULL, "blue", &blue));
    if (!r) {
        ossl_property_free(blue);
        blue = NULL;
    }

    r = r && TEST_ptr_eq(ossl_prop_defn_get(NULL, "red"), red)
        && TEST_ptr_eq(ossl_prop_defn_get(NULL, "blue"), blue)
        && TEST_ptr(blue2 = ossl_parse_property(NULL, "blue"))
        && TEST_ptr_ne(blue2, blue)
        && TEST_true(ossl_prop_defn_set(NULL, "blue", &blue2));
    if (!r) {
        ossl_property_free(blue2);
        blue2 = NULL;
    }

    r = r && TEST_ptr_eq(blue2, blue)
        && TEST_ptr_eq(ossl_prop_defn_get(NULL, "blue"), blue);

    ossl_method_store_free(store);
    return r;
}

static const struct {
    const char *defn;
    const char *query;
    int e;
} definition_tests[] = {
    { "alpha", "alpha=yes", 1 },
    { "alpha=no", "alpha", -1 },
    { "alpha=1", "alpha=1", 1 },
    { "alpha=2", "alpha=1",-1 },
    { "alpha", "omega", -1 },
    { "alpha", "?omega", 0 },
    { "alpha", "?omega=1", 0 },
    { "alpha", "?omega=no", 1 },
    { "alpha", "?omega=yes", 0 },
    { "alpha, omega", "?omega=yes", 1 },
    { "alpha, omega", "?omega=no", 0 }
};

static int test_definition_compares(int n)
{
    OSSL_METHOD_STORE *store;
    OSSL_PROPERTY_LIST *d = NULL, *q = NULL;
    int r;

    r = TEST_ptr(store = ossl_method_store_new(NULL))
        && add_property_names("alpha", "omega", NULL)
        && TEST_ptr(d = ossl_parse_property(NULL, definition_tests[n].defn))
        && TEST_ptr(q = ossl_parse_query(NULL, definition_tests[n].query, 0))
        && TEST_int_eq(ossl_property_match_count(q, d), definition_tests[n].e);

    ossl_property_free(d);
    ossl_property_free(q);
    ossl_method_store_free(store);
    return r;
}

static int test_register_deregister(void)
{
    static const struct {
        int nid;
        const char *prop;
        char *impl;
    } impls[] = {
        { 6, "position=1", "a" },
        { 6, "position=2", "b" },
        { 6, "position=3", "c" },
        { 6, "position=4", "d" },
    };
    size_t i;
    int ret = 0;
    OSSL_METHOD_STORE *store;
    OSSL_PROVIDER prov = { 1 };

    if (!TEST_ptr(store = ossl_method_store_new(NULL))
        || !add_property_names("position", NULL))
        goto err;

    for (i = 0; i < OSSL_NELEM(impls); i++)
        if (!TEST_true(ossl_method_store_add(store, &prov, impls[i].nid,
                                             impls[i].prop, impls[i].impl,
                                             &up_ref, &down_ref))) {
            TEST_note("iteration %zd", i + 1);
            goto err;
        }

    /* Deregister in a different order to registration */
    for (i = 0; i < OSSL_NELEM(impls); i++) {
        const size_t j = (1 + i * 3) % OSSL_NELEM(impls);
        int nid = impls[j].nid;
        void *impl = impls[j].impl;

        if (!TEST_true(ossl_method_store_remove(store, nid, impl))
            || !TEST_false(ossl_method_store_remove(store, nid, impl))) {
            TEST_note("iteration %zd, position %zd", i + 1, j + 1);
            goto err;
        }
    }

    if (TEST_false(ossl_method_store_remove(store, impls[0].nid, impls[0].impl)))
        ret = 1;
err:
    ossl_method_store_free(store);
    return ret;
}

static int test_property(void)
{
    static OSSL_PROVIDER fake_provider1 = { 1 };
    static OSSL_PROVIDER fake_provider2 = { 2 };
    static const OSSL_PROVIDER *fake_prov1 = &fake_provider1;
    static const OSSL_PROVIDER *fake_prov2 = &fake_provider2;
    static const struct {
        const OSSL_PROVIDER **prov;
        int nid;
        const char *prop;
        char *impl;
    } impls[] = {
        { &fake_prov1, 1, "fast=no, colour=green", "a" },
        { &fake_prov1, 1, "fast, colour=blue", "b" },
        { &fake_prov1, 1, "", "-" },
        { &fake_prov2, 9, "sky=blue, furry", "c" },
        { &fake_prov2, 3, NULL, "d" },
        { &fake_prov2, 6, "sky.colour=blue, sky=green, old.data", "e" },
    };
    static struct {
        const OSSL_PROVIDER **prov;
        int nid;
        const char *prop;
        char *expected;
    } queries[] = {
        { &fake_prov1, 1, "fast", "b" },
        { &fake_prov1, 1, "fast=yes", "b" },
        { &fake_prov1, 1, "fast=no, colour=green", "a" },
        { &fake_prov1, 1, "colour=blue, fast", "b" },
        { &fake_prov1, 1, "colour=blue", "b" },
        { &fake_prov2, 9, "furry", "c" },
        { &fake_prov2, 6, "sky.colour=blue", "e" },
        { &fake_prov2, 6, "old.data", "e" },
        { &fake_prov2, 9, "furry=yes, sky=blue", "c" },
        { &fake_prov1, 1, "", "a" },
        { &fake_prov2, 3, "", "d" },
    };
    OSSL_METHOD_STORE *store;
    size_t i;
    int ret = 0;
    void *result;

    if (!TEST_ptr(store = ossl_method_store_new(NULL))
        || !add_property_names("fast", "colour", "sky", "furry", NULL))
        goto err;

    for (i = 0; i < OSSL_NELEM(impls); i++)
        if (!TEST_true(ossl_method_store_add(store, *impls[i].prov,
                                             impls[i].nid, impls[i].prop,
                                             impls[i].impl,
                                             &up_ref, &down_ref))) {
            TEST_note("iteration %zd", i + 1);
            goto err;
        }
    /*
     * The first check of queries is with NULL given as provider.  All
     * queries are expected to succeed.
     */
    for (i = 0; i < OSSL_NELEM(queries); i++) {
        const OSSL_PROVIDER *nullprov = NULL;
        OSSL_PROPERTY_LIST *pq = NULL;

        if (!TEST_true(ossl_method_store_fetch(store,
                                               queries[i].nid, queries[i].prop,
                                               &nullprov, &result))
            || !TEST_str_eq((char *)result, queries[i].expected)) {
            TEST_note("iteration %zd", i + 1);
            ossl_property_free(pq);
            goto err;
        }
        ossl_property_free(pq);
    }
    /*
     * The second check of queries is with &address1 given as provider.
     */
    for (i = 0; i < OSSL_NELEM(queries); i++) {
        OSSL_PROPERTY_LIST *pq = NULL;

        result = NULL;
        if (queries[i].prov == &fake_prov1) {
            if (!TEST_true(ossl_method_store_fetch(store,
                                                   queries[i].nid,
                                                   queries[i].prop,
                                                   &fake_prov1, &result))
                || !TEST_ptr_eq(fake_prov1, &fake_provider1)
                || !TEST_str_eq((char *)result, queries[i].expected)) {
                TEST_note("iteration %zd", i + 1);
                ossl_property_free(pq);
                goto err;
            }
        } else {
            if (!TEST_false(ossl_method_store_fetch(store,
                                                    queries[i].nid,
                                                    queries[i].prop,
                                                    &fake_prov1, &result))
                || !TEST_ptr_eq(fake_prov1, &fake_provider1)
                || !TEST_ptr_null(result)) {
                TEST_note("iteration %zd", i + 1);
                ossl_property_free(pq);
                goto err;
            }
        }
        ossl_property_free(pq);
    }
    /*
     * The third check of queries is with &address2 given as provider.
     */
    for (i = 0; i < OSSL_NELEM(queries); i++) {
        OSSL_PROPERTY_LIST *pq = NULL;

        result = NULL;
        if (queries[i].prov == &fake_prov2) {
            if (!TEST_true(ossl_method_store_fetch(store,
                                                   queries[i].nid,
                                                   queries[i].prop,
                                                   &fake_prov2, &result))
                || !TEST_ptr_eq(fake_prov2, &fake_provider2)
                || !TEST_str_eq((char *)result, queries[i].expected)) {
                TEST_note("iteration %zd", i + 1);
                ossl_property_free(pq);
                goto err;
            }
        } else {
            if (!TEST_false(ossl_method_store_fetch(store,
                                                    queries[i].nid,
                                                    queries[i].prop,
                                                    &fake_prov2, &result))
                || !TEST_ptr_eq(fake_prov2, &fake_provider2)
                || !TEST_ptr_null(result)) {
                TEST_note("iteration %zd", i + 1);
                ossl_property_free(pq);
                goto err;
            }
        }
        ossl_property_free(pq);
    }
    ret = 1;
err:
    ossl_method_store_free(store);
    return ret;
}

static int test_query_cache_stochastic(void)
{
    const int max = 10000, tail = 10;
    OSSL_METHOD_STORE *store;
    int i, res = 0;
    char buf[50];
    void *result;
    int errors = 0;
    int v[10001];
    OSSL_PROVIDER prov = { 1 };

    if (!TEST_ptr(store = ossl_method_store_new(NULL))
        || !add_property_names("n", NULL))
        goto err;

    for (i = 1; i <= max; i++) {
        v[i] = 2 * i;
        BIO_snprintf(buf, sizeof(buf), "n=%d\n", i);
        if (!TEST_true(ossl_method_store_add(store, &prov, i, buf, "abc",
                                             &up_ref, &down_ref))
                || !TEST_true(ossl_method_store_cache_set(store, &prov, i,
                                                          buf, v + i,
                                                          &up_ref, &down_ref))
                || !TEST_true(ossl_method_store_cache_set(store, &prov, i,
                                                          "n=1234", "miss",
                                                          &up_ref, &down_ref))) {
            TEST_note("iteration %d", i);
            goto err;
        }
    }
    for (i = 1; i <= max; i++) {
        BIO_snprintf(buf, sizeof(buf), "n=%d\n", i);
        if (!ossl_method_store_cache_get(store, NULL, i, buf, &result)
            || result != v + i)
            errors++;
    }
    /* There is a tiny probability that this will fail when it shouldn't */
    res = TEST_int_gt(errors, tail) && TEST_int_lt(errors, max - tail);

err:
    ossl_method_store_free(store);
    return res;
}

static int test_fips_mode(void)
{
    int ret = 0;
    OSSL_LIB_CTX *ctx = NULL;

    if (!TEST_ptr(ctx = OSSL_LIB_CTX_new()))
        goto err;

    ret = TEST_true(EVP_set_default_properties(ctx, "default=yes,fips=yes"))
          && TEST_true(EVP_default_properties_is_fips_enabled(ctx))
          && TEST_true(EVP_set_default_properties(ctx, "fips=no,default=yes"))
          && TEST_false(EVP_default_properties_is_fips_enabled(ctx))
          && TEST_true(EVP_set_default_properties(ctx, "fips=no"))
          && TEST_false(EVP_default_properties_is_fips_enabled(ctx))
          && TEST_true(EVP_set_default_properties(ctx, "fips!=no"))
          && TEST_true(EVP_default_properties_is_fips_enabled(ctx))
          && TEST_true(EVP_set_default_properties(ctx, "fips=no"))
          && TEST_false(EVP_default_properties_is_fips_enabled(ctx))
          && TEST_true(EVP_set_default_properties(ctx, "fips=no,default=yes"))
          && TEST_true(EVP_default_properties_enable_fips(ctx, 1))
          && TEST_true(EVP_default_properties_is_fips_enabled(ctx))
          && TEST_true(EVP_default_properties_enable_fips(ctx, 0))
          && TEST_false(EVP_default_properties_is_fips_enabled(ctx));
err:
    OSSL_LIB_CTX_free(ctx);
    return ret;
}

static struct {
    const char *in;
    const char *out;
} to_string_tests[] = {
    { "fips=yes", "fips=yes" },
    { "fips!=yes", "fips!=yes" },
    { "fips = yes", "fips=yes" },
    { "fips", "fips=yes" },
    { "fips=no", "fips=no" },
    { "-fips", "-fips" },
    { "?fips=yes", "?fips=yes" },
    { "fips=yes,provider=fips", "fips=yes,provider=fips" },
    { "fips = yes , provider = fips", "fips=yes,provider=fips" },
    { "fips=yes,provider!=fips", "fips=yes,provider!=fips" },
    { "fips=yes,?provider=fips", "fips=yes,?provider=fips" },
    { "fips=yes,-provider", "fips=yes,-provider" },
      /* foo is an unknown internal name */
    { "foo=yes,fips=yes", "fips=yes"},
    { "", "" },
    { "fips=3", "fips=3" },
    { "fips=-3", "fips=-3" },
    { "provider='foo bar'", "provider='foo bar'" },
    { "provider=\"foo bar'\"", "provider=\"foo bar'\"" },
    { "provider=abc***", "provider='abc***'" },
    { NULL, "" }
};

static int test_property_list_to_string(int i)
{
    OSSL_PROPERTY_LIST *pl = NULL;
    int ret = 0;
    size_t bufsize;
    char *buf = NULL;

    if (to_string_tests[i].in != NULL
            && !TEST_ptr(pl = ossl_parse_query(NULL, to_string_tests[i].in, 1)))
        goto err;
    bufsize = ossl_property_list_to_string(NULL, pl, NULL, 0);
    if (!TEST_size_t_gt(bufsize, 0))
        goto err;
    buf = OPENSSL_malloc(bufsize);
    if (!TEST_ptr(buf)
            || !TEST_size_t_eq(ossl_property_list_to_string(NULL, pl, buf,
                                                            bufsize),
                               bufsize)
            || !TEST_str_eq(to_string_tests[i].out, buf)
            || !TEST_size_t_eq(bufsize, strlen(to_string_tests[i].out) + 1))
        goto err;

    ret = 1;
 err:
    OPENSSL_free(buf);
    ossl_property_free(pl);
    return ret;
}

int setup_tests(void)
{
    ADD_TEST(test_property_string);
    ADD_TEST(test_property_query_value_create);
    ADD_ALL_TESTS(test_property_parse, OSSL_NELEM(parser_tests));
    ADD_ALL_TESTS(test_property_parse_error, OSSL_NELEM(parse_error_tests));
    ADD_ALL_TESTS(test_property_merge, OSSL_NELEM(merge_tests));
    ADD_TEST(test_property_defn_cache);
    ADD_ALL_TESTS(test_definition_compares, OSSL_NELEM(definition_tests));
    ADD_TEST(test_register_deregister);
    ADD_TEST(test_property);
    ADD_TEST(test_query_cache_stochastic);
    ADD_TEST(test_fips_mode);
    ADD_ALL_TESTS(test_property_list_to_string, OSSL_NELEM(to_string_tests));
    return 1;
}

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top