Latest update, add TLS 1.3 session time configuration.
This commit is contained in:
+10
-4
@@ -186,6 +186,9 @@ IF[{- !$disabled{tests} -}]
|
||||
SOURCE[evp_extra_test]=evp_extra_test.c
|
||||
INCLUDE[evp_extra_test]=../include ../apps/include ../crypto/include
|
||||
DEPEND[evp_extra_test]=../libcrypto libtestutil.a
|
||||
IF[{- $disabled{fips} || !$target{dso_scheme} -}]
|
||||
DEFINE[evp_extra_test]=NO_FIPS_MODULE
|
||||
ENDIF
|
||||
|
||||
SOURCE[igetest]=igetest.c
|
||||
INCLUDE[igetest]=../include ../apps/include
|
||||
@@ -603,7 +606,7 @@ IF[{- !$disabled{tests} -}]
|
||||
SOURCE[provider_test]=provider_test.c p_test.c
|
||||
INCLUDE[provider_test]=../include ../apps/include
|
||||
DEPEND[provider_test]=../libcrypto.a libtestutil.a
|
||||
IF[{- !$disabled{shared} -}]
|
||||
IF[{- !$disabled{module} -}]
|
||||
MODULES{noinst}=p_test
|
||||
SOURCE[p_test]=p_test.c
|
||||
INCLUDE[p_test]=../include
|
||||
@@ -611,10 +614,13 @@ IF[{- !$disabled{tests} -}]
|
||||
SOURCE[p_test]=p_test.ld
|
||||
GENERATE[p_test.ld]=../util/providers.num
|
||||
ENDIF
|
||||
ELSE
|
||||
DEFINE[provider_test]=OPENSSL_NO_SHARED
|
||||
DEFINE[provider_internal_test]=OPENSSL_NO_SHARED
|
||||
ENDIF
|
||||
IF[{- $disabled{module} || !$target{dso_scheme} -}]
|
||||
DEFINE[provider_test]=NO_PROVIDER_MODULE
|
||||
DEFINE[provider_internal_test]=NO_PROVIDER_MODULE
|
||||
ENDIF
|
||||
DEPEND[]=provider_internal_test.conf
|
||||
GENERATE[provider_internal_test.conf]=provider_internal_test.conf.in
|
||||
|
||||
PROGRAMS{noinst}=params_test
|
||||
SOURCE[params_test]=params_test.c
|
||||
|
||||
@@ -254,6 +254,11 @@ static int test_cavs_kats(const struct drbg_kat *test[], int i)
|
||||
const struct drbg_kat *td = test[i];
|
||||
int rv = 0;
|
||||
|
||||
#ifdef FIPS_MODE
|
||||
/* FIPS mode doesn't support instantiating without a derivation function */
|
||||
if ((td->flags & USE_DF) == 0)
|
||||
return 1;
|
||||
#endif
|
||||
switch (td->type) {
|
||||
case NO_RESEED:
|
||||
if (!single_kat_no_reseed(td))
|
||||
|
||||
+85
-2
@@ -104,9 +104,12 @@ typedef struct drbg_selftest_data_st {
|
||||
make_drbg_test_data(nid, 0, pr, p)
|
||||
|
||||
static DRBG_SELFTEST_DATA drbg_test[] = {
|
||||
#ifndef FIPS_MODE
|
||||
/* FIPS mode doesn't support CTR DRBG without a derivation function */
|
||||
make_drbg_test_data_no_df (NID_aes_128_ctr, aes_128_no_df, 0),
|
||||
make_drbg_test_data_no_df (NID_aes_192_ctr, aes_192_no_df, 0),
|
||||
make_drbg_test_data_no_df (NID_aes_256_ctr, aes_256_no_df, 1),
|
||||
#endif
|
||||
make_drbg_test_data_use_df(NID_aes_128_ctr, aes_128_use_df, 0),
|
||||
make_drbg_test_data_use_df(NID_aes_192_ctr, aes_192_use_df, 0),
|
||||
make_drbg_test_data_use_df(NID_aes_256_ctr, aes_256_use_df, 1),
|
||||
@@ -1009,6 +1012,83 @@ static int test_rand_add(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int test_rand_drbg_prediction_resistance(void)
|
||||
{
|
||||
RAND_DRBG *m = NULL, *i = NULL, *s = NULL;
|
||||
unsigned char buf1[51], buf2[sizeof(buf1)];
|
||||
int ret = 0, mreseed, ireseed, sreseed;
|
||||
|
||||
/* Initialise a three long DRBG chain */
|
||||
if (!TEST_ptr(m = RAND_DRBG_new(0, 0, NULL))
|
||||
|| !TEST_true(disable_crngt(m))
|
||||
|| !TEST_true(RAND_DRBG_instantiate(m, NULL, 0))
|
||||
|| !TEST_ptr(i = RAND_DRBG_new(0, 0, m))
|
||||
|| !TEST_true(RAND_DRBG_instantiate(i, NULL, 0))
|
||||
|| !TEST_ptr(s = RAND_DRBG_new(0, 0, i))
|
||||
|| !TEST_true(RAND_DRBG_instantiate(s, NULL, 0)))
|
||||
goto err;
|
||||
|
||||
/* During a normal reseed, only the slave DRBG should be reseed */
|
||||
mreseed = ++m->reseed_prop_counter;
|
||||
ireseed = ++i->reseed_prop_counter;
|
||||
sreseed = s->reseed_prop_counter;
|
||||
if (!TEST_true(RAND_DRBG_reseed(s, NULL, 0, 0))
|
||||
|| !TEST_int_eq(m->reseed_prop_counter, mreseed)
|
||||
|| !TEST_int_eq(i->reseed_prop_counter, ireseed)
|
||||
|| !TEST_int_gt(s->reseed_prop_counter, sreseed))
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* When prediction resistance is requested, the request should be
|
||||
* propagated to the master, so that the entire DRBG chain reseeds.
|
||||
*/
|
||||
sreseed = s->reseed_prop_counter;
|
||||
if (!TEST_true(RAND_DRBG_reseed(s, NULL, 0, 1))
|
||||
|| !TEST_int_gt(m->reseed_prop_counter, mreseed)
|
||||
|| !TEST_int_gt(i->reseed_prop_counter, ireseed)
|
||||
|| !TEST_int_gt(s->reseed_prop_counter, sreseed))
|
||||
goto err;
|
||||
|
||||
/* During a normal generate, only the slave DRBG should be reseed */
|
||||
mreseed = ++m->reseed_prop_counter;
|
||||
ireseed = ++i->reseed_prop_counter;
|
||||
sreseed = s->reseed_prop_counter;
|
||||
if (!TEST_true(RAND_DRBG_generate(s, buf1, sizeof(buf1), 0, NULL, 0))
|
||||
|| !TEST_int_eq(m->reseed_prop_counter, mreseed)
|
||||
|| !TEST_int_eq(i->reseed_prop_counter, ireseed)
|
||||
|| !TEST_int_gt(s->reseed_prop_counter, sreseed))
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* When a prediction resistant generate is requested, the request
|
||||
* should be propagated to the master, reseeding the entire DRBG chain.
|
||||
*/
|
||||
sreseed = s->reseed_prop_counter;
|
||||
if (!TEST_true(RAND_DRBG_generate(s, buf2, sizeof(buf2), 1, NULL, 0))
|
||||
|| !TEST_int_gt(m->reseed_prop_counter, mreseed)
|
||||
|| !TEST_int_gt(i->reseed_prop_counter, ireseed)
|
||||
|| !TEST_int_gt(s->reseed_prop_counter, sreseed)
|
||||
|| !TEST_mem_ne(buf1, sizeof(buf1), buf2, sizeof(buf2)))
|
||||
goto err;
|
||||
|
||||
/* Verify that a normal reseed still only reseeds the slave DRBG */
|
||||
mreseed = ++m->reseed_prop_counter;
|
||||
ireseed = ++i->reseed_prop_counter;
|
||||
sreseed = s->reseed_prop_counter;
|
||||
if (!TEST_true(RAND_DRBG_reseed(s, NULL, 0, 0))
|
||||
|| !TEST_int_eq(m->reseed_prop_counter, mreseed)
|
||||
|| !TEST_int_eq(i->reseed_prop_counter, ireseed)
|
||||
|| !TEST_int_gt(s->reseed_prop_counter, sreseed))
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
RAND_DRBG_free(s);
|
||||
RAND_DRBG_free(i);
|
||||
RAND_DRBG_free(m);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int test_multi_set(void)
|
||||
{
|
||||
int rv = 0;
|
||||
@@ -1107,14 +1187,16 @@ static int test_set_defaults(void)
|
||||
&& TEST_int_eq(public->type, NID_sha256)
|
||||
&& TEST_int_eq(public->flags, RAND_DRBG_FLAG_PUBLIC)
|
||||
|
||||
/* Change DRBG defaults and change master and check again */
|
||||
/* FIPS mode doesn't support CTR DRBG without a derivation function */
|
||||
#ifndef FIPS_MODE
|
||||
/* Change DRBG defaults and change master and check again */
|
||||
&& TEST_true(RAND_DRBG_set_defaults(NID_aes_256_ctr,
|
||||
RAND_DRBG_FLAG_CTR_NO_DF))
|
||||
&& TEST_true(RAND_DRBG_uninstantiate(master))
|
||||
&& TEST_int_eq(master->type, NID_aes_256_ctr)
|
||||
&& TEST_int_eq(master->flags,
|
||||
RAND_DRBG_FLAG_MASTER|RAND_DRBG_FLAG_CTR_NO_DF)
|
||||
|
||||
#endif
|
||||
/* Reset back to the standard defaults */
|
||||
&& TEST_true(RAND_DRBG_set_defaults(RAND_DRBG_TYPE,
|
||||
RAND_DRBG_FLAGS
|
||||
@@ -1247,6 +1329,7 @@ int setup_tests(void)
|
||||
ADD_TEST(test_rand_drbg_reseed);
|
||||
ADD_TEST(test_rand_seed);
|
||||
ADD_TEST(test_rand_add);
|
||||
ADD_TEST(test_rand_drbg_prediction_resistance);
|
||||
ADD_TEST(test_multi_set);
|
||||
ADD_TEST(test_set_defaults);
|
||||
#if defined(OPENSSL_THREADS)
|
||||
|
||||
+314
-2
@@ -8,6 +8,7 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "internal/nelem.h"
|
||||
#include "testutil.h"
|
||||
|
||||
@@ -1556,6 +1557,262 @@ static const unsigned char p521_explicit[] = {
|
||||
0xbb, 0x6f, 0xb7, 0x1e, 0x91, 0x38, 0x64, 0x09, 0x02, 0x01, 0x01,
|
||||
};
|
||||
|
||||
/*
|
||||
* This test validates a named curve's group parameters using
|
||||
* EC_GROUP_check_named_curve(). It also checks that modifying any of the
|
||||
* group parameters results in the curve not being valid.
|
||||
*/
|
||||
static int check_named_curve_test(int id)
|
||||
{
|
||||
int ret = 0, nid, field_nid, has_seed;
|
||||
EC_GROUP *group = NULL, *gtest = NULL;
|
||||
const EC_POINT *group_gen = NULL;
|
||||
EC_POINT *other_gen = NULL;
|
||||
BIGNUM *group_p = NULL, *group_a = NULL, *group_b = NULL;
|
||||
BIGNUM *other_p = NULL, *other_a = NULL, *other_b = NULL;
|
||||
BIGNUM *group_cofactor = NULL, *other_cofactor = NULL;
|
||||
BIGNUM *other_order = NULL;
|
||||
const BIGNUM *group_order = NULL;
|
||||
BN_CTX *bn_ctx = NULL;
|
||||
static const unsigned char invalid_seed[] = "THIS IS NOT A VALID SEED";
|
||||
static size_t invalid_seed_len = sizeof(invalid_seed);
|
||||
|
||||
/* Do some setup */
|
||||
nid = curves[id].nid;
|
||||
if (!TEST_ptr(bn_ctx = BN_CTX_new())
|
||||
|| !TEST_ptr(group = EC_GROUP_new_by_curve_name(nid))
|
||||
|| !TEST_ptr(gtest = EC_GROUP_dup(group))
|
||||
|| !TEST_ptr(group_p = BN_new())
|
||||
|| !TEST_ptr(group_a = BN_new())
|
||||
|| !TEST_ptr(group_b = BN_new())
|
||||
|| !TEST_ptr(group_cofactor = BN_new())
|
||||
|| !TEST_ptr(group_gen = EC_GROUP_get0_generator(group))
|
||||
|| !TEST_ptr(group_order = EC_GROUP_get0_order(group))
|
||||
|| !TEST_true(EC_GROUP_get_cofactor(group, group_cofactor, NULL))
|
||||
|| !TEST_true(EC_GROUP_get_curve(group, group_p, group_a, group_b, NULL))
|
||||
|| !TEST_ptr(other_gen = EC_POINT_dup(group_gen, group))
|
||||
|| !TEST_true(EC_POINT_add(group, other_gen, group_gen, group_gen, NULL))
|
||||
|| !TEST_ptr(other_order = BN_dup(group_order))
|
||||
|| !TEST_true(BN_add_word(other_order, 1))
|
||||
|| !TEST_ptr(other_a = BN_dup(group_a))
|
||||
|| !TEST_true(BN_add_word(other_a, 1))
|
||||
|| !TEST_ptr(other_b = BN_dup(group_b))
|
||||
|| !TEST_true(BN_add_word(other_b, 1))
|
||||
|| !TEST_ptr(other_cofactor = BN_dup(group_cofactor))
|
||||
|| !TEST_true(BN_add_word(other_cofactor, 1)))
|
||||
goto err;
|
||||
|
||||
/* Determine if the built-in curve has a seed field set */
|
||||
has_seed = (EC_GROUP_get_seed_len(group) > 0);
|
||||
field_nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group));
|
||||
if (field_nid == NID_X9_62_characteristic_two_field) {
|
||||
if (!TEST_ptr(other_p = BN_dup(group_p))
|
||||
|| !TEST_true(BN_lshift1(other_p, other_p)))
|
||||
goto err;
|
||||
} else {
|
||||
if (!TEST_ptr(other_p = BN_dup(group_p)))
|
||||
goto err;
|
||||
/*
|
||||
* Just choosing any arbitrary prime does not work..
|
||||
* Setting p via ec_GFp_nist_group_set_curve() needs the prime to be a
|
||||
* nist prime. So only select one of these as an alternate prime.
|
||||
*/
|
||||
if (!TEST_ptr(BN_copy(other_p,
|
||||
BN_ucmp(BN_get0_nist_prime_192(), other_p) == 0 ?
|
||||
BN_get0_nist_prime_256() :
|
||||
BN_get0_nist_prime_192())))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Passes because this is a valid curve */
|
||||
if (!TEST_int_eq(EC_GROUP_check_named_curve(group, 0), nid)
|
||||
/* Only NIST curves pass */
|
||||
|| !TEST_int_eq(EC_GROUP_check_named_curve(group, 1),
|
||||
EC_curve_nid2nist(nid) != NULL ? nid : NID_undef))
|
||||
goto err;
|
||||
|
||||
/* Fail if the curve name doesn't match the parameters */
|
||||
EC_GROUP_set_curve_name(group, nid + 1);
|
||||
ERR_set_mark();
|
||||
if (!TEST_int_le(EC_GROUP_check_named_curve(group, 0), 0))
|
||||
goto err;
|
||||
ERR_pop_to_mark();
|
||||
|
||||
/* Restore curve name and ensure it's passing */
|
||||
EC_GROUP_set_curve_name(group, nid);
|
||||
if (!TEST_int_eq(EC_GROUP_check_named_curve(group, 0), nid))
|
||||
goto err;
|
||||
|
||||
if (!TEST_int_eq(EC_GROUP_set_seed(group, invalid_seed, invalid_seed_len),
|
||||
invalid_seed_len))
|
||||
goto err;
|
||||
|
||||
if (has_seed) {
|
||||
/*
|
||||
* If the built-in curve has a seed and we set the seed to another value
|
||||
* then it will fail the check.
|
||||
*/
|
||||
if (!TEST_int_eq(EC_GROUP_check_named_curve(group, 0), 0))
|
||||
goto err;
|
||||
} else {
|
||||
/*
|
||||
* If the built-in curve does not have a seed then setting the seed will
|
||||
* pass the check (as the seed is optional).
|
||||
*/
|
||||
if (!TEST_int_eq(EC_GROUP_check_named_curve(group, 0), nid))
|
||||
goto err;
|
||||
}
|
||||
/* Pass if the seed is unknown (as it is optional) */
|
||||
if (!TEST_int_eq(EC_GROUP_set_seed(group, NULL, 0), 1)
|
||||
|| !TEST_int_eq(EC_GROUP_check_named_curve(group, 0), nid))
|
||||
goto err;
|
||||
|
||||
/* Check that a duped group passes */
|
||||
if (!TEST_int_eq(EC_GROUP_check_named_curve(gtest, 0), nid))
|
||||
goto err;
|
||||
|
||||
/* check that changing any generator parameter fails */
|
||||
if (!TEST_true(EC_GROUP_set_generator(gtest, other_gen, group_order,
|
||||
group_cofactor))
|
||||
|| !TEST_int_eq(EC_GROUP_check_named_curve(gtest, 0), 0)
|
||||
|| !TEST_true(EC_GROUP_set_generator(gtest, group_gen, other_order,
|
||||
group_cofactor))
|
||||
|| !TEST_int_eq(EC_GROUP_check_named_curve(gtest, 0), 0)
|
||||
/* The order is not an optional field, so this should fail */
|
||||
|| !TEST_true(EC_GROUP_set_generator(gtest, group_gen, NULL,
|
||||
group_cofactor))
|
||||
|| !TEST_int_le(EC_GROUP_check_named_curve(gtest, 0), 0)
|
||||
|| !TEST_true(EC_GROUP_set_generator(gtest, group_gen, group_order,
|
||||
other_cofactor))
|
||||
|| !TEST_int_eq(EC_GROUP_check_named_curve(gtest, 0), 0)
|
||||
/* Check that if the cofactor is not set then it still passes */
|
||||
|| !TEST_true(EC_GROUP_set_generator(gtest, group_gen, group_order,
|
||||
NULL))
|
||||
|| !TEST_int_eq(EC_GROUP_check_named_curve(gtest, 0), nid)
|
||||
/* check that restoring the generator passes */
|
||||
|| !TEST_true(EC_GROUP_set_generator(gtest, group_gen, group_order,
|
||||
group_cofactor))
|
||||
|| !TEST_int_eq(EC_GROUP_check_named_curve(gtest, 0), nid))
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* check that changing any curve parameter fails
|
||||
*
|
||||
* Setting arbitrary p, a or b might fail for some EC_GROUPs
|
||||
* depending on the internal EC_METHOD implementation, hence run
|
||||
* these tests conditionally to the success of EC_GROUP_set_curve().
|
||||
*/
|
||||
ERR_set_mark();
|
||||
if (EC_GROUP_set_curve(gtest, other_p, group_a, group_b, NULL)) {
|
||||
if (!TEST_int_le(EC_GROUP_check_named_curve(gtest, 0), 0))
|
||||
goto err;
|
||||
} else {
|
||||
/* clear the error stack if EC_GROUP_set_curve() failed */
|
||||
ERR_pop_to_mark();
|
||||
ERR_set_mark();
|
||||
}
|
||||
if (EC_GROUP_set_curve(gtest, group_p, other_a, group_b, NULL)) {
|
||||
if (!TEST_int_le(EC_GROUP_check_named_curve(gtest, 0), 0))
|
||||
goto err;
|
||||
} else {
|
||||
/* clear the error stack if EC_GROUP_set_curve() failed */
|
||||
ERR_pop_to_mark();
|
||||
ERR_set_mark();
|
||||
}
|
||||
if (EC_GROUP_set_curve(gtest, group_p, group_a, other_b, NULL)) {
|
||||
if (!TEST_int_le(EC_GROUP_check_named_curve(gtest, 0), 0))
|
||||
goto err;
|
||||
} else {
|
||||
/* clear the error stack if EC_GROUP_set_curve() failed */
|
||||
ERR_pop_to_mark();
|
||||
ERR_set_mark();
|
||||
}
|
||||
ERR_pop_to_mark();
|
||||
|
||||
/* Check that restoring the curve parameters passes */
|
||||
if (!TEST_true(EC_GROUP_set_curve(gtest, group_p, group_a, group_b, NULL))
|
||||
|| !TEST_int_eq(EC_GROUP_check_named_curve(gtest, 0), nid))
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
BN_free(group_p);
|
||||
BN_free(other_p);
|
||||
BN_free(group_a);
|
||||
BN_free(other_a);
|
||||
BN_free(group_b);
|
||||
BN_free(other_b);
|
||||
BN_free(group_cofactor);
|
||||
BN_free(other_cofactor);
|
||||
BN_free(other_order);
|
||||
EC_POINT_free(other_gen);
|
||||
EC_GROUP_free(gtest);
|
||||
EC_GROUP_free(group);
|
||||
BN_CTX_free(bn_ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This checks the lookup capability of EC_GROUP_check_named_curve()
|
||||
* when the given group was created with explicit parameters.
|
||||
*
|
||||
* It is possible to retrieve an alternative alias that does not match
|
||||
* the original nid in this case.
|
||||
*/
|
||||
static int check_named_curve_lookup_test(int id)
|
||||
{
|
||||
int ret = 0, nid, rv = 0;
|
||||
EC_GROUP *g = NULL , *ga = NULL;
|
||||
ECPARAMETERS *p = NULL, *pa = NULL;
|
||||
BN_CTX *ctx = NULL;
|
||||
|
||||
/* Do some setup */
|
||||
nid = curves[id].nid;
|
||||
if (!TEST_ptr(ctx = BN_CTX_new())
|
||||
|| !TEST_ptr(g = EC_GROUP_new_by_curve_name(nid))
|
||||
|| !TEST_ptr(p = EC_GROUP_get_ecparameters(g, NULL)))
|
||||
goto err;
|
||||
|
||||
/* replace with group from explicit parameters */
|
||||
EC_GROUP_free(g);
|
||||
if (!TEST_ptr(g = EC_GROUP_new_from_ecparameters(p)))
|
||||
goto err;
|
||||
|
||||
if (!TEST_int_gt(rv = EC_GROUP_check_named_curve(g, 0), 0))
|
||||
goto err;
|
||||
if (rv != nid) {
|
||||
/*
|
||||
* Found an alias:
|
||||
* fail if the returned nid is not an alias of the original group.
|
||||
*
|
||||
* The comparison here is done by comparing two explicit
|
||||
* parameter EC_GROUPs with EC_GROUP_cmp(), to ensure the
|
||||
* comparison happens with unnamed EC_GROUPs using the same
|
||||
* EC_METHODs.
|
||||
*/
|
||||
if (!TEST_ptr(ga = EC_GROUP_new_by_curve_name(rv))
|
||||
|| !TEST_ptr(pa = EC_GROUP_get_ecparameters(ga, NULL)))
|
||||
goto err;
|
||||
|
||||
/* replace with group from explicit parameters, then compare */
|
||||
EC_GROUP_free(ga);
|
||||
if (!TEST_ptr(ga = EC_GROUP_new_from_ecparameters(pa))
|
||||
|| !TEST_int_eq(EC_GROUP_cmp(g, ga, ctx), 0))
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
EC_GROUP_free(g);
|
||||
EC_GROUP_free(ga);
|
||||
ECPARAMETERS_free(p);
|
||||
ECPARAMETERS_free(pa);
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int parameter_test(void)
|
||||
{
|
||||
EC_GROUP *group = NULL, *group2 = NULL;
|
||||
@@ -1598,7 +1855,59 @@ err:
|
||||
OPENSSL_free(buf);
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int check_ec_key_field_public_range_test(int id)
|
||||
{
|
||||
int ret = 0, type = 0;
|
||||
const EC_POINT *pub = NULL;
|
||||
const EC_GROUP *group = NULL;
|
||||
const EC_METHOD *meth = NULL;
|
||||
const BIGNUM *field = NULL;
|
||||
BIGNUM *x = NULL, *y = NULL;
|
||||
EC_KEY *key = NULL;
|
||||
|
||||
if (!(TEST_ptr(x = BN_new())
|
||||
&& TEST_ptr(y = BN_new())
|
||||
&& TEST_ptr(key = EC_KEY_new_by_curve_name(curves[id].nid))
|
||||
&& TEST_ptr(group = EC_KEY_get0_group(key))
|
||||
&& TEST_ptr(meth = EC_GROUP_method_of(group))
|
||||
&& TEST_ptr(field = EC_GROUP_get0_field(group))
|
||||
&& TEST_int_gt(EC_KEY_generate_key(key), 0)
|
||||
&& TEST_int_gt(EC_KEY_check_key(key), 0)
|
||||
&& TEST_ptr(pub = EC_KEY_get0_public_key(key))
|
||||
&& TEST_int_gt(EC_POINT_get_affine_coordinates(group, pub, x, y,
|
||||
NULL), 0)))
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* Make the public point out of range by adding the field (which will still
|
||||
* be the same point on the curve). The add is different for char2 fields.
|
||||
*/
|
||||
type = EC_METHOD_get_field_type(meth);
|
||||
if (type == NID_X9_62_characteristic_two_field) {
|
||||
/* test for binary curves */
|
||||
if (!TEST_true(BN_GF2m_add(x, x, field)))
|
||||
goto err;
|
||||
} else if (type == NID_X9_62_prime_field) {
|
||||
/* test for prime curves */
|
||||
if (!TEST_true(BN_add(x, x, field)))
|
||||
goto err;
|
||||
} else {
|
||||
/* this should never happen */
|
||||
TEST_error("Unsupported EC_METHOD field_type");
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_int_le(EC_KEY_set_public_key_affine_coordinates(key, x, y), 0))
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
BN_free(x);
|
||||
BN_free(y);
|
||||
EC_KEY_free(key);
|
||||
return ret;
|
||||
}
|
||||
#endif /* OPENSSL_NO_EC */
|
||||
|
||||
int setup_tests(void)
|
||||
{
|
||||
@@ -1621,7 +1930,10 @@ int setup_tests(void)
|
||||
ADD_ALL_TESTS(internal_curve_test, crv_len);
|
||||
ADD_ALL_TESTS(internal_curve_test_method, crv_len);
|
||||
ADD_TEST(group_field_test);
|
||||
#endif
|
||||
ADD_ALL_TESTS(check_named_curve_test, crv_len);
|
||||
ADD_ALL_TESTS(check_named_curve_lookup_test, crv_len);
|
||||
ADD_ALL_TESTS(check_ec_key_field_public_range_test, crv_len);
|
||||
#endif /* OPENSSL_NO_EC */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
+78
-20
@@ -1083,7 +1083,8 @@ static int calculate_digest(const EVP_MD *md, const char *msg, size_t len,
|
||||
|| !TEST_true(EVP_DigestUpdate(ctx, msg, len))
|
||||
|| !TEST_true(EVP_DigestFinal_ex(ctx, out, NULL))
|
||||
|| !TEST_mem_eq(out, SHA256_DIGEST_LENGTH, exptd,
|
||||
SHA256_DIGEST_LENGTH))
|
||||
SHA256_DIGEST_LENGTH)
|
||||
|| !TEST_true(md == EVP_MD_CTX_md(ctx)))
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
@@ -1097,12 +1098,14 @@ static int calculate_digest(const EVP_MD *md, const char *msg, size_t len,
|
||||
* Test 0: Test with the default OPENSSL_CTX
|
||||
* Test 1: Test with an explicit OPENSSL_CTX
|
||||
* Test 2: Explicit OPENSSL_CTX with explicit load of default provider
|
||||
* Test 3: Explicit OPENSSL_CTX with explicit load of default and fips provider
|
||||
* Test 4: Explicit OPENSSL_CTX with explicit load of fips provider
|
||||
*/
|
||||
static int test_EVP_MD_fetch(int tst)
|
||||
{
|
||||
OPENSSL_CTX *ctx = NULL;
|
||||
EVP_MD *md = NULL;
|
||||
OSSL_PROVIDER *prov = NULL;
|
||||
OSSL_PROVIDER *defltprov = NULL, *fipsprov = NULL;
|
||||
int ret = 0;
|
||||
const char testmsg[] = "Hello world";
|
||||
const unsigned char exptd[] = {
|
||||
@@ -1116,25 +1119,35 @@ static int test_EVP_MD_fetch(int tst)
|
||||
if (!TEST_ptr(ctx))
|
||||
goto err;
|
||||
|
||||
if (tst == 2) {
|
||||
prov = OSSL_PROVIDER_load(ctx, "default");
|
||||
if (!TEST_ptr(prov))
|
||||
if (tst == 2 || tst == 3) {
|
||||
defltprov = OSSL_PROVIDER_load(ctx, "default");
|
||||
if (!TEST_ptr(defltprov))
|
||||
goto err;
|
||||
}
|
||||
if (tst == 3 || tst == 4) {
|
||||
fipsprov = OSSL_PROVIDER_load(ctx, "fips");
|
||||
if (!TEST_ptr(fipsprov))
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
/* Implicit fetching of the MD should produce the expected result */
|
||||
if (!TEST_true(calculate_digest(EVP_sha256(), testmsg, sizeof(testmsg),
|
||||
exptd)))
|
||||
exptd))
|
||||
|| !TEST_int_eq(EVP_MD_size(EVP_sha256()), SHA256_DIGEST_LENGTH)
|
||||
|| !TEST_int_eq(EVP_MD_block_size(EVP_sha256()), SHA256_CBLOCK))
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* Test that without loading any providers or specifying any properties we
|
||||
* can get a sha256 md from the default provider.
|
||||
* Test that without specifying any properties we can get a sha256 md from a
|
||||
* provider.
|
||||
*/
|
||||
if (!TEST_ptr(md = EVP_MD_fetch(ctx, "SHA256", NULL))
|
||||
|| !TEST_ptr(md)
|
||||
|| !TEST_int_eq(EVP_MD_nid(md), NID_sha256)
|
||||
|| !TEST_true(calculate_digest(md, testmsg, sizeof(testmsg), exptd)))
|
||||
|| !TEST_true(calculate_digest(md, testmsg, sizeof(testmsg), exptd))
|
||||
|| !TEST_int_eq(EVP_MD_size(md), SHA256_DIGEST_LENGTH)
|
||||
|| !TEST_int_eq(EVP_MD_block_size(md), SHA256_CBLOCK))
|
||||
goto err;
|
||||
|
||||
/* Also test EVP_MD_upref() while we're doing this */
|
||||
@@ -1146,26 +1159,67 @@ static int test_EVP_MD_fetch(int tst)
|
||||
md = NULL;
|
||||
|
||||
/*
|
||||
* We've only loaded the default provider so explicitly asking for a
|
||||
* non-default implementation should fail.
|
||||
* In tests 0 - 2 we've only loaded the default provider so explicitly
|
||||
* asking for a non-default implementation should fail. In tests 3 and 4 we
|
||||
* have the FIPS provider loaded so we should succeed in that case.
|
||||
*/
|
||||
if (!TEST_ptr_null(md = EVP_MD_fetch(ctx, "SHA256", "default=no")))
|
||||
goto err;
|
||||
|
||||
/* Explicitly asking for the default implementation should succeeed */
|
||||
if (!TEST_ptr(md = EVP_MD_fetch(ctx, "SHA256", "default=yes"))
|
||||
|| !TEST_int_eq(EVP_MD_nid(md), NID_sha256)
|
||||
|| !TEST_true(calculate_digest(md, testmsg, sizeof(testmsg), exptd)))
|
||||
goto err;
|
||||
md = EVP_MD_fetch(ctx, "SHA256", "default=no");
|
||||
if (tst == 3 || tst == 4) {
|
||||
if (!TEST_ptr(md)
|
||||
|| !TEST_true(calculate_digest(md, testmsg, sizeof(testmsg),
|
||||
exptd)))
|
||||
goto err;
|
||||
} else {
|
||||
if (!TEST_ptr_null(md))
|
||||
goto err;
|
||||
}
|
||||
|
||||
EVP_MD_meth_free(md);
|
||||
md = NULL;
|
||||
|
||||
/*
|
||||
* Explicitly asking for the default implementation should succeeed except
|
||||
* in test 4 where the default provider is not loaded.
|
||||
*/
|
||||
md = EVP_MD_fetch(ctx, "SHA256", "default=yes");
|
||||
if (tst != 4) {
|
||||
if (!TEST_ptr(md)
|
||||
|| !TEST_int_eq(EVP_MD_nid(md), NID_sha256)
|
||||
|| !TEST_true(calculate_digest(md, testmsg, sizeof(testmsg),
|
||||
exptd))
|
||||
|| !TEST_int_eq(EVP_MD_size(md), SHA256_DIGEST_LENGTH)
|
||||
|| !TEST_int_eq(EVP_MD_block_size(md), SHA256_CBLOCK))
|
||||
goto err;
|
||||
} else {
|
||||
if (!TEST_ptr_null(md))
|
||||
goto err;
|
||||
}
|
||||
|
||||
EVP_MD_meth_free(md);
|
||||
md = NULL;
|
||||
|
||||
/*
|
||||
* Explicitly asking for a fips implementation should succeed if we have
|
||||
* the FIPS provider loaded and fail otherwise
|
||||
*/
|
||||
md = EVP_MD_fetch(ctx, "SHA256", "fips=yes");
|
||||
if (tst == 3 || tst == 4) {
|
||||
if (!TEST_ptr(md)
|
||||
|| !TEST_true(calculate_digest(md, testmsg, sizeof(testmsg),
|
||||
exptd)))
|
||||
goto err;
|
||||
} else {
|
||||
if (!TEST_ptr_null(md))
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
EVP_MD_meth_free(md);
|
||||
OSSL_PROVIDER_unload(prov);
|
||||
OSSL_PROVIDER_unload(defltprov);
|
||||
OSSL_PROVIDER_unload(fipsprov);
|
||||
OPENSSL_CTX_free(ctx);
|
||||
return ret;
|
||||
}
|
||||
@@ -1199,6 +1253,10 @@ int setup_tests(void)
|
||||
ADD_ALL_TESTS(test_invalide_ec_char2_pub_range_decode,
|
||||
OSSL_NELEM(ec_der_pub_keys));
|
||||
#endif
|
||||
#ifdef NO_FIPS_MODULE
|
||||
ADD_ALL_TESTS(test_EVP_MD_fetch, 3);
|
||||
#else
|
||||
ADD_ALL_TESTS(test_EVP_MD_fetch, 5);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
+11
-6
@@ -15,19 +15,21 @@
|
||||
#include "internal/nelem.h"
|
||||
#include "testutil.h"
|
||||
|
||||
#define TEST_SIZE 128
|
||||
#define BIG_TEST_SIZE 10240
|
||||
#if !OPENSSL_API_3
|
||||
|
||||
#if BIG_TEST_SIZE < TEST_SIZE
|
||||
#error BIG_TEST_SIZE is smaller than TEST_SIZE
|
||||
#endif
|
||||
# define TEST_SIZE 128
|
||||
# define BIG_TEST_SIZE 10240
|
||||
|
||||
# if BIG_TEST_SIZE < TEST_SIZE
|
||||
# error BIG_TEST_SIZE is smaller than TEST_SIZE
|
||||
# endif
|
||||
|
||||
static unsigned char rkey[16];
|
||||
static unsigned char rkey2[16];
|
||||
static unsigned char plaintext[BIG_TEST_SIZE];
|
||||
static unsigned char saved_iv[AES_BLOCK_SIZE * 4];
|
||||
|
||||
#define MAX_VECTOR_SIZE 64
|
||||
# define MAX_VECTOR_SIZE 64
|
||||
|
||||
struct ige_test {
|
||||
const unsigned char key[16];
|
||||
@@ -432,9 +434,11 @@ static int test_bi_ige_garble3(void)
|
||||
/* Fail if there is more than 1% matching bytes */
|
||||
return TEST_size_t_le(matches, sizeof(checktext) / 100);
|
||||
}
|
||||
#endif
|
||||
|
||||
int setup_tests(void)
|
||||
{
|
||||
#if !OPENSSL_API_3
|
||||
RAND_bytes(rkey, sizeof(rkey));
|
||||
RAND_bytes(rkey2, sizeof(rkey2));
|
||||
RAND_bytes(plaintext, sizeof(plaintext));
|
||||
@@ -450,5 +454,6 @@ int setup_tests(void)
|
||||
ADD_TEST(test_bi_ige_garble3);
|
||||
ADD_ALL_TESTS(test_ige_vectors, OSSL_NELEM(ige_test_vectors));
|
||||
ADD_ALL_TESTS(test_bi_ige_vectors, OSSL_NELEM(bi_ige_test_vectors));
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
@@ -9,9 +9,12 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/provider.h>
|
||||
#include "internal/nelem.h"
|
||||
#include "testutil.h"
|
||||
|
||||
static OSSL_PROVIDER *prov = NULL;
|
||||
|
||||
#ifndef OPENSSL_NO_MD2
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/md2.h>
|
||||
@@ -58,6 +61,17 @@ static int test_md2(int n)
|
||||
}
|
||||
#endif
|
||||
|
||||
int global_init(void)
|
||||
{
|
||||
prov = OSSL_PROVIDER_load(NULL, "legacy");
|
||||
|
||||
return prov != NULL;
|
||||
}
|
||||
void cleanup_tests(void)
|
||||
{
|
||||
OSSL_PROVIDER_unload(prov);
|
||||
}
|
||||
|
||||
int setup_tests(void)
|
||||
{
|
||||
#ifndef OPENSSL_NO_MD2
|
||||
|
||||
+16
-4
@@ -52,21 +52,33 @@ static int p_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
|
||||
if (strcmp(p->key, "greeting") == 0) {
|
||||
static char *opensslv = NULL;
|
||||
static char *provname = NULL;
|
||||
static char *greeting = NULL;
|
||||
static OSSL_PARAM counter_request[] = {
|
||||
/* Known libcrypto provided parameters */
|
||||
{ "openssl-version", OSSL_PARAM_UTF8_PTR,
|
||||
&opensslv, sizeof(&opensslv), NULL },
|
||||
{ "provider-name", OSSL_PARAM_UTF8_PTR,
|
||||
&provname, sizeof(&provname), NULL},
|
||||
|
||||
/* This might be present, if there's such a configuration */
|
||||
{ "greeting", OSSL_PARAM_UTF8_PTR,
|
||||
&greeting, sizeof(&greeting), NULL },
|
||||
|
||||
{ NULL, 0, NULL, 0, NULL }
|
||||
};
|
||||
char buf[256];
|
||||
size_t buf_l;
|
||||
|
||||
if (c_get_params(prov, counter_request)) {
|
||||
const char *versionp = *(void **)counter_request[0].data;
|
||||
const char *namep = *(void **)counter_request[1].data;
|
||||
sprintf(buf, "Hello OpenSSL %.20s, greetings from %s!",
|
||||
versionp, namep);
|
||||
if (greeting) {
|
||||
strcpy(buf, greeting);
|
||||
} else {
|
||||
const char *versionp = *(void **)counter_request[0].data;
|
||||
const char *namep = *(void **)counter_request[1].data;
|
||||
|
||||
sprintf(buf, "Hello OpenSSL %.20s, greetings from %s!",
|
||||
versionp, namep);
|
||||
}
|
||||
} else {
|
||||
sprintf(buf, "Howdy stranger...");
|
||||
}
|
||||
|
||||
+90
-114
@@ -26,7 +26,15 @@ static void swap_copy(unsigned char *out, const void *in, size_t len)
|
||||
out[j] = ((unsigned char *)in)[len - j - 1];
|
||||
}
|
||||
|
||||
static void copy_to_le(unsigned char *out, const void *in, size_t len)
|
||||
/*
|
||||
* A memory copy that converts the native byte ordering either to or from
|
||||
* little endian format.
|
||||
*
|
||||
* On a little endian machine copying either is just a memcpy(3), on a
|
||||
* big endian machine copying from native to or from little endian involves
|
||||
* byte reversal.
|
||||
*/
|
||||
static void le_copy(unsigned char *out, const void *in, size_t len)
|
||||
{
|
||||
DECLARE_IS_ENDIAN;
|
||||
|
||||
@@ -36,16 +44,6 @@ static void copy_to_le(unsigned char *out, const void *in, size_t len)
|
||||
swap_copy(out, in, len);
|
||||
}
|
||||
|
||||
static void copy_be_to_native(unsigned char *out, const void *in, size_t len)
|
||||
{
|
||||
DECLARE_IS_ENDIAN;
|
||||
|
||||
if (IS_LITTLE_ENDIAN)
|
||||
swap_copy(out, in, len);
|
||||
else
|
||||
memcpy(out, in, len);
|
||||
}
|
||||
|
||||
static const struct {
|
||||
size_t len;
|
||||
unsigned char value[MAX_LEN];
|
||||
@@ -60,8 +58,8 @@ static const struct {
|
||||
0x89, 0x67, 0xf2, 0x68, 0x33, 0xa0, 0x14, 0xb0 } },
|
||||
};
|
||||
|
||||
static int test_param_type_extra(const OSSL_PARAM *param, unsigned char *cmp,
|
||||
size_t width)
|
||||
static int test_param_type_extra(const OSSL_PARAM *param,
|
||||
const unsigned char *cmp, size_t width)
|
||||
{
|
||||
int32_t i32;
|
||||
int64_t i64;
|
||||
@@ -85,17 +83,17 @@ static int test_param_type_extra(const OSSL_PARAM *param, unsigned char *cmp,
|
||||
|
||||
/* Check signed types */
|
||||
if (bit32) {
|
||||
copy_to_le(buf, &i32, sizeof(i32));
|
||||
le_copy(buf, &i32, sizeof(i32));
|
||||
sz = sizeof(i32) < width ? sizeof(i32) : width;
|
||||
if (!TEST_mem_eq(buf, sz, cmp, sz))
|
||||
return 0;
|
||||
}
|
||||
copy_to_le(buf, &i64, sizeof(i64));
|
||||
le_copy(buf, &i64, sizeof(i64));
|
||||
sz = sizeof(i64) < width ? sizeof(i64) : width;
|
||||
if (!TEST_mem_eq(buf, sz, cmp, sz))
|
||||
return 0;
|
||||
if (sizet && !signd) {
|
||||
copy_to_le(buf, &s, sizeof(s));
|
||||
le_copy(buf, &s, sizeof(s));
|
||||
sz = sizeof(s) < width ? sizeof(s) : width;
|
||||
if (!TEST_mem_eq(buf, sz, cmp, sz))
|
||||
return 0;
|
||||
@@ -133,268 +131,248 @@ static int test_param_type_extra(const OSSL_PARAM *param, unsigned char *cmp,
|
||||
static int test_param_int(int n)
|
||||
{
|
||||
int in, out;
|
||||
unsigned char buf[MAX_LEN], le[MAX_LEN], cmp[sizeof(int)];
|
||||
unsigned char buf[MAX_LEN], cmp[sizeof(int)];
|
||||
const size_t len = raw_values[n].len >= sizeof(int) ?
|
||||
sizeof(int) : raw_values[n].len;
|
||||
OSSL_PARAM param = OSSL_PARAM_int("a", NULL);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(le, 0, sizeof(le));
|
||||
copy_be_to_native(buf, raw_values[n].value, len);
|
||||
swap_copy(le, raw_values[n].value, len);
|
||||
le_copy(buf, raw_values[n].value, sizeof(in));
|
||||
memcpy(&in, buf, sizeof(in));
|
||||
param.data = &out;
|
||||
if (!TEST_true(OSSL_PARAM_set_int(¶m, in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, le, len))
|
||||
le_copy(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, raw_values[n].value, len))
|
||||
return 0;
|
||||
in = 0;
|
||||
param.data = buf;
|
||||
if (!TEST_true(OSSL_PARAM_get_int(¶m, &in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
|
||||
le_copy(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in)))
|
||||
return 0;
|
||||
param.data = &out;
|
||||
return test_param_type_extra(¶m, le, sizeof(int));
|
||||
return test_param_type_extra(¶m, raw_values[n].value, sizeof(int));
|
||||
}
|
||||
|
||||
static int test_param_long(int n)
|
||||
{
|
||||
long int in, out;
|
||||
unsigned char buf[MAX_LEN], le[MAX_LEN], cmp[sizeof(long int)];
|
||||
unsigned char buf[MAX_LEN], cmp[sizeof(long int)];
|
||||
const size_t len = raw_values[n].len >= sizeof(long int)
|
||||
? sizeof(long int) : raw_values[n].len;
|
||||
OSSL_PARAM param = OSSL_PARAM_long("a", NULL);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(le, 0, sizeof(le));
|
||||
copy_be_to_native(buf, raw_values[n].value, len);
|
||||
swap_copy(le, raw_values[n].value, len);
|
||||
le_copy(buf, raw_values[n].value, sizeof(in));
|
||||
memcpy(&in, buf, sizeof(in));
|
||||
param.data = &out;
|
||||
if (!TEST_true(OSSL_PARAM_set_long(¶m, in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, le, len))
|
||||
le_copy(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, raw_values[n].value, len))
|
||||
return 0;
|
||||
in = 0;
|
||||
param.data = buf;
|
||||
if (!TEST_true(OSSL_PARAM_get_long(¶m, &in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
|
||||
le_copy(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in)))
|
||||
return 0;
|
||||
param.data = &out;
|
||||
return test_param_type_extra(¶m, le, sizeof(long int));
|
||||
return test_param_type_extra(¶m, raw_values[n].value, sizeof(long int));
|
||||
}
|
||||
|
||||
static int test_param_uint(int n)
|
||||
{
|
||||
unsigned int in, out;
|
||||
unsigned char buf[MAX_LEN], le[MAX_LEN], cmp[sizeof(unsigned int)];
|
||||
unsigned char buf[MAX_LEN], cmp[sizeof(unsigned int)];
|
||||
const size_t len = raw_values[n].len >= sizeof(unsigned int) ? sizeof(unsigned int) : raw_values[n].len;
|
||||
OSSL_PARAM param = OSSL_PARAM_uint("a", NULL);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(le, 0, sizeof(le));
|
||||
copy_be_to_native(buf, raw_values[n].value, len);
|
||||
swap_copy(le, raw_values[n].value, len);
|
||||
le_copy(buf, raw_values[n].value, sizeof(in));
|
||||
memcpy(&in, buf, sizeof(in));
|
||||
param.data = &out;
|
||||
if (!TEST_true(OSSL_PARAM_set_uint(¶m, in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, le, len))
|
||||
le_copy(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, raw_values[n].value, len))
|
||||
return 0;
|
||||
in = 0;
|
||||
param.data = buf;
|
||||
if (!TEST_true(OSSL_PARAM_get_uint(¶m, &in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
|
||||
le_copy(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in)))
|
||||
return 0;
|
||||
param.data = &out;
|
||||
return test_param_type_extra(¶m, le, sizeof(unsigned int));
|
||||
return test_param_type_extra(¶m, raw_values[n].value, sizeof(unsigned int));
|
||||
}
|
||||
|
||||
static int test_param_ulong(int n)
|
||||
{
|
||||
unsigned long int in, out;
|
||||
unsigned char buf[MAX_LEN], le[MAX_LEN], cmp[sizeof(unsigned long int)];
|
||||
unsigned char buf[MAX_LEN], cmp[sizeof(unsigned long int)];
|
||||
const size_t len = raw_values[n].len >= sizeof(unsigned long int)
|
||||
? sizeof(unsigned long int) : raw_values[n].len;
|
||||
OSSL_PARAM param = OSSL_PARAM_ulong("a", NULL);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(le, 0, sizeof(le));
|
||||
copy_be_to_native(buf, raw_values[n].value, len);
|
||||
swap_copy(le, raw_values[n].value, len);
|
||||
le_copy(buf, raw_values[n].value, sizeof(in));
|
||||
memcpy(&in, buf, sizeof(in));
|
||||
param.data = &out;
|
||||
if (!TEST_true(OSSL_PARAM_set_ulong(¶m, in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, le, len))
|
||||
le_copy(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, raw_values[n].value, len))
|
||||
return 0;
|
||||
in = 0;
|
||||
param.data = buf;
|
||||
if (!TEST_true(OSSL_PARAM_get_ulong(¶m, &in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
|
||||
le_copy(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in)))
|
||||
return 0;
|
||||
param.data = &out;
|
||||
return test_param_type_extra(¶m, le, sizeof(unsigned long int));
|
||||
return test_param_type_extra(¶m, raw_values[n].value, sizeof(unsigned long int));
|
||||
}
|
||||
|
||||
static int test_param_int32(int n)
|
||||
{
|
||||
int32_t in, out;
|
||||
unsigned char buf[MAX_LEN], le[MAX_LEN], cmp[sizeof(int32_t)];
|
||||
unsigned char buf[MAX_LEN], cmp[sizeof(int32_t)];
|
||||
const size_t len = raw_values[n].len >= sizeof(int32_t)
|
||||
? sizeof(int32_t) : raw_values[n].len;
|
||||
OSSL_PARAM param = OSSL_PARAM_int32("a", NULL);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(le, 0, sizeof(le));
|
||||
copy_be_to_native(buf, raw_values[n].value, len);
|
||||
swap_copy(le, raw_values[n].value, len);
|
||||
le_copy(buf, raw_values[n].value, sizeof(in));
|
||||
memcpy(&in, buf, sizeof(in));
|
||||
param.data = &out;
|
||||
if (!TEST_true(OSSL_PARAM_set_int32(¶m, in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, le, len))
|
||||
le_copy(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, raw_values[n].value, len))
|
||||
return 0;
|
||||
in = 0;
|
||||
param.data = buf;
|
||||
if (!TEST_true(OSSL_PARAM_get_int32(¶m, &in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
|
||||
le_copy(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in)))
|
||||
return 0;
|
||||
param.data = &out;
|
||||
return test_param_type_extra(¶m, le, sizeof(int32_t));
|
||||
return test_param_type_extra(¶m, raw_values[n].value, sizeof(int32_t));
|
||||
}
|
||||
|
||||
static int test_param_uint32(int n)
|
||||
{
|
||||
uint32_t in, out;
|
||||
unsigned char buf[MAX_LEN], le[MAX_LEN], cmp[sizeof(uint32_t)];
|
||||
unsigned char buf[MAX_LEN], cmp[sizeof(uint32_t)];
|
||||
const size_t len = raw_values[n].len >= sizeof(uint32_t)
|
||||
? sizeof(uint32_t) : raw_values[n].len;
|
||||
OSSL_PARAM param = OSSL_PARAM_uint32("a", NULL);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(le, 0, sizeof(le));
|
||||
copy_be_to_native(buf, raw_values[n].value, len);
|
||||
swap_copy(le, raw_values[n].value, len);
|
||||
le_copy(buf, raw_values[n].value, sizeof(in));
|
||||
memcpy(&in, buf, sizeof(in));
|
||||
param.data = &out;
|
||||
if (!TEST_true(OSSL_PARAM_set_uint32(¶m, in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, le, len))
|
||||
le_copy(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, raw_values[n].value, len))
|
||||
return 0;
|
||||
in = 0;
|
||||
param.data = buf;
|
||||
if (!TEST_true(OSSL_PARAM_get_uint32(¶m, &in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
|
||||
le_copy(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in)))
|
||||
return 0;
|
||||
param.data = &out;
|
||||
return test_param_type_extra(¶m, le, sizeof(uint32_t));
|
||||
return test_param_type_extra(¶m, raw_values[n].value, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
static int test_param_int64(int n)
|
||||
{
|
||||
int64_t in, out;
|
||||
unsigned char buf[MAX_LEN], le[MAX_LEN], cmp[sizeof(int64_t)];
|
||||
unsigned char buf[MAX_LEN], cmp[sizeof(int64_t)];
|
||||
const size_t len = raw_values[n].len >= sizeof(int64_t)
|
||||
? sizeof(int64_t) : raw_values[n].len;
|
||||
OSSL_PARAM param = OSSL_PARAM_int64("a", NULL);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(le, 0, sizeof(le));
|
||||
copy_be_to_native(buf, raw_values[n].value, len);
|
||||
swap_copy(le, raw_values[n].value, len);
|
||||
le_copy(buf, raw_values[n].value, sizeof(in));
|
||||
memcpy(&in, buf, sizeof(in));
|
||||
param.data = &out;
|
||||
if (!TEST_true(OSSL_PARAM_set_int64(¶m, in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, le, len))
|
||||
le_copy(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, raw_values[n].value, len))
|
||||
return 0;
|
||||
in = 0;
|
||||
param.data = buf;
|
||||
if (!TEST_true(OSSL_PARAM_get_int64(¶m, &in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
|
||||
le_copy(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in)))
|
||||
return 0;
|
||||
param.data = &out;
|
||||
return test_param_type_extra(¶m, le, sizeof(int64_t));
|
||||
return test_param_type_extra(¶m, raw_values[n].value, sizeof(int64_t));
|
||||
}
|
||||
|
||||
static int test_param_uint64(int n)
|
||||
{
|
||||
uint64_t in, out;
|
||||
unsigned char buf[MAX_LEN], le[MAX_LEN], cmp[sizeof(uint64_t)];
|
||||
unsigned char buf[MAX_LEN], cmp[sizeof(uint64_t)];
|
||||
const size_t len = raw_values[n].len >= sizeof(uint64_t)
|
||||
? sizeof(uint64_t) : raw_values[n].len;
|
||||
OSSL_PARAM param = OSSL_PARAM_uint64("a", NULL);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(le, 0, sizeof(le));
|
||||
copy_be_to_native(buf, raw_values[n].value, len);
|
||||
swap_copy(le, raw_values[n].value, len);
|
||||
le_copy(buf, raw_values[n].value, sizeof(in));
|
||||
memcpy(&in, buf, sizeof(in));
|
||||
param.data = &out;
|
||||
if (!TEST_true(OSSL_PARAM_set_uint64(¶m, in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, le, len))
|
||||
le_copy(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, raw_values[n].value, len))
|
||||
return 0;
|
||||
in = 0;
|
||||
param.data = buf;
|
||||
if (!TEST_true(OSSL_PARAM_get_uint64(¶m, &in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
|
||||
le_copy(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in)))
|
||||
return 0;
|
||||
param.data = &out;
|
||||
return test_param_type_extra(¶m, le, sizeof(uint64_t));
|
||||
return test_param_type_extra(¶m, raw_values[n].value, sizeof(uint64_t));
|
||||
}
|
||||
|
||||
static int test_param_size_t(int n)
|
||||
{
|
||||
size_t in, out;
|
||||
unsigned char buf[MAX_LEN], le[MAX_LEN], cmp[sizeof(size_t)];
|
||||
unsigned char buf[MAX_LEN], cmp[sizeof(size_t)];
|
||||
const size_t len = raw_values[n].len >= sizeof(size_t)
|
||||
? sizeof(size_t) : raw_values[n].len;
|
||||
OSSL_PARAM param = OSSL_PARAM_size_t("a", NULL);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(le, 0, sizeof(le));
|
||||
copy_be_to_native(buf, raw_values[n].value, len);
|
||||
swap_copy(le, raw_values[n].value, len);
|
||||
le_copy(buf, raw_values[n].value, sizeof(in));
|
||||
memcpy(&in, buf, sizeof(in));
|
||||
param.data = &out;
|
||||
if (!TEST_true(OSSL_PARAM_set_size_t(¶m, in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, le, len))
|
||||
le_copy(cmp, &out, sizeof(out));
|
||||
if (!TEST_mem_eq(cmp, len, raw_values[n].value, len))
|
||||
return 0;
|
||||
in = 0;
|
||||
param.data = buf;
|
||||
if (!TEST_true(OSSL_PARAM_get_size_t(¶m, &in)))
|
||||
return 0;
|
||||
copy_to_le(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
|
||||
le_copy(cmp, &in, sizeof(in));
|
||||
if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in)))
|
||||
return 0;
|
||||
param.data = &out;
|
||||
return test_param_type_extra(¶m, le, sizeof(size_t));
|
||||
return test_param_type_extra(¶m, raw_values[n].value, sizeof(size_t));
|
||||
}
|
||||
|
||||
static int test_param_bignum(int n)
|
||||
{
|
||||
unsigned char buf[MAX_LEN], bnbuf[MAX_LEN], le[MAX_LEN];
|
||||
unsigned char buf[MAX_LEN], bnbuf[MAX_LEN];
|
||||
const size_t len = raw_values[n].len;
|
||||
size_t bnsize;
|
||||
BIGNUM *b = NULL, *c = NULL;
|
||||
@@ -406,9 +384,8 @@ static int test_param_bignum(int n)
|
||||
param.data_size = len;
|
||||
param.return_size = &bnsize;
|
||||
|
||||
copy_be_to_native(buf, raw_values[n].value, len);
|
||||
swap_copy(le, raw_values[n].value, len);
|
||||
if (!TEST_ptr(b = BN_bin2bn(raw_values[n].value, (int)len, NULL)))
|
||||
le_copy(buf, raw_values[n].value, len);
|
||||
if (!TEST_ptr(b = BN_lebin2bn(raw_values[n].value, (int)len, NULL)))
|
||||
goto err;
|
||||
|
||||
if (!TEST_true(OSSL_PARAM_set_BN(¶m, b))
|
||||
@@ -471,7 +448,6 @@ static int test_param_construct(void)
|
||||
void *vp, *vpn = NULL, *vp2;
|
||||
OSSL_PARAM *p;
|
||||
const OSSL_PARAM *cp;
|
||||
static const OSSL_PARAM pend = OSSL_PARAM_END;
|
||||
int i, n = 0, ret = 0;
|
||||
unsigned int u;
|
||||
long int l;
|
||||
@@ -499,9 +475,9 @@ static int test_param_construct(void)
|
||||
&sz);
|
||||
params[n++] = OSSL_PARAM_construct_octet_string("octstr", buf, sizeof(buf),
|
||||
&sz);
|
||||
params[n++] = OSSL_PARAM_construct_utf8_ptr("utf8ptr", &bufp, &sz);
|
||||
params[n++] = OSSL_PARAM_construct_octet_ptr("octptr", &vp, &sz);
|
||||
params[n] = pend;
|
||||
params[n++] = OSSL_PARAM_construct_utf8_ptr("utf8ptr", &bufp, 0, &sz);
|
||||
params[n++] = OSSL_PARAM_construct_octet_ptr("octptr", &vp, 0, &sz);
|
||||
params[n] = OSSL_PARAM_construct_end();
|
||||
|
||||
/* Search failure */
|
||||
if (!TEST_ptr_null(OSSL_PARAM_locate(params, "fnord")))
|
||||
|
||||
+26
-9
@@ -143,8 +143,10 @@ static int raw_set_params(void *vobj, const OSSL_PARAM *params)
|
||||
return 0;
|
||||
} else if (strcmp(params->key, "p5") == 0) {
|
||||
strncpy(obj->p5, params->data, params->data_size);
|
||||
obj->p5_l = strlen(obj->p5) + 1;
|
||||
} else if (strcmp(params->key, "p6") == 0) {
|
||||
obj->p6 = *(const char **)params->data;
|
||||
obj->p6_l = params->data_size;
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -233,10 +235,13 @@ static int api_set_params(void *vobj, const OSSL_PARAM *params)
|
||||
char *p5_ptr = obj->p5;
|
||||
if (!TEST_true(OSSL_PARAM_get_utf8_string(p, &p5_ptr, sizeof(obj->p5))))
|
||||
return 0;
|
||||
obj->p5_l = strlen(obj->p5) + 1;
|
||||
}
|
||||
if ((p = OSSL_PARAM_locate(params, "p6")) != NULL) {
|
||||
if (!TEST_true(OSSL_PARAM_get_utf8_ptr(p, &obj->p6)))
|
||||
return 0;
|
||||
obj->p6_l = strlen(obj->p6) + 1;
|
||||
}
|
||||
if ((p = OSSL_PARAM_locate(params, "p6")) != NULL
|
||||
&& !TEST_true(OSSL_PARAM_get_utf8_ptr(p, &obj->p6)))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -364,7 +369,8 @@ static const OSSL_PARAM static_raw_params[] = {
|
||||
&bignumbin_l },
|
||||
{ "p4", OSSL_PARAM_UTF8_STRING, &app_p4, sizeof(app_p4), &app_p4_l },
|
||||
{ "p5", OSSL_PARAM_UTF8_STRING, &app_p5, sizeof(app_p5), &app_p5_l },
|
||||
{ "p6", OSSL_PARAM_UTF8_PTR, &app_p6, sizeof(app_p6), &app_p6_l },
|
||||
/* sizeof(app_p6_init), because we know that's what we're using */
|
||||
{ "p6", OSSL_PARAM_UTF8_PTR, &app_p6, sizeof(app_p6_init), &app_p6_l },
|
||||
{ "foo", OSSL_PARAM_OCTET_STRING, &foo, sizeof(foo), &foo_l },
|
||||
{ NULL, 0, NULL, 0, NULL }
|
||||
};
|
||||
@@ -377,8 +383,9 @@ static const OSSL_PARAM static_api_params[] = {
|
||||
&app_p4, sizeof(app_p4), &app_p4_l),
|
||||
OSSL_PARAM_DEFN("p5", OSSL_PARAM_UTF8_STRING,
|
||||
&app_p5, sizeof(app_p5), &app_p5_l),
|
||||
/* sizeof(app_p6_init), because we know that's what we're using */
|
||||
OSSL_PARAM_DEFN("p6", OSSL_PARAM_UTF8_PTR,
|
||||
&app_p6, sizeof(app_p6), &app_p6_l),
|
||||
&app_p6, sizeof(app_p6_init), &app_p6_l),
|
||||
OSSL_PARAM_DEFN("foo", OSSL_PARAM_OCTET_STRING, &foo, sizeof(foo), &foo_l),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
@@ -391,7 +398,6 @@ static OSSL_PARAM *construct_api_params(void)
|
||||
{
|
||||
size_t n = 0;
|
||||
static OSSL_PARAM params[10];
|
||||
OSSL_PARAM param_end = OSSL_PARAM_END;
|
||||
|
||||
params[n++] = OSSL_PARAM_construct_int("p1", &app_p1, NULL);
|
||||
params[n++] = OSSL_PARAM_construct_BN("p3", bignumbin, sizeof(bignumbin),
|
||||
@@ -400,11 +406,12 @@ static OSSL_PARAM *construct_api_params(void)
|
||||
&app_p4_l);
|
||||
params[n++] = OSSL_PARAM_construct_utf8_string("p5", app_p5,
|
||||
sizeof(app_p5), &app_p5_l);
|
||||
/* sizeof(app_p6_init), because we know that's what we're using */
|
||||
params[n++] = OSSL_PARAM_construct_utf8_ptr("p6", (char **)&app_p6,
|
||||
&app_p6_l);
|
||||
sizeof(app_p6_init), &app_p6_l);
|
||||
params[n++] = OSSL_PARAM_construct_octet_string("foo", &foo, sizeof(foo),
|
||||
&foo_l);
|
||||
params[n++] = param_end;
|
||||
params[n++] = OSSL_PARAM_construct_end();
|
||||
|
||||
return params;
|
||||
}
|
||||
@@ -473,7 +480,9 @@ static int test_case_variant(const OSSL_PARAM *params,
|
||||
|| !TEST_ptr(BN_native2bn(bignumbin, bignumbin_l, app_p3))
|
||||
|| !TEST_BN_eq(app_p3, verify_p3) /* "provider" value */
|
||||
|| !TEST_str_eq(app_p4, p4_init) /* "provider" value */
|
||||
|| !TEST_size_t_eq(app_p5_l, sizeof(p5_init)) /* "provider" value */
|
||||
|| !TEST_str_eq(app_p5, p5_init) /* "provider" value */
|
||||
|| !TEST_size_t_eq(app_p6_l, sizeof(p6_init)) /* "provider" value */
|
||||
|| !TEST_str_eq(app_p6, p6_init) /* "provider" value */
|
||||
|| !TEST_char_eq(foo[0], app_foo_init) /* Should remain untouched */
|
||||
|| !TEST_int_eq(foo_l, sizeof(app_foo_init)))
|
||||
@@ -494,7 +503,11 @@ static int test_case_variant(const OSSL_PARAM *params,
|
||||
|| !TEST_double_eq(sneakpeek->p2, p2_init) /* Should remain untouched */
|
||||
|| !TEST_BN_eq(sneakpeek->p3, app_p3) /* app value set */
|
||||
|| !TEST_str_eq(sneakpeek->p4, app_p4) /* app value set */
|
||||
|| !TEST_str_eq(sneakpeek->p5, app_p5)) /* app value set */
|
||||
|| !TEST_size_t_eq(sneakpeek->p5_l, app_p5_l) /* app value set */
|
||||
|| !TEST_str_eq(sneakpeek->p5, app_p5) /* app value set */
|
||||
|| !TEST_size_t_eq(sneakpeek->p6_l,
|
||||
sizeof(app_p6_init)) /* app value set */
|
||||
|| !TEST_str_eq(sneakpeek->p6, app_p6)) /* app value set */
|
||||
errcnt++;
|
||||
}
|
||||
|
||||
@@ -516,7 +529,11 @@ static int test_case_variant(const OSSL_PARAM *params,
|
||||
|| !TEST_ptr(BN_native2bn(bignumbin, bignumbin_l, app_p3))
|
||||
|| !TEST_BN_eq(app_p3, verify_p3) /* app value */
|
||||
|| !TEST_str_eq(app_p4, app_p4_init) /* app value */
|
||||
|| !TEST_size_t_eq(app_p5_l,
|
||||
sizeof(app_p5_init)) /* app value */
|
||||
|| !TEST_str_eq(app_p5, app_p5_init) /* app value */
|
||||
|| !TEST_size_t_eq(app_p6_l,
|
||||
sizeof(app_p6_init)) /* app value */
|
||||
|| !TEST_str_eq(app_p6, app_p6_init) /* app value */
|
||||
|| !TEST_char_eq(foo[0], app_foo_init) /* Should remain untouched */
|
||||
|| !TEST_int_eq(foo_l, sizeof(app_foo_init)))
|
||||
|
||||
@@ -8,14 +8,10 @@
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "internal/provider.h"
|
||||
#include "testutil.h"
|
||||
|
||||
#if !defined(DSO_VMS) && !defined(DSO_DLCFN) && !defined(DSO_DL) \
|
||||
&& !defined(DSO_WIN32) && !defined(DSO_DLFCN)
|
||||
# define OPENSSL_NO_DSO
|
||||
#endif
|
||||
|
||||
extern OSSL_provider_init_fn PROVIDER_INIT_FUNCTION_NAME;
|
||||
|
||||
static char buf[256];
|
||||
@@ -25,20 +21,11 @@ static OSSL_PARAM greeting_request[] = {
|
||||
{ NULL, 0, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
static int test_provider(OSSL_PROVIDER *prov)
|
||||
static int test_provider(OSSL_PROVIDER *prov, const char *expected_greeting)
|
||||
{
|
||||
const char *name = NULL;
|
||||
const char *greeting = NULL;
|
||||
char expected_greeting[256];
|
||||
int ret = 0;
|
||||
|
||||
if (!TEST_ptr(name = ossl_provider_name(prov)))
|
||||
return 0;
|
||||
|
||||
BIO_snprintf(expected_greeting, sizeof(expected_greeting),
|
||||
"Hello OpenSSL %.20s, greetings from %s!",
|
||||
OPENSSL_VERSION_STR, name);
|
||||
|
||||
ret =
|
||||
TEST_true(ossl_provider_activate(prov))
|
||||
&& TEST_true(ossl_provider_get_params(prov, greeting_request))
|
||||
@@ -46,10 +33,22 @@ static int test_provider(OSSL_PROVIDER *prov)
|
||||
&& TEST_size_t_gt(greeting_request[0].data_size, 0)
|
||||
&& TEST_str_eq(greeting, expected_greeting);
|
||||
|
||||
TEST_info("Got this greeting: %s\n", greeting);
|
||||
ossl_provider_free(prov);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const char *expected_greeting1(const char *name)
|
||||
{
|
||||
static char expected_greeting[256] = "";
|
||||
|
||||
BIO_snprintf(expected_greeting, sizeof(expected_greeting),
|
||||
"Hello OpenSSL %.20s, greetings from %s!",
|
||||
OPENSSL_VERSION_STR, name);
|
||||
|
||||
return expected_greeting;
|
||||
}
|
||||
|
||||
static int test_builtin_provider(void)
|
||||
{
|
||||
const char *name = "p_test_builtin";
|
||||
@@ -58,10 +57,10 @@ static int test_builtin_provider(void)
|
||||
return
|
||||
TEST_ptr(prov =
|
||||
ossl_provider_new(NULL, name, PROVIDER_INIT_FUNCTION_NAME))
|
||||
&& test_provider(prov);
|
||||
&& test_provider(prov, expected_greeting1(name));
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_DSO
|
||||
#ifndef NO_PROVIDER_MODULE
|
||||
static int test_loaded_provider(void)
|
||||
{
|
||||
const char *name = "p_test";
|
||||
@@ -69,15 +68,30 @@ static int test_loaded_provider(void)
|
||||
|
||||
return
|
||||
TEST_ptr(prov = ossl_provider_new(NULL, name, NULL))
|
||||
&& test_provider(prov);
|
||||
&& test_provider(prov, expected_greeting1(name));
|
||||
}
|
||||
|
||||
static int test_configured_provider(void)
|
||||
{
|
||||
const char *name = "p_test_configured";
|
||||
OSSL_PROVIDER *prov = NULL;
|
||||
/* This MUST match the config file */
|
||||
const char *expected_greeting =
|
||||
"Hello OpenSSL, greetings from Test Provider";
|
||||
|
||||
return
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL)
|
||||
&& TEST_ptr(prov = ossl_provider_find(NULL, name))
|
||||
&& test_provider(prov, expected_greeting);
|
||||
}
|
||||
#endif
|
||||
|
||||
int setup_tests(void)
|
||||
{
|
||||
ADD_TEST(test_builtin_provider);
|
||||
#ifndef OPENSSL_NO_DSO
|
||||
#ifndef NO_PROVIDER_MODULE
|
||||
ADD_TEST(test_loaded_provider);
|
||||
ADD_TEST(test_configured_provider);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{- use platform -}
|
||||
openssl_conf = openssl_init
|
||||
|
||||
[openssl_init]
|
||||
providers = providers
|
||||
|
||||
[providers]
|
||||
p_test_configured = p_test_configured
|
||||
|
||||
[p_test_configured]
|
||||
module = {- platform->dso('p_test') -}
|
||||
activate = 1
|
||||
greeting = Hello OpenSSL, greetings from Test Provider
|
||||
@@ -11,12 +11,6 @@
|
||||
#include <openssl/provider.h>
|
||||
#include "testutil.h"
|
||||
|
||||
#if !defined(DSO_VMS) && !defined(DSO_DLCFN) && !defined(DSO_DL) \
|
||||
&& !defined(DSO_WIN32) && !defined(DSO_DLFCN)
|
||||
# define OPENSSL_NO_DSO
|
||||
#endif
|
||||
|
||||
|
||||
extern OSSL_provider_init_fn PROVIDER_INIT_FUNCTION_NAME;
|
||||
|
||||
static char buf[256];
|
||||
@@ -55,7 +49,7 @@ static int test_builtin_provider(void)
|
||||
&& test_provider(name);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_DSO
|
||||
#ifndef NO_PROVIDER_MODULE
|
||||
static int test_loaded_provider(void)
|
||||
{
|
||||
const char *name = "p_test";
|
||||
@@ -67,7 +61,7 @@ static int test_loaded_provider(void)
|
||||
int setup_tests(void)
|
||||
{
|
||||
ADD_TEST(test_builtin_provider);
|
||||
#ifndef OPENSSL_NO_DSO
|
||||
#ifndef NO_PROVIDER_MODULE
|
||||
ADD_TEST(test_loaded_provider);
|
||||
#endif
|
||||
return 1;
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
# https://www.openssl.org/source/license.html
|
||||
|
||||
use strict;
|
||||
use OpenSSL::Test qw(:DEFAULT bldtop_dir);
|
||||
use OpenSSL::Test qw(:DEFAULT bldtop_dir bldtop_file);
|
||||
use OpenSSL::Test::Simple;
|
||||
use OpenSSL::Test::Utils;
|
||||
|
||||
setup("test_internal_provider");
|
||||
|
||||
$ENV{"OPENSSL_MODULES"} = bldtop_dir("test");
|
||||
$ENV{OPENSSL_MODULES} = bldtop_dir("test");
|
||||
$ENV{OPENSSL_CONF} = bldtop_file("test", "provider_internal_test.conf");
|
||||
|
||||
simple_test("test_internal_provider", "provider_internal_test");
|
||||
@@ -8,5 +8,10 @@
|
||||
|
||||
|
||||
use OpenSSL::Test::Simple;
|
||||
use OpenSSL::Test qw/:DEFAULT bldtop_dir/;
|
||||
|
||||
setup("test_md2");
|
||||
|
||||
$ENV{OPENSSL_MODULES} = bldtop_dir("providers");
|
||||
|
||||
simple_test("test_md2", "md2test", "md2");
|
||||
@@ -23,12 +23,20 @@ plan skip_all => "EC isn't supported in this build"
|
||||
my @valid = glob(data_file("valid", "*.pem"));
|
||||
my @invalid = glob(data_file("invalid", "*.pem"));
|
||||
|
||||
plan tests => scalar @valid + scalar @invalid;
|
||||
plan tests => scalar @valid + scalar @invalid + scalar @valid + scalar @invalid;
|
||||
|
||||
foreach (@valid) {
|
||||
ok(run(app([qw{openssl ecparam -noout -check -in}, $_])));
|
||||
}
|
||||
|
||||
foreach (@valid) {
|
||||
ok(run(app([qw{openssl ecparam -noout -check_named -in}, $_])));
|
||||
}
|
||||
|
||||
foreach (@invalid) {
|
||||
ok(!run(app([qw{openssl ecparam -noout -check -in}, $_])));
|
||||
}
|
||||
|
||||
foreach (@invalid) {
|
||||
ok(!run(app([qw{openssl ecparam -noout -check_named -in}, $_])));
|
||||
}
|
||||
@@ -375,7 +375,7 @@ SKIP: {
|
||||
}
|
||||
|
||||
SKIP: {
|
||||
skip "SM2 is not supported by this OpenSSL build", 1
|
||||
skip "SM2 is not supported by this OpenSSL build", 2
|
||||
if disabled("sm2");
|
||||
|
||||
# Test '-sm2-id' and '-sm2-hex-id' option
|
||||
|
||||
@@ -1184,7 +1184,7 @@ Key = 0000000000000000000000000000000000000000000000000000000000000000
|
||||
IV = 00000000000000000000000000000000
|
||||
Plaintext = 0000000000000000000000000000000000000000000000000000000000000000
|
||||
Ciphertext = 917cf69ebd68b2ec9b9fe9a3eadda692cd43d2f59598ed858c02c2652fbf922e
|
||||
Result = CIPHERUPDATE_ERROR
|
||||
Result = KEY_SET_ERROR
|
||||
|
||||
Cipher = aes-128-xts
|
||||
Key = 1111111111111111111111111111111122222222222222222222222222222222
|
||||
|
||||
@@ -10,9 +10,12 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use OpenSSL::Test;
|
||||
use OpenSSL::Test qw/:DEFAULT bldtop_dir/;
|
||||
|
||||
setup("test_evp_extra");
|
||||
|
||||
plan tests => 1;
|
||||
|
||||
$ENV{OPENSSL_MODULES} = bldtop_dir("providers");
|
||||
|
||||
ok(run(test(["evp_extra_test"])), "running evp_extra_test");
|
||||
@@ -324,6 +324,14 @@ my @smime_cms_param_tests = (
|
||||
"-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
|
||||
],
|
||||
|
||||
[ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=-3",
|
||||
[ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
|
||||
"-signer", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:pss",
|
||||
"-keyopt", "rsa_pss_saltlen:-3", "-out", "test.cms" ],
|
||||
[ "-verify", "-in", "test.cms", "-inform", "PEM",
|
||||
"-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
|
||||
],
|
||||
|
||||
[ "signed content test streaming PEM format, RSA keys, PSS signature, no attributes",
|
||||
[ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach", "-noattr",
|
||||
"-signer", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:pss",
|
||||
|
||||
+144
-23
@@ -723,6 +723,8 @@ static int ping_pong_query(SSL *clientssl, SSL *serverssl, int cfd, int sfd)
|
||||
size_t err = 0;
|
||||
char crec_wseq_before[TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE];
|
||||
char crec_wseq_after[TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE];
|
||||
char crec_rseq_before[TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE];
|
||||
char crec_rseq_after[TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE];
|
||||
char srec_wseq_before[TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE];
|
||||
char srec_wseq_after[TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE];
|
||||
char srec_rseq_before[TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE];
|
||||
@@ -731,6 +733,8 @@ static int ping_pong_query(SSL *clientssl, SSL *serverssl, int cfd, int sfd)
|
||||
cbuf[0] = count++;
|
||||
memcpy(crec_wseq_before, &clientssl->rlayer.write_sequence,
|
||||
TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
|
||||
memcpy(crec_rseq_before, &clientssl->rlayer.read_sequence,
|
||||
TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
|
||||
memcpy(srec_wseq_before, &serverssl->rlayer.write_sequence,
|
||||
TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
|
||||
memcpy(srec_rseq_before, &serverssl->rlayer.read_sequence,
|
||||
@@ -756,6 +760,8 @@ static int ping_pong_query(SSL *clientssl, SSL *serverssl, int cfd, int sfd)
|
||||
|
||||
memcpy(crec_wseq_after, &clientssl->rlayer.write_sequence,
|
||||
TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
|
||||
memcpy(crec_rseq_after, &clientssl->rlayer.read_sequence,
|
||||
TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
|
||||
memcpy(srec_wseq_after, &serverssl->rlayer.write_sequence,
|
||||
TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
|
||||
memcpy(srec_rseq_after, &serverssl->rlayer.read_sequence,
|
||||
@@ -786,16 +792,33 @@ static int ping_pong_query(SSL *clientssl, SSL *serverssl, int cfd, int sfd)
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!TEST_mem_ne(srec_rseq_before, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE,
|
||||
srec_rseq_after, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE))
|
||||
goto end;
|
||||
if (clientssl->mode & SSL_MODE_NO_KTLS_RX) {
|
||||
if (!TEST_mem_ne(crec_rseq_before, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE,
|
||||
crec_rseq_after, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE))
|
||||
goto end;
|
||||
} else {
|
||||
if (!TEST_mem_eq(crec_rseq_before, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE,
|
||||
crec_rseq_after, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE))
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (serverssl->mode & SSL_MODE_NO_KTLS_RX) {
|
||||
if (!TEST_mem_ne(srec_rseq_before, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE,
|
||||
srec_rseq_after, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE))
|
||||
goto end;
|
||||
} else {
|
||||
if (!TEST_mem_eq(srec_rseq_before, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE,
|
||||
srec_rseq_after, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE))
|
||||
goto end;
|
||||
}
|
||||
|
||||
return 1;
|
||||
end:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int execute_test_ktls(int cis_ktls_tx, int sis_ktls_tx)
|
||||
static int execute_test_ktls(int cis_ktls_tx, int cis_ktls_rx,
|
||||
int sis_ktls_tx, int sis_ktls_rx)
|
||||
{
|
||||
SSL_CTX *cctx = NULL, *sctx = NULL;
|
||||
SSL *clientssl = NULL, *serverssl = NULL;
|
||||
@@ -830,6 +853,16 @@ static int execute_test_ktls(int cis_ktls_tx, int sis_ktls_tx)
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!cis_ktls_rx) {
|
||||
if (!TEST_true(SSL_set_mode(clientssl, SSL_MODE_NO_KTLS_RX)))
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!sis_ktls_rx) {
|
||||
if (!TEST_true(SSL_set_mode(serverssl, SSL_MODE_NO_KTLS_RX)))
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!TEST_true(create_ssl_connection(serverssl, clientssl,
|
||||
SSL_ERROR_NONE)))
|
||||
goto end;
|
||||
@@ -850,6 +883,22 @@ static int execute_test_ktls(int cis_ktls_tx, int sis_ktls_tx)
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!cis_ktls_rx) {
|
||||
if (!TEST_false(BIO_get_ktls_recv(clientssl->rbio)))
|
||||
goto end;
|
||||
} else {
|
||||
if (!TEST_true(BIO_get_ktls_recv(clientssl->rbio)))
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!sis_ktls_rx) {
|
||||
if (!TEST_false(BIO_get_ktls_recv(serverssl->rbio)))
|
||||
goto end;
|
||||
} else {
|
||||
if (!TEST_true(BIO_get_ktls_recv(serverssl->rbio)))
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!TEST_true(ping_pong_query(clientssl, serverssl, cfd, sfd)))
|
||||
goto end;
|
||||
|
||||
@@ -869,24 +918,84 @@ end:
|
||||
return testresult;
|
||||
}
|
||||
|
||||
static int test_ktls_no_txrx_client_no_txrx_server(void)
|
||||
{
|
||||
return execute_test_ktls(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
static int test_ktls_no_rx_client_no_txrx_server(void)
|
||||
{
|
||||
return execute_test_ktls(1, 0, 0, 0);
|
||||
}
|
||||
|
||||
static int test_ktls_no_tx_client_no_txrx_server(void)
|
||||
{
|
||||
return execute_test_ktls(0, 1, 0, 0);
|
||||
}
|
||||
|
||||
static int test_ktls_client_no_txrx_server(void)
|
||||
{
|
||||
return execute_test_ktls(1, 1, 0, 0);
|
||||
}
|
||||
|
||||
static int test_ktls_no_txrx_client_no_rx_server(void)
|
||||
{
|
||||
return execute_test_ktls(0, 0, 1, 0);
|
||||
}
|
||||
|
||||
static int test_ktls_no_rx_client_no_rx_server(void)
|
||||
{
|
||||
return execute_test_ktls(1, 0, 1, 0);
|
||||
}
|
||||
|
||||
static int test_ktls_no_tx_client_no_rx_server(void)
|
||||
{
|
||||
return execute_test_ktls(0, 1, 1, 0);
|
||||
}
|
||||
|
||||
static int test_ktls_client_no_rx_server(void)
|
||||
{
|
||||
return execute_test_ktls(1, 1, 1, 0);
|
||||
}
|
||||
|
||||
static int test_ktls_no_txrx_client_no_tx_server(void)
|
||||
{
|
||||
return execute_test_ktls(0, 0, 0, 1);
|
||||
}
|
||||
|
||||
static int test_ktls_no_rx_client_no_tx_server(void)
|
||||
{
|
||||
return execute_test_ktls(1, 0, 0, 1);
|
||||
}
|
||||
|
||||
static int test_ktls_no_tx_client_no_tx_server(void)
|
||||
{
|
||||
return execute_test_ktls(0, 1, 0, 1);
|
||||
}
|
||||
|
||||
static int test_ktls_client_no_tx_server(void)
|
||||
{
|
||||
return execute_test_ktls(1, 1, 0, 1);
|
||||
}
|
||||
|
||||
static int test_ktls_no_txrx_client_server(void)
|
||||
{
|
||||
return execute_test_ktls(0, 0, 1, 1);
|
||||
}
|
||||
|
||||
static int test_ktls_no_rx_client_server(void)
|
||||
{
|
||||
return execute_test_ktls(1, 0, 1, 1);
|
||||
}
|
||||
|
||||
static int test_ktls_no_tx_client_server(void)
|
||||
{
|
||||
return execute_test_ktls(0, 1, 1, 1);
|
||||
}
|
||||
|
||||
static int test_ktls_client_server(void)
|
||||
{
|
||||
return execute_test_ktls(1, 1);
|
||||
}
|
||||
|
||||
static int test_ktls_no_client_server(void)
|
||||
{
|
||||
return execute_test_ktls(0, 1);
|
||||
}
|
||||
|
||||
static int test_ktls_client_no_server(void)
|
||||
{
|
||||
return execute_test_ktls(1, 0);
|
||||
}
|
||||
|
||||
static int test_ktls_no_client_no_server(void)
|
||||
{
|
||||
return execute_test_ktls(0, 0);
|
||||
return execute_test_ktls(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -6155,10 +6264,22 @@ int setup_tests(void)
|
||||
|
||||
#if !defined(OPENSSL_NO_TLS1_2) && !defined(OPENSSL_NO_KTLS) \
|
||||
&& !defined(OPENSSL_NO_SOCK)
|
||||
ADD_TEST(test_ktls_no_txrx_client_no_txrx_server);
|
||||
ADD_TEST(test_ktls_no_rx_client_no_txrx_server);
|
||||
ADD_TEST(test_ktls_no_tx_client_no_txrx_server);
|
||||
ADD_TEST(test_ktls_client_no_txrx_server);
|
||||
ADD_TEST(test_ktls_no_txrx_client_no_rx_server);
|
||||
ADD_TEST(test_ktls_no_rx_client_no_rx_server);
|
||||
ADD_TEST(test_ktls_no_tx_client_no_rx_server);
|
||||
ADD_TEST(test_ktls_client_no_rx_server);
|
||||
ADD_TEST(test_ktls_no_txrx_client_no_tx_server);
|
||||
ADD_TEST(test_ktls_no_rx_client_no_tx_server);
|
||||
ADD_TEST(test_ktls_no_tx_client_no_tx_server);
|
||||
ADD_TEST(test_ktls_client_no_tx_server);
|
||||
ADD_TEST(test_ktls_no_txrx_client_server);
|
||||
ADD_TEST(test_ktls_no_rx_client_server);
|
||||
ADD_TEST(test_ktls_no_tx_client_server);
|
||||
ADD_TEST(test_ktls_client_server);
|
||||
ADD_TEST(test_ktls_no_client_server);
|
||||
ADD_TEST(test_ktls_client_no_server);
|
||||
ADD_TEST(test_ktls_no_client_no_server);
|
||||
#endif
|
||||
ADD_TEST(test_large_message_tls);
|
||||
ADD_TEST(test_large_message_tls_read_ahead);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/x509.h>
|
||||
@@ -177,6 +178,48 @@ static int test_store_ctx(void)
|
||||
|
||||
OPT_TEST_DECLARE_USAGE("roots.pem untrusted.pem bad.pem\n")
|
||||
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
static int test_sm2_id(void)
|
||||
{
|
||||
/* we only need an X509 structure, no matter if it's a real SM2 cert */
|
||||
X509 *x = NULL;
|
||||
BIO *bio = NULL;
|
||||
int ret = 0;
|
||||
ASN1_OCTET_STRING *v = NULL, *v2 = NULL;
|
||||
char *sm2id = "this is an ID";
|
||||
|
||||
bio = BIO_new_file(bad_f, "r");
|
||||
if (bio == NULL)
|
||||
goto err;
|
||||
|
||||
x = PEM_read_bio_X509(bio, NULL, 0, NULL);
|
||||
if (x == NULL)
|
||||
goto err;
|
||||
|
||||
v = ASN1_OCTET_STRING_new();
|
||||
if (v == NULL)
|
||||
goto err;
|
||||
|
||||
if (!ASN1_OCTET_STRING_set(v, (unsigned char *)sm2id, (int)strlen(sm2id))) {
|
||||
ASN1_OCTET_STRING_free(v);
|
||||
goto err;
|
||||
}
|
||||
|
||||
X509_set0_sm2_id(x, v);
|
||||
|
||||
v2 = X509_get0_sm2_id(x);
|
||||
if (!TEST_ptr(v2)
|
||||
|| !TEST_int_eq(ASN1_OCTET_STRING_cmp(v, v2), 0))
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
X509_free(x);
|
||||
BIO_free(bio);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int setup_tests(void)
|
||||
{
|
||||
if (!TEST_ptr(roots_f = test_get_argument(0))
|
||||
@@ -186,5 +229,8 @@ int setup_tests(void)
|
||||
|
||||
ADD_TEST(test_alt_chains_cert_forgery);
|
||||
ADD_TEST(test_store_ctx);
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
ADD_TEST(test_sm2_id);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user