Fix crash and latest update.

This commit is contained in:
2019-03-16 01:19:24 +09:00
parent ee0cf37f98
commit c03e0c45f8
168 changed files with 12859 additions and 1295 deletions
+2 -2
View File
@@ -396,7 +396,7 @@ static ASN1_INT64_DATA int64_expected[] = {
CUSTOM_EXPECTED_FAILURE, /* t_8bytes_3_pad (illegal padding) */
CUSTOM_EXPECTED_SUCCESS(INT64_MIN, INT64_MIN), /* t_8bytes_4_neg */
CUSTOM_EXPECTED_FAILURE, /* t_8bytes_5_negpad (illegal padding) */
CUSTOM_EXPECTED_SUCCESS(0x1ffffffff, 0x1ffffffff), /* t_5bytes_1 */
CUSTOM_EXPECTED_SUCCESS(0x1ffffffffULL, 0x1ffffffffULL), /* t_5bytes_1 */
CUSTOM_EXPECTED_SUCCESS(0x80000000, 0x80000000), /* t_4bytes_1 */
CUSTOM_EXPECTED_SUCCESS(INT32_MAX - 1, INT32_MAX -1), /* t_4bytes_2 */
CUSTOM_EXPECTED_FAILURE, /* t_4bytes_3_pad (illegal padding) */
@@ -446,7 +446,7 @@ static ASN1_UINT64_DATA uint64_expected[] = {
CUSTOM_EXPECTED_FAILURE, /* t_8bytes_3_pad */
CUSTOM_EXPECTED_FAILURE, /* t_8bytes_4_neg */
CUSTOM_EXPECTED_FAILURE, /* t_8bytes_5_negpad */
CUSTOM_EXPECTED_SUCCESS(0x1ffffffff, 0x1ffffffff), /* t_5bytes_1 */
CUSTOM_EXPECTED_SUCCESS(0x1ffffffffULL, 0x1ffffffffULL), /* t_5bytes_1 */
CUSTOM_EXPECTED_SUCCESS(0x80000000, 0x80000000), /* t_4bytes_1 */
CUSTOM_EXPECTED_SUCCESS(INT32_MAX - 1, INT32_MAX -1), /* t_4bytes_2 */
CUSTOM_EXPECTED_FAILURE, /* t_4bytes_3_pad (illegal padding) */
+4 -4
View File
@@ -146,14 +146,14 @@ typedef struct j_data_st {
} j_data;
static j_data jf_data[] = {
{ 0xffffffffffffffffU, "%ju", "18446744073709551615" },
{ 0xffffffffffffffffU, "%jx", "ffffffffffffffff" },
{ 0x8000000000000000U, "%ju", "9223372036854775808" },
{ 0xffffffffffffffffULL, "%ju", "18446744073709551615" },
{ 0xffffffffffffffffULL, "%jx", "ffffffffffffffff" },
{ 0x8000000000000000ULL, "%ju", "9223372036854775808" },
/*
* These tests imply two's-complement, but it's the only binary
* representation we support, see test/sanitytest.c...
*/
{ 0x8000000000000000U, "%ji", "-9223372036854775808" },
{ 0x8000000000000000ULL, "%ji", "-9223372036854775808" },
};
static int test_j(int i)
+103
View File
@@ -0,0 +1,103 @@
/*
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (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 <assert.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include "internal/nelem.h"
#include "internal/numbers.h"
#include "testutil.h"
#include "bn_prime.h"
#include "internal/bn_int.h"
static BN_CTX *ctx;
static int test_is_prime_enhanced(void)
{
int ret;
int status = 0;
BIGNUM *bn = NULL;
ret = TEST_ptr(bn = BN_new())
/* test passing a prime returns the correct status */
&& TEST_true(BN_set_word(bn, 11))
/* return extra parameters related to composite */
&& TEST_true(bn_miller_rabin_is_prime(bn, 10, ctx, NULL, 1, &status))
&& TEST_int_eq(status, BN_PRIMETEST_PROBABLY_PRIME);
BN_free(bn);
return ret;
}
static int composites[] = {
9, 21, 77, 81, 265
};
static int test_is_composite_enhanced(int id)
{
int ret;
int status = 0;
BIGNUM *bn = NULL;
ret = TEST_ptr(bn = BN_new())
/* negative tests for different composite numbers */
&& TEST_true(BN_set_word(bn, composites[id]))
&& TEST_true(bn_miller_rabin_is_prime(bn, 10, ctx, NULL, 1, &status))
&& TEST_int_ne(status, BN_PRIMETEST_PROBABLY_PRIME);
BN_free(bn);
return ret;
}
/* Test that multiplying all the small primes from 3 to 751 equals a constant.
* This test is mainly used to test that both 32 and 64 bit are correct.
*/
static int test_bn_small_factors(void)
{
int ret = 0, i;
BIGNUM *b = NULL;
if (!(TEST_ptr(b = BN_new()) && TEST_true(BN_set_word(b, 3))))
goto err;
for (i = 1; i < NUMPRIMES; i++) {
prime_t p = primes[i];
if (p > 3 && p <= 751)
BN_mul_word(b, p);
if (p > 751)
break;
}
ret = TEST_BN_eq(bn_get0_small_factors(), b);
err:
BN_free(b);
return ret;
}
int setup_tests(void)
{
if (!TEST_ptr(ctx = BN_CTX_new()))
return 0;
ADD_TEST(test_is_prime_enhanced);
ADD_ALL_TESTS(test_is_composite_enhanced, (int)OSSL_NELEM(composites));
ADD_TEST(test_bn_small_factors);
return 1;
}
void cleanup_tests(void)
{
BN_CTX_free(ctx);
}
+45 -3
View File
@@ -34,7 +34,7 @@ IF[{- !$disabled{tests} -}]
bftest ssltest_old dsatest dsa_no_digest_size_test exptest rsa_test \
evp_test evp_extra_test igetest v3nametest v3ext \
crltest danetest bad_dtls_test lhash_test sparse_array_test \
conf_include_test \
conf_include_test params_api_test \
constant_time_test verify_extra_test clienthellotest \
packettest asynctest secmemtest srptest memleaktest stack_test \
dtlsv1listentest ct_test threadstest afalgtest d2i_test \
@@ -50,7 +50,7 @@ IF[{- !$disabled{tests} -}]
time_offset_test pemtest ssl_cert_table_internal_test ciphername_test \
servername_test ocspapitest rsa_mp_test fatalerrtest tls13ccstest \
sysdefaulttest errtest gosttest \
context_internal_test aesgcmtest
context_internal_test aesgcmtest params_test
SOURCE[versions]=versions.c
INCLUDE[versions]=../include ../apps/include
@@ -307,6 +307,10 @@ IF[{- !$disabled{tests} -}]
INCLUDE[bioprinttest]=../include ../apps/include
DEPEND[bioprinttest]=../libcrypto libtestutil.a
SOURCE[params_api_test]=params_api_test.c
INCLUDE[params_api_test]=../include ../apps/include
DEPEND[params_api_test]=../libcrypto libtestutil.a
SOURCE[sslapitest]=sslapitest.c ssltestlib.c
INCLUDE[sslapitest]=../include ../apps/include ..
DEPEND[sslapitest]=../libcrypto ../libssl libtestutil.a
@@ -445,7 +449,9 @@ IF[{- !$disabled{tests} -}]
IF[1]
PROGRAMS{noinst}=asn1_internal_test modes_internal_test x509_internal_test \
tls13encryptiontest wpackettest ctype_internal_test \
rdrand_sanitytest property_test
rdrand_sanitytest property_test \
rsa_sp800_56b_test bn_internal_test
IF[{- !$disabled{poly1305} -}]
PROGRAMS{noinst}=poly1305_internal_test
ENDIF
@@ -528,6 +534,14 @@ IF[{- !$disabled{tests} -}]
SOURCE[rdrand_sanitytest]=rdrand_sanitytest.c
INCLUDE[rdrand_sanitytest]=../include ../apps/include
DEPEND[rdrand_sanitytest]=../libcrypto.a libtestutil.a
SOURCE[rsa_sp800_56b_test]=rsa_sp800_56b_test.c
INCLUDE[rsa_sp800_56b_test]=.. ../include ../crypto/include ../crypto/rsa ../apps/include
DEPEND[rsa_sp800_56b_test]=../libcrypto.a libtestutil.a
SOURCE[bn_internal_test]=bn_internal_test.c
INCLUDE[bn_internal_test]=.. ../include ../crypto/include ../crypto/bn ../apps/include
DEPEND[bn_internal_test]=../libcrypto.a libtestutil.a
ENDIF
IF[{- !$disabled{mdc2} -}]
@@ -578,6 +592,34 @@ IF[{- !$disabled{tests} -}]
SOURCE[context_internal_test]=context_internal_test.c
INCLUDE[context_internal_test]=.. ../include ../apps/include
DEPEND[context_internal_test]=../libcrypto.a libtestutil.a
PROGRAMS{noinst}=provider_internal_test
DEFINE[provider_internal_test]=PROVIDER_INIT_FUNCTION_NAME=p_test_init
SOURCE[provider_internal_test]=provider_internal_test.c p_test.c
INCLUDE[provider_internal_test]=../include ../apps/include
DEPEND[provider_internal_test]=../libcrypto.a libtestutil.a
PROGRAMS{noinst}=provider_test
DEFINE[provider_test]=PROVIDER_INIT_FUNCTION_NAME=p_test_init
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} -}]
MODULES{noinst}=p_test
SOURCE[p_test]=p_test.c
INCLUDE[p_test]=../include
IF[{- defined $target{shared_defflag} -}]
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
PROGRAMS{noinst}=params_test
SOURCE[params_test]=params_test.c
INCLUDE[params_test]=.. ../include ../apps/include
DEPEND[params_test]=../libcrypto.a libtestutil.a
ENDIF
{-
+2 -2
View File
@@ -63,7 +63,7 @@ static CT_TEST_FIXTURE *set_up(const char *const test_case_name)
if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
goto end;
fixture->test_case_name = test_case_name;
fixture->epoch_time_in_ms = 1473269626000; /* Sep 7 17:33:46 2016 GMT */
fixture->epoch_time_in_ms = 1473269626000ULL; /* Sep 7 17:33:46 2016 GMT */
if (!TEST_ptr(fixture->ctlog_store = CTLOG_STORE_new())
|| !TEST_int_eq(
CTLOG_STORE_load_default_file(fixture->ctlog_store), 1))
@@ -423,7 +423,7 @@ static int test_verify_fails_for_future_sct(void)
SETUP_CT_TEST_FIXTURE();
if (fixture == NULL)
return 0;
fixture->epoch_time_in_ms = 1365094800000; /* Apr 4 17:00:00 2013 GMT */
fixture->epoch_time_in_ms = 1365094800000ULL; /* Apr 4 17:00:00 2013 GMT */
fixture->certs_dir = certs_dir;
fixture->certificate_file = "embeddedSCTs1.pem";
fixture->issuer_file = "embeddedSCTs1_issuer.pem";
+70
View File
@@ -1440,6 +1440,75 @@ err:
BN_CTX_free(ctx);
return r;
}
/*
* Tests a point known to cause an incorrect underflow in an old version of
* ecp_nist521.c
*/
static int underflow_test(void)
{
BN_CTX *ctx = NULL;
EC_GROUP *grp = NULL;
EC_POINT *P = NULL, *Q = NULL, *R = NULL;
BIGNUM *x1 = NULL, *y1 = NULL, *z1 = NULL, *x2 = NULL, *y2 = NULL;
BIGNUM *k = NULL;
int testresult = 0;
const char *x1str =
"1534f0077fffffe87e9adcfe000000000000000000003e05a21d2400002e031b1f4"
"b80000c6fafa4f3c1288798d624a247b5e2ffffffffffffffefe099241900004";
const char *p521m1 =
"1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe";
ctx = BN_CTX_new();
if (!TEST_ptr(ctx))
return 0;
BN_CTX_start(ctx);
x1 = BN_CTX_get(ctx);
y1 = BN_CTX_get(ctx);
z1 = BN_CTX_get(ctx);
x2 = BN_CTX_get(ctx);
y2 = BN_CTX_get(ctx);
k = BN_CTX_get(ctx);
if (!TEST_ptr(k))
goto err;
grp = EC_GROUP_new_by_curve_name(NID_secp521r1);
P = EC_POINT_new(grp);
Q = EC_POINT_new(grp);
R = EC_POINT_new(grp);
if (!TEST_ptr(grp) || !TEST_ptr(P) || !TEST_ptr(Q) || !TEST_ptr(R))
goto err;
if (!TEST_int_gt(BN_hex2bn(&x1, x1str), 0)
|| !TEST_int_gt(BN_hex2bn(&y1, p521m1), 0)
|| !TEST_int_gt(BN_hex2bn(&z1, p521m1), 0)
|| !TEST_int_gt(BN_hex2bn(&k, "02"), 0)
|| !TEST_true(EC_POINT_set_Jprojective_coordinates_GFp(grp, P, x1,
y1, z1, ctx))
|| !TEST_true(EC_POINT_mul(grp, Q, NULL, P, k, ctx))
|| !TEST_true(EC_POINT_get_affine_coordinates(grp, Q, x1, y1, ctx))
|| !TEST_true(EC_POINT_dbl(grp, R, P, ctx))
|| !TEST_true(EC_POINT_get_affine_coordinates(grp, R, x2, y2, ctx)))
goto err;
if (!TEST_int_eq(BN_cmp(x1, x2), 0)
|| !TEST_int_eq(BN_cmp(y1, y2), 0))
goto err;
testresult = 1;
err:
BN_CTX_end(ctx);
EC_POINT_free(P);
EC_POINT_free(Q);
EC_POINT_free(R);
EC_GROUP_free(grp);
BN_CTX_free(ctx);
return testresult;
}
# endif
static const unsigned char p521_named[] = {
@@ -1547,6 +1616,7 @@ int setup_tests(void)
# endif
# ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
ADD_ALL_TESTS(nistp_single_test, OSSL_NELEM(nistp_tests_params));
ADD_TEST(underflow_test);
# endif
ADD_ALL_TESTS(internal_curve_test, crv_len);
ADD_ALL_TESTS(internal_curve_test_method, crv_len);
+110
View File
@@ -0,0 +1,110 @@
/*
* Copyright 2019 The OpenSSL Project Authors. 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
*/
/*
* This is a very simple provider that does absolutely nothing except respond
* to provider global parameter requests. It does this by simply echoing back
* a parameter request it makes to the loading library.
*/
#include <string.h>
#include <stdio.h>
/*
* When built as an object file to link the application with, we get the
* init function name through the macro PROVIDER_INIT_FUNCTION_NAME. If
* not defined, we use the standard init function name for the shared
* object form.
*/
#ifdef PROVIDER_INIT_FUNCTION_NAME
# define OSSL_provider_init PROVIDER_INIT_FUNCTION_NAME
#endif
#include <openssl/core.h>
#include <openssl/core_numbers.h>
static OSSL_core_get_param_types_fn *c_get_param_types = NULL;
static OSSL_core_get_params_fn *c_get_params = NULL;
/* Tell the core what params we provide and what type they are */
static const OSSL_ITEM p_param_types[] = {
{ OSSL_PARAM_UTF8_STRING, "greeting" },
{ 0, NULL }
};
static const OSSL_ITEM *p_get_param_types(const OSSL_PROVIDER *_)
{
return p_param_types;
}
static int p_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
{
const OSSL_PARAM *p = params;
int ok = 1;
for (; ok && p->key != NULL; p++) {
if (strcmp(p->key, "greeting") == 0) {
static char *opensslv = NULL;
static char *provname = NULL;
static OSSL_PARAM counter_request[] = {
{ "openssl-version", OSSL_PARAM_UTF8_PTR,
&opensslv, sizeof(&opensslv), NULL },
{ "provider-name", OSSL_PARAM_UTF8_PTR,
&provname, sizeof(&provname), 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);
} else {
sprintf(buf, "Howdy stranger...");
}
*p->return_size = buf_l = strlen(buf) + 1;
if (p->data_size >= buf_l)
strncpy(p->data, buf, buf_l);
else
ok = 0;
}
}
return ok;
}
static const OSSL_DISPATCH p_test_table[] = {
{ OSSL_FUNC_PROVIDER_GET_PARAM_TYPES, (void (*)(void))p_get_param_types },
{ OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))p_get_params },
{ 0, NULL }
};
int OSSL_provider_init(const OSSL_PROVIDER *provider,
const OSSL_DISPATCH *in,
const OSSL_DISPATCH **out)
{
for (; in->function_id != 0; in++) {
switch (in->function_id) {
case OSSL_FUNC_CORE_GET_PARAM_TYPES:
c_get_param_types = OSSL_get_core_get_param_types(in);
break;
case OSSL_FUNC_CORE_GET_PARAMS:
c_get_params = OSSL_get_core_get_params(in);
break;
default:
/* Just ignore anything we don't understand */
break;
}
}
*out = p_test_table;
return 1;
}
+627
View File
@@ -0,0 +1,627 @@
/*
* Copyright 2019 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 <string.h>
#include "testutil.h"
#include "internal/nelem.h"
#include <openssl/params.h>
#include <openssl/bn.h>
/* The maximum size of the static buffers used to test most things */
#define MAX_LEN 20
static void swap_copy(unsigned char *out, const void *in, size_t len)
{
size_t j;
for (j = 0; j < len; j++)
out[j] = ((unsigned char *)in)[len - j - 1];
}
static void copy_to_le(unsigned char *out, const void *in, size_t len)
{
#ifdef B_ENDIAN
swap_copy(out, in, len);
#else
memcpy(out, in, len);
#endif
}
static void copy_be_to_native(unsigned char *out, const void *in, size_t len)
{
#ifdef B_ENDIAN
memcpy(out, in, len);
#else
swap_copy(out, in, len);
#endif
}
static const struct {
size_t len;
unsigned char value[MAX_LEN];
} raw_values[] = {
{ 4, { 0x38, 0x27, 0xbf, 0x3b } },
{ 4, { 0x9f, 0x26, 0x48, 0x22 } },
{ 8, { 0x59, 0xb2, 0x1a, 0xe9, 0x2a, 0xd8, 0x46, 0x40 } },
{ 8, { 0xb4, 0xae, 0xbd, 0xb4, 0xdd, 0x04, 0xb1, 0x4c } },
{ 16, { 0x61, 0xe8, 0x7e, 0x31, 0xe9, 0x33, 0x83, 0x3d,
0x87, 0x99, 0xc7, 0xd8, 0x5d, 0xa9, 0x8b, 0x42 } },
{ 16, { 0xee, 0x6e, 0x8b, 0xc3, 0xec, 0xcf, 0x37, 0xcc,
0x89, 0x67, 0xf2, 0x68, 0x33, 0xa0, 0x14, 0xb0 } },
};
static int test_param_type_extra(const OSSL_PARAM *param, unsigned char *cmp,
size_t width)
{
int32_t i32;
int64_t i64;
size_t s, sz;
unsigned char buf[MAX_LEN];
const int bit32 = param->data_size == sizeof(int32_t);
const int sizet = bit32 && sizeof(size_t) > sizeof(int32_t);
const int signd = param->data_type == OSSL_PARAM_INTEGER;
if (signd) {
if ((bit32 && !TEST_true(OSSL_PARAM_get_int32(param, &i32)))
|| !TEST_true(OSSL_PARAM_get_int64(param, &i64)))
return 0;
} else {
if ((bit32
&& !TEST_true(OSSL_PARAM_get_uint32(param, (uint32_t *)&i32)))
|| !TEST_true(OSSL_PARAM_get_uint64(param, (uint64_t *)&i64))
|| (sizet && !TEST_true(OSSL_PARAM_get_size_t(param, &s))))
return 0;
}
/* Check signed types */
if (bit32) {
copy_to_le(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));
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));
sz = sizeof(s) < width ? sizeof(s) : width;
if (!TEST_mem_eq(buf, sz, cmp, sz))
return 0;
}
/* Check a widening write if possible */
if (sizeof(size_t) > width) {
if (signd) {
if (!TEST_true(OSSL_PARAM_set_int32(param, 12345))
|| !TEST_true(OSSL_PARAM_get_int64(param, &i64))
|| !TEST_size_t_eq(i64, 12345))
return 0;
} else {
if (!TEST_true(OSSL_PARAM_set_uint32(param, 12345))
|| !TEST_true(OSSL_PARAM_get_uint64(param, (uint64_t *)&i64))
|| !TEST_size_t_eq(i64, 12345))
return 0;
}
}
return 1;
}
/*
* The test cases for each of the bastic integral types are similar.
* For each type, a param of that type is set and an attempt to read it
* get is made. Finally, the above function is called to verify that
* the params can be read as other types.
*
* All the real work is done via byte buffers which are converted to machine
* byte order and to little endian for comparisons. Narrower values are best
* compared using little endian because their values and positions don't
* change.
*/
static int test_param_int(int n)
{
int in, out;
unsigned char buf[MAX_LEN], le[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);
memcpy(&in, buf, sizeof(in));
param.data = &out;
if (!TEST_true(OSSL_PARAM_set_int(&param, in)))
return 0;
copy_to_le(cmp, &out, sizeof(out));
if (!TEST_mem_eq(cmp, len, le, len))
return 0;
in = 0;
param.data = buf;
if (!TEST_true(OSSL_PARAM_get_int(&param, &in)))
return 0;
copy_to_le(cmp, &in, sizeof(in));
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
return 0;
param.data = &out;
return test_param_type_extra(&param, le, 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)];
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);
memcpy(&in, buf, sizeof(in));
param.data = &out;
if (!TEST_true(OSSL_PARAM_set_long(&param, in)))
return 0;
copy_to_le(cmp, &out, sizeof(out));
if (!TEST_mem_eq(cmp, len, le, len))
return 0;
in = 0;
param.data = buf;
if (!TEST_true(OSSL_PARAM_get_long(&param, &in)))
return 0;
copy_to_le(cmp, &in, sizeof(in));
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
return 0;
param.data = &out;
return test_param_type_extra(&param, le, 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)];
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);
memcpy(&in, buf, sizeof(in));
param.data = &out;
if (!TEST_true(OSSL_PARAM_set_uint(&param, in)))
return 0;
copy_to_le(cmp, &out, sizeof(out));
if (!TEST_mem_eq(cmp, len, le, len))
return 0;
in = 0;
param.data = buf;
if (!TEST_true(OSSL_PARAM_get_uint(&param, &in)))
return 0;
copy_to_le(cmp, &in, sizeof(in));
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
return 0;
param.data = &out;
return test_param_type_extra(&param, le, 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)];
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);
memcpy(&in, buf, sizeof(in));
param.data = &out;
if (!TEST_true(OSSL_PARAM_set_ulong(&param, in)))
return 0;
copy_to_le(cmp, &out, sizeof(out));
if (!TEST_mem_eq(cmp, len, le, len))
return 0;
in = 0;
param.data = buf;
if (!TEST_true(OSSL_PARAM_get_ulong(&param, &in)))
return 0;
copy_to_le(cmp, &in, sizeof(in));
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
return 0;
param.data = &out;
return test_param_type_extra(&param, le, 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)];
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);
memcpy(&in, buf, sizeof(in));
param.data = &out;
if (!TEST_true(OSSL_PARAM_set_int32(&param, in)))
return 0;
copy_to_le(cmp, &out, sizeof(out));
if (!TEST_mem_eq(cmp, len, le, len))
return 0;
in = 0;
param.data = buf;
if (!TEST_true(OSSL_PARAM_get_int32(&param, &in)))
return 0;
copy_to_le(cmp, &in, sizeof(in));
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
return 0;
param.data = &out;
return test_param_type_extra(&param, le, 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)];
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);
memcpy(&in, buf, sizeof(in));
param.data = &out;
if (!TEST_true(OSSL_PARAM_set_uint32(&param, in)))
return 0;
copy_to_le(cmp, &out, sizeof(out));
if (!TEST_mem_eq(cmp, len, le, len))
return 0;
in = 0;
param.data = buf;
if (!TEST_true(OSSL_PARAM_get_uint32(&param, &in)))
return 0;
copy_to_le(cmp, &in, sizeof(in));
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
return 0;
param.data = &out;
return test_param_type_extra(&param, le, 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)];
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);
memcpy(&in, buf, sizeof(in));
param.data = &out;
if (!TEST_true(OSSL_PARAM_set_int64(&param, in)))
return 0;
copy_to_le(cmp, &out, sizeof(out));
if (!TEST_mem_eq(cmp, len, le, len))
return 0;
in = 0;
param.data = buf;
if (!TEST_true(OSSL_PARAM_get_int64(&param, &in)))
return 0;
copy_to_le(cmp, &in, sizeof(in));
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
return 0;
param.data = &out;
return test_param_type_extra(&param, le, 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)];
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);
memcpy(&in, buf, sizeof(in));
param.data = &out;
if (!TEST_true(OSSL_PARAM_set_uint64(&param, in)))
return 0;
copy_to_le(cmp, &out, sizeof(out));
if (!TEST_mem_eq(cmp, len, le, len))
return 0;
in = 0;
param.data = buf;
if (!TEST_true(OSSL_PARAM_get_uint64(&param, &in)))
return 0;
copy_to_le(cmp, &in, sizeof(in));
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
return 0;
param.data = &out;
return test_param_type_extra(&param, le, 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)];
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);
memcpy(&in, buf, sizeof(in));
param.data = &out;
if (!TEST_true(OSSL_PARAM_set_size_t(&param, in)))
return 0;
copy_to_le(cmp, &out, sizeof(out));
if (!TEST_mem_eq(cmp, len, le, len))
return 0;
in = 0;
param.data = buf;
if (!TEST_true(OSSL_PARAM_get_size_t(&param, &in)))
return 0;
copy_to_le(cmp, &in, sizeof(in));
if (!TEST_mem_eq(cmp, sizeof(in), le, sizeof(in)))
return 0;
param.data = &out;
return test_param_type_extra(&param, le, sizeof(size_t));
}
static int test_param_bignum(int n)
{
unsigned char buf[MAX_LEN], bnbuf[MAX_LEN], le[MAX_LEN];
const size_t len = raw_values[n].len;
size_t bnsize;
BIGNUM *b = NULL, *c = NULL;
OSSL_PARAM param = OSSL_PARAM_DEFN("bn", OSSL_PARAM_UNSIGNED_INTEGER,
NULL, 0, NULL);
int ret = 0;
param.data = bnbuf;
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)))
goto err;
if (!TEST_true(OSSL_PARAM_set_BN(&param, b))
|| !TEST_mem_eq(bnbuf, bnsize, buf, bnsize))
goto err;
param.data_size = *param.return_size;
if (!TEST_true(OSSL_PARAM_get_BN(&param, &c))
|| !TEST_BN_eq(b, c))
goto err;
ret = 1;
err:
BN_free(b);
BN_free(c);
return ret;
}
static int test_param_real(void)
{
double p;
OSSL_PARAM param = OSSL_PARAM_double("r", NULL);
param.data = &p;
return TEST_true(OSSL_PARAM_set_double(&param, 3.14159))
&& TEST_double_eq(p, 3.14159);
}
/*
* The tests are a bit special in that they are trying to do both sides
* of the param passing. This means that the OSSL_PARAM structure needs to
* be updated so that a get call matches size with the corresponding set call.
* This is not a problem in normal usage because the owner of the OSSL_PARAM
* "knows" the size of what it wants to put in and gets the size back via the
* return_size pointer when it needs to get data out. That is, the owner
* does not need to call these APIs since it has direct access.
*
* The result is that the tests need the locate call to return a non-const
* pointer at times. Hence the cast here.
*/
static OSSL_PARAM *locate(OSSL_PARAM *p, const char *name)
{
return (OSSL_PARAM *)OSSL_PARAM_locate(p, name);
}
static int test_param_construct(void)
{
static const char *int_names[] = {
"int", "long", "int32", "int64"
};
static const char *uint_names[] = {
"uint", "ulong", "uint32", "uint64", "size_t"
};
static const unsigned char bn_val[16] = {
0xac, 0x75, 0x22, 0x7d, 0x81, 0x06, 0x7a, 0x23,
0xa6, 0xed, 0x87, 0xc7, 0xab, 0xf4, 0x73, 0x22
};
OSSL_PARAM params[20];
char buf[100], buf2[100], *bufp, *bufp2;
unsigned char ubuf[100];
void *vp, *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;
unsigned long int ul;
int32_t i32;
uint32_t u32;
int64_t i64;
uint64_t u64;
size_t j, k, s, sz;
double d, d2;
BIGNUM *bn = NULL, *bn2 = NULL;
params[n++] = OSSL_PARAM_construct_int("int", &i, &sz);
params[n++] = OSSL_PARAM_construct_uint("uint", &u, &sz);
params[n++] = OSSL_PARAM_construct_long("long", &l, &sz);
params[n++] = OSSL_PARAM_construct_ulong("ulong", &ul, &sz);
params[n++] = OSSL_PARAM_construct_int32("int32", &i32, &sz);
params[n++] = OSSL_PARAM_construct_int64("int64", &i64, &sz);
params[n++] = OSSL_PARAM_construct_uint32("uint32", &u32, &sz);
params[n++] = OSSL_PARAM_construct_uint64("uint64", &u64, &sz);
params[n++] = OSSL_PARAM_construct_size_t("size_t", &s, &sz);
params[n++] = OSSL_PARAM_construct_double("double", &d, &sz);
params[n++] = OSSL_PARAM_construct_BN("bignum", ubuf, sizeof(ubuf), &sz);
params[n++] = OSSL_PARAM_construct_utf8_string("utf8str", buf, sizeof(buf),
&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;
/* Search failure */
if (!TEST_ptr_null(OSSL_PARAM_locate(params, "fnord")))
goto err;
/* All signed integral types */
for (j = 0; j < OSSL_NELEM(int_names); j++) {
if (!TEST_ptr(cp = OSSL_PARAM_locate(params, int_names[j]))
|| !TEST_true(OSSL_PARAM_set_int32(cp, (int32_t)(3 + j)))
|| !TEST_true(OSSL_PARAM_get_int64(cp, &i64))
|| !TEST_size_t_eq(cp->data_size, sz)
|| !TEST_size_t_eq((size_t)i64, 3 + j)) {
TEST_note("iteration %zu var %s", j + 1, int_names[j]);
goto err;
}
}
/* All unsigned integral types */
for (j = 0; j < OSSL_NELEM(uint_names); j++) {
if (!TEST_ptr(cp = OSSL_PARAM_locate(params, uint_names[j]))
|| !TEST_true(OSSL_PARAM_set_uint32(cp, (uint32_t)(3 + j)))
|| !TEST_true(OSSL_PARAM_get_uint64(cp, &u64))
|| !TEST_size_t_eq(cp->data_size, sz)
|| !TEST_size_t_eq((size_t)u64, 3 + j)) {
TEST_note("iteration %zu var %s", j + 1, uint_names[j]);
goto err;
}
}
/* Real */
if (!TEST_ptr(cp = OSSL_PARAM_locate(params, "double"))
|| !TEST_true(OSSL_PARAM_set_double(cp, 3.14))
|| !TEST_true(OSSL_PARAM_get_double(cp, &d2))
|| !TEST_size_t_eq(sz, sizeof(double))
|| !TEST_double_eq(d, d2))
goto err;
/* UTF8 string */
bufp = NULL;
if (!TEST_ptr(cp = OSSL_PARAM_locate(params, "utf8str"))
|| !TEST_true(OSSL_PARAM_set_utf8_string(cp, "abcdef"))
|| !TEST_size_t_eq(sz, sizeof("abcdef"))
|| !TEST_true(OSSL_PARAM_get_utf8_string(cp, &bufp, 0))
|| !TEST_str_eq(bufp, "abcdef"))
goto err;
OPENSSL_free(bufp);
bufp = buf2;
if (!TEST_true(OSSL_PARAM_get_utf8_string(cp, &bufp, sizeof(buf2)))
|| !TEST_str_eq(buf2, "abcdef"))
goto err;
/* UTF8 pointer */
bufp = buf;
sz = 0;
if (!TEST_ptr(cp = OSSL_PARAM_locate(params, "utf8ptr"))
|| !TEST_true(OSSL_PARAM_set_utf8_ptr(cp, "tuvwxyz"))
|| !TEST_size_t_eq(sz, sizeof("tuvwxyz"))
|| !TEST_str_eq(bufp, "tuvwxyz")
|| !TEST_true(OSSL_PARAM_get_utf8_ptr(cp, (const char **)&bufp2))
|| !TEST_ptr_eq(bufp2, bufp))
goto err;
/* OCTET string */
vp = NULL;
if (!TEST_ptr(p = locate(params, "octstr"))
|| !TEST_true(OSSL_PARAM_set_octet_string(p, "abcdefghi",
sizeof("abcdefghi")))
|| !TEST_size_t_eq(sz, sizeof("abcdefghi")))
goto err;
/* Match the return size to avoid trailing garbage bytes */
p->data_size = *p->return_size;
if (!TEST_true(OSSL_PARAM_get_octet_string(p, &vp, 0, &s))
|| !TEST_size_t_eq(s, sizeof("abcdefghi"))
|| !TEST_mem_eq(vp, sizeof("abcdefghi"),
"abcdefghi", sizeof("abcdefghi")))
goto err;
OPENSSL_free(vp);
vp = buf2;
if (!TEST_true(OSSL_PARAM_get_octet_string(p, &vp, sizeof(buf2), &s))
|| !TEST_size_t_eq(s, sizeof("abcdefghi"))
|| !TEST_mem_eq(vp, sizeof("abcdefghi"),
"abcdefghi", sizeof("abcdefghi")))
goto err;
/* OCTET pointer */
vp = &l;
sz = 0;
if (!TEST_ptr(p = locate(params, "octptr"))
|| !TEST_true(OSSL_PARAM_set_octet_ptr(p, &ul, sizeof(ul)))
|| !TEST_size_t_eq(sz, sizeof(ul))
|| !TEST_ptr_eq(vp, &ul))
goto err;
/* Match the return size to avoid trailing garbage bytes */
p->data_size = *p->return_size;
if (!TEST_true(OSSL_PARAM_get_octet_ptr(p, (const void **)&vp2, &k))
|| !TEST_size_t_eq(k, sizeof(ul))
|| !TEST_ptr_eq(vp2, vp))
goto err;
/* BIGNUM */
if (!TEST_ptr(p = locate(params, "bignum"))
|| !TEST_ptr(bn = BN_lebin2bn(bn_val, (int)sizeof(bn_val), NULL))
|| !TEST_true(OSSL_PARAM_set_BN(p, bn))
|| !TEST_size_t_eq(sz, sizeof(bn_val)))
goto err;
/* Match the return size to avoid trailing garbage bytes */
p->data_size = *p->return_size;
if(!TEST_true(OSSL_PARAM_get_BN(p, &bn2))
|| !TEST_BN_eq(bn, bn2))
goto err;
ret = 1;
err:
BN_free(bn);
BN_free(bn2);
return ret;
}
int setup_tests(void)
{
ADD_ALL_TESTS(test_param_int, OSSL_NELEM(raw_values));
ADD_ALL_TESTS(test_param_long, OSSL_NELEM(raw_values));
ADD_ALL_TESTS(test_param_uint, OSSL_NELEM(raw_values));
ADD_ALL_TESTS(test_param_ulong, OSSL_NELEM(raw_values));
ADD_ALL_TESTS(test_param_int32, OSSL_NELEM(raw_values));
ADD_ALL_TESTS(test_param_uint32, OSSL_NELEM(raw_values));
ADD_ALL_TESTS(test_param_size_t, OSSL_NELEM(raw_values));
ADD_ALL_TESTS(test_param_int64, OSSL_NELEM(raw_values));
ADD_ALL_TESTS(test_param_uint64, OSSL_NELEM(raw_values));
ADD_ALL_TESTS(test_param_bignum, OSSL_NELEM(raw_values));
ADD_TEST(test_param_real);
ADD_TEST(test_param_construct);
return 1;
}
+549
View File
@@ -0,0 +1,549 @@
/*
* Copyright 2019 The OpenSSL Project Authors. 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 may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
/*
* This program tests the use of OSSL_PARAM, currently in raw form.
*/
#include <string.h>
#include <openssl/bn.h>
#include <openssl/core.h>
#include <openssl/params.h>
#include "internal/nelem.h"
#include "testutil.h"
/*-
* PROVIDER SECTION
* ================
*
* Even though it's not necessarily ONLY providers doing this part,
* they are naturally going to be the most common users of
* set_params and get_params functions.
*/
/*
* In real use cases, setters and getters would take an object with
* which the parameters are associated. This structure is a cheap
* simulation.
*/
struct object_st {
/*
* Documented as a native integer, of the size given by sizeof(int).
* Assumed data type OSSL_PARAM_INTEGER
*/
int p1;
/*
* Documented as a native double, of the size given by sizeof(double).
* Assumed data type OSSL_PARAM_REAL
*/
double p2;
/*
* Documented as an arbitrarly large unsigned integer.
* The data size must be large enough to accomodate.
* Assumed data type OSSL_PARAM_UNSIGNED_INTEGER
*/
BIGNUM *p3;
/*
* Documented as a C string.
* The data size must be large enough to accomodate.
* Assumed data type OSSL_PARAM_UTF8_STRING
*/
char *p4;
size_t p4_l;
/*
* Documented as a C string.
* Assumed data type OSSL_PARAM_UTF8_STRING
*/
char p5[256];
size_t p5_l;
/*
* Documented as a pointer to a constant C string.
* Assumed data type OSSL_PARAM_UTF8_PTR
*/
const char *p6;
size_t p6_l;
};
#define p1_init 42 /* The ultimate answer */
#define p2_init 6.283 /* Magic number */
/* Stolen from evp_data, BLAKE2s256 test */
#define p3_init \
"4142434445464748494a4b4c4d4e4f50" \
"5152535455565758595a616263646566" \
"6768696a6b6c6d6e6f70717273747576" \
"7778797a30313233343536373839"
#define p4_init "BLAKE2s256" /* Random string */
#define p5_init "Hellow World" /* Random string */
#define p6_init OPENSSL_FULL_VERSION_STR /* Static string */
static void cleanup_object(void *vobj)
{
struct object_st *obj = vobj;
BN_free(obj->p3);
obj->p3 = NULL;
OPENSSL_free(obj->p4);
obj->p4 = NULL;
OPENSSL_free(obj);
}
static void *init_object(void)
{
struct object_st *obj = OPENSSL_zalloc(sizeof(*obj));
obj->p1 = p1_init;
obj->p2 = p2_init;
if (!TEST_true(BN_hex2bn(&obj->p3, p3_init)))
goto fail;
if (!TEST_ptr(obj->p4 = OPENSSL_strdup(p4_init)))
goto fail;
strcpy(obj->p5, p5_init);
obj->p6 = p6_init;
return obj;
fail:
cleanup_object(obj);
obj = NULL;
return NULL;
}
/*
* RAW provider, which handles the parameters in a very raw manner,
* with no fancy API and very minimal checking. The application that
* calls these to set or request parameters MUST get its OSSL_PARAM
* array right.
*/
static int raw_set_params(void *vobj, const OSSL_PARAM *params)
{
struct object_st *obj = vobj;
for (; params->key != NULL; params++)
if (strcmp(params->key, "p1") == 0) {
obj->p1 = *(int *)params->data;
} else if (strcmp(params->key, "p2") == 0) {
obj->p2 = *(double *)params->data;
} else if (strcmp(params->key, "p3") == 0) {
BN_free(obj->p3);
if (!TEST_ptr(obj->p3 = BN_native2bn(params->data,
params->data_size, NULL)))
return 0;
} else if (strcmp(params->key, "p4") == 0) {
OPENSSL_free(obj->p4);
if (!TEST_ptr(obj->p4 = OPENSSL_strndup(params->data,
params->data_size)))
return 0;
} else if (strcmp(params->key, "p5") == 0) {
strncpy(obj->p5, params->data, params->data_size);
} else if (strcmp(params->key, "p6") == 0) {
obj->p6 = *(const char **)params->data;
}
return 1;
}
static int raw_get_params(void *vobj, const OSSL_PARAM *params)
{
struct object_st *obj = vobj;
for (; params->key != NULL; params++)
if (strcmp(params->key, "p1") == 0) {
if (params->return_size != NULL)
*params->return_size = sizeof(obj->p1);
*(int *)params->data = obj->p1;
} else if (strcmp(params->key, "p2") == 0) {
if (params->return_size != NULL)
*params->return_size = sizeof(obj->p2);
*(double *)params->data = obj->p2;
} else if (strcmp(params->key, "p3") == 0) {
size_t bytes = BN_num_bytes(obj->p3);
if (params->return_size != NULL)
*params->return_size = bytes;
if (!TEST_size_t_ge(params->data_size, bytes))
return 0;
BN_bn2nativepad(obj->p3, params->data, bytes);
} else if (strcmp(params->key, "p4") == 0) {
size_t bytes = strlen(obj->p4) + 1;
if (params->return_size != NULL)
*params->return_size = bytes;
if (!TEST_size_t_ge(params->data_size, bytes))
return 0;
strcpy(params->data, obj->p4);
} else if (strcmp(params->key, "p5") == 0) {
size_t bytes = strlen(obj->p5) + 1;
if (params->return_size != NULL)
*params->return_size = bytes;
if (!TEST_size_t_ge(params->data_size, bytes))
return 0;
strcpy(params->data, obj->p5);
} else if (strcmp(params->key, "p6") == 0) {
/*
* We COULD also use OPENSSL_FULL_VERSION_STR directly and
* use sizeof(OPENSSL_FULL_VERSION_STR) instead of calling
* strlen().
* The caller wouldn't know the difference.
*/
size_t bytes = strlen(obj->p6) + 1;
if (params->return_size != NULL)
*params->return_size = bytes;
*(const char **)params->data = obj->p6;
}
return 1;
}
/*
* API provider, which handles the parameters using the API from params.h
*/
static int api_set_params(void *vobj, const OSSL_PARAM *params)
{
struct object_st *obj = vobj;
const OSSL_PARAM *p = NULL;
if ((p = OSSL_PARAM_locate(params, "p1")) != NULL
&& !TEST_true(OSSL_PARAM_get_int(p, &obj->p1)))
return 0;
if ((p = OSSL_PARAM_locate(params, "p2")) != NULL
&& !TEST_true(OSSL_PARAM_get_double(p, &obj->p2)))
return 0;
if ((p = OSSL_PARAM_locate(params, "p3")) != NULL
&& !TEST_true(OSSL_PARAM_get_BN(p, &obj->p3)))
return 0;
if ((p = OSSL_PARAM_locate(params, "p4")) != NULL) {
OPENSSL_free(obj->p4);
obj->p4 = NULL;
/* If the value pointer is NULL, we get it automatically allocated */
if (!TEST_true(OSSL_PARAM_get_utf8_string(p, &obj->p4, 0)))
return 0;
}
if ((p = OSSL_PARAM_locate(params, "p5")) != NULL) {
char *p5_ptr = obj->p5;
if (!TEST_true(OSSL_PARAM_get_utf8_string(p, &p5_ptr, sizeof(obj->p5))))
return 0;
}
if ((p = OSSL_PARAM_locate(params, "p6")) != NULL
&& !TEST_true(OSSL_PARAM_get_utf8_ptr(p, &obj->p6)))
return 0;
return 1;
}
static int api_get_params(void *vobj, const OSSL_PARAM *params)
{
struct object_st *obj = vobj;
const OSSL_PARAM *p = NULL;
if ((p = OSSL_PARAM_locate(params, "p1")) != NULL
&& !TEST_true(OSSL_PARAM_set_int(p, obj->p1)))
return 0;
if ((p = OSSL_PARAM_locate(params, "p2")) != NULL
&& !TEST_true(OSSL_PARAM_set_double(p, obj->p2)))
return 0;
if ((p = OSSL_PARAM_locate(params, "p3")) != NULL
&& !TEST_true(OSSL_PARAM_set_BN(p, obj->p3)))
return 0;
if ((p = OSSL_PARAM_locate(params, "p4")) != NULL
&& !TEST_true(OSSL_PARAM_set_utf8_string(p, obj->p4)))
return 0;
if ((p = OSSL_PARAM_locate(params, "p5")) != NULL
&& !TEST_true(OSSL_PARAM_set_utf8_string(p, obj->p5)))
return 0;
if ((p = OSSL_PARAM_locate(params, "p6")) != NULL
&& !TEST_true(OSSL_PARAM_set_utf8_ptr(p, obj->p6)))
return 0;
return 1;
}
/*
* This structure only simulates a provider dispatch, the real deal is
* a bit more code that's not necessary in these tests.
*/
struct provider_dispatch_st {
int (*set_params)(void *obj, const OSSL_PARAM *params);
int (*get_params)(void *obj, const OSSL_PARAM *params);
};
/* "raw" provider */
static const struct provider_dispatch_st provider_raw = {
raw_set_params, raw_get_params
};
/* "api" provider */
static const struct provider_dispatch_st provider_api = {
api_set_params, api_get_params
};
/*-
* APPLICATION SECTION
* ===================
*/
/* In all our tests, these are variables that get manipulated as parameters
*
* These arrays consistenly do nothing with the "p2" parameter, and
* always include a "foo" parameter. This is to check that the
* set_params and get_params calls ignore the lack of parameters that
* the application isn't interested in, as well as ignore parameters
* they don't understand (the application may have one big bag of
* parameters).
*/
static int app_p1; /* "p1" */
static double app_p2; /* "p2" is ignored */
static BIGNUM *app_p3 = NULL; /* "p3" */
static unsigned char bignumbin[4096]; /* "p3" */
static size_t bignumbin_l; /* "p3" */
static char app_p4[256]; /* "p4" */
static size_t app_p4_l; /* "p4" */
static char app_p5[256]; /* "p5" */
static size_t app_p5_l; /* "p5" */
static const char *app_p6 = NULL; /* "p6" */
static size_t app_p6_l; /* "p6" */
static unsigned char foo[1]; /* "foo" */
static size_t foo_l; /* "foo" */
#define app_p1_init 17 /* A random number */
#define app_p2_init 47.11 /* Another random number */
#define app_p3_init "deadbeef" /* Classic */
#define app_p4_init "Hello"
#define app_p5_init "World"
#define app_p6_init "Cookie"
#define app_foo_init 'z'
static int cleanup_app_variables(void)
{
BN_free(app_p3);
app_p3 = NULL;
return 1;
}
static int init_app_variables(void)
{
int l = 0;
cleanup_app_variables();
app_p1 = app_p1_init;
app_p2 = app_p2_init;
if (!BN_hex2bn(&app_p3, app_p3_init)
|| (l = BN_bn2nativepad(app_p3, bignumbin, sizeof(bignumbin))) < 0)
return 0;
bignumbin_l = (size_t)l;
strcpy(app_p4, app_p4_init);
app_p4_l = sizeof(app_p4_init);
strcpy(app_p5, app_p5_init);
app_p5_l = sizeof(app_p5_init);
app_p6 = app_p6_init;
foo[0] = app_foo_init;
foo_l = sizeof(app_foo_init);
return 1;
}
/*
* Here, we define test OSSL_PARAM arrays
*/
/* An array of OSSL_PARAM, specific in the most raw manner possible */
static const OSSL_PARAM static_raw_params[] = {
{ "p1", OSSL_PARAM_INTEGER, &app_p1, sizeof(app_p1), NULL },
{ "p3", OSSL_PARAM_UNSIGNED_INTEGER, &bignumbin, sizeof(bignumbin),
&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 },
{ "foo", OSSL_PARAM_OCTET_STRING, &foo, sizeof(foo), &foo_l },
{ NULL, 0, NULL, 0, NULL }
};
/* The same array of OSSL_PARAM, specified with the macros from params.h */
static const OSSL_PARAM static_api_params[] = {
OSSL_PARAM_int("p1", &app_p1),
OSSL_PARAM_SIZED_BN("p3", &bignumbin, sizeof(bignumbin), bignumbin_l),
OSSL_PARAM_DEFN("p4", OSSL_PARAM_UTF8_STRING,
&app_p4, sizeof(app_p4), &app_p4_l),
OSSL_PARAM_DEFN("p5", OSSL_PARAM_UTF8_STRING,
&app_p5, sizeof(app_p5), &app_p5_l),
OSSL_PARAM_DEFN("p6", OSSL_PARAM_UTF8_PTR,
&app_p6, sizeof(app_p6), &app_p6_l),
OSSL_PARAM_DEFN("foo", OSSL_PARAM_OCTET_STRING, &foo, sizeof(foo), &foo_l),
OSSL_PARAM_END
};
/*
* The same array again, but constructed at run-time
* This exercises the OSSL_PARAM constructor functions
*/
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),
&bignumbin_l);
params[n++] = OSSL_PARAM_construct_utf8_string("p4", app_p4, sizeof(app_p4),
&app_p4_l);
params[n++] = OSSL_PARAM_construct_utf8_string("p5", app_p5,
sizeof(app_p5), &app_p5_l);
params[n++] = OSSL_PARAM_construct_utf8_ptr("p6", (char **)&app_p6,
&app_p6_l);
params[n++] = OSSL_PARAM_construct_octet_string("foo", &foo, sizeof(foo),
&foo_l);
params[n++] = param_end;
return params;
}
struct param_owner_st {
const OSSL_PARAM *static_params;
OSSL_PARAM *(*constructed_params)(void);
};
static const struct param_owner_st raw_params = {
static_raw_params, NULL
};
static const struct param_owner_st api_params = {
static_api_params, construct_api_params
};
/*-
* TESTING
* =======
*/
/*
* Test cases to combine parameters with "provider side" functions
*/
static struct {
const struct provider_dispatch_st *prov;
const struct param_owner_st *app;
const char *desc;
} test_cases[] = {
/* Tests within specific methods */
{ &provider_raw, &raw_params, "raw provider vs raw params" },
{ &provider_api, &api_params, "api provider vs api params" },
/* Mixed methods */
{ &provider_raw, &api_params, "raw provider vs api params" },
{ &provider_api, &raw_params, "api provider vs raw params" },
};
/* Generic tester of combinations of "providers" and params */
static int test_case_variant(const OSSL_PARAM *params,
const struct provider_dispatch_st *prov)
{
BIGNUM *verify_p3 = NULL;
void *obj = NULL;
int errcnt = 0;
/*
* Initialize
*/
if (!TEST_ptr(obj = init_object())
|| !TEST_true(BN_hex2bn(&verify_p3, p3_init))) {
errcnt++;
goto fin;
}
/*
* Get parameters a first time, just to see that getting works and
* gets us the values we expect.
*/
init_app_variables();
if (!TEST_true(prov->get_params(obj, params))
|| !TEST_int_eq(app_p1, p1_init) /* "provider" value */
|| !TEST_double_eq(app_p2, app_p2_init) /* Should remain untouched */
|| !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_str_eq(app_p5, p5_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)))
errcnt++;
/*
* Set parameters, then sneak into the object itself and check
* that its attributes got set (or ignored) properly.
*/
init_app_variables();
if (!TEST_true(prov->set_params(obj, params))) {
errcnt++;
} else {
struct object_st *sneakpeek = obj;
if (!TEST_int_eq(sneakpeek->p1, app_p1) /* app value set */
|| !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 */
errcnt++;
}
/*
* Get parameters again, checking that we get different values
* than earlier where relevant.
*/
BN_free(verify_p3);
verify_p3 = NULL;
if (!TEST_true(BN_hex2bn(&verify_p3, app_p3_init))) {
errcnt++;
goto fin;
}
if (!TEST_true(prov->get_params(obj, params))
|| !TEST_int_eq(app_p1, app_p1_init) /* app value */
|| !TEST_double_eq(app_p2, app_p2_init) /* Should remain untouched */
|| !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_str_eq(app_p5, app_p5_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)))
errcnt++;
fin:
BN_free(verify_p3);
verify_p3 = NULL;
cleanup_app_variables();
cleanup_object(obj);
return errcnt == 0;
}
static int test_case(int i)
{
TEST_info("Case: %s", test_cases[i].desc);
return test_case_variant(test_cases[i].app->static_params,
test_cases[i].prov)
&& (test_cases[i].app->constructed_params == NULL
|| test_case_variant(test_cases[i].app->constructed_params(),
test_cases[i].prov));
}
int setup_tests(void)
{
ADD_ALL_TESTS(test_case, OSSL_NELEM(test_cases));
return 1;
}
+84
View File
@@ -0,0 +1,84 @@
/*
* Copyright 2019 The OpenSSL Project Authors. 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 <stddef.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];
static size_t buf_l = 0;
static OSSL_PARAM greeting_request[] = {
{ "greeting", OSSL_PARAM_UTF8_STRING, buf, sizeof(buf), &buf_l },
{ NULL, 0, NULL, 0, NULL }
};
static int test_provider(OSSL_PROVIDER *prov)
{
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;
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))
&& TEST_ptr(greeting = greeting_request[0].data)
&& TEST_size_t_gt(greeting_request[0].data_size, 0)
&& TEST_str_eq(greeting, expected_greeting);
ossl_provider_free(prov);
return ret;
}
static int test_builtin_provider(void)
{
const char *name = "p_test_builtin";
OSSL_PROVIDER *prov = NULL;
return
TEST_ptr(prov =
ossl_provider_new(NULL, name, PROVIDER_INIT_FUNCTION_NAME))
&& test_provider(prov);
}
#ifndef OPENSSL_NO_DSO
static int test_loaded_provider(void)
{
const char *name = "p_test";
OSSL_PROVIDER *prov = NULL;
return
TEST_ptr(prov = ossl_provider_new(NULL, name, NULL))
&& test_provider(prov);
}
#endif
int setup_tests(void)
{
ADD_TEST(test_builtin_provider);
#ifndef OPENSSL_NO_DSO
ADD_TEST(test_loaded_provider);
#endif
return 1;
}
+75
View File
@@ -0,0 +1,75 @@
/*
* Copyright 2019 The OpenSSL Project Authors. 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 <stddef.h>
#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];
static size_t buf_l = 0;
static OSSL_PARAM greeting_request[] = {
{ "greeting", OSSL_PARAM_UTF8_STRING, buf, sizeof(buf), &buf_l },
{ NULL, 0, NULL, 0, NULL }
};
static int test_provider(const char *name)
{
OSSL_PROVIDER *prov = NULL;
const char *greeting = NULL;
char expected_greeting[256];
snprintf(expected_greeting, sizeof(expected_greeting),
"Hello OpenSSL %.20s, greetings from %s!",
OPENSSL_VERSION_STR, name);
return
TEST_ptr(prov = OSSL_PROVIDER_load(NULL, name))
&& TEST_true(OSSL_PROVIDER_get_params(prov, greeting_request))
&& TEST_ptr(greeting = greeting_request[0].data)
&& TEST_size_t_gt(greeting_request[0].data_size, 0)
&& TEST_str_eq(greeting, expected_greeting)
&& TEST_true(OSSL_PROVIDER_unload(prov));
}
static int test_builtin_provider(void)
{
const char *name = "p_test_builtin";
return
TEST_true(OSSL_PROVIDER_add_builtin(NULL, name,
PROVIDER_INIT_FUNCTION_NAME))
&& test_provider(name);
}
#ifndef OPENSSL_NO_DSO
static int test_loaded_provider(void)
{
const char *name = "p_test";
return test_provider(name);
}
#endif
int setup_tests(void)
{
ADD_TEST(test_builtin_provider);
#ifndef OPENSSL_NO_DSO
ADD_TEST(test_loaded_provider);
#endif
return 1;
}
+18
View File
@@ -0,0 +1,18 @@
#! /usr/bin/env perl
# Copyright 2019 The OpenSSL Project Authors. 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
use strict;
use OpenSSL::Test qw(:DEFAULT bldtop_dir);
use OpenSSL::Test::Simple;
use OpenSSL::Test::Utils;
setup("test_internal_provider");
$ENV{"OPENSSL_MODULES"} = bldtop_dir("test");
simple_test("test_internal_provider", "provider_internal_test");
+19
View File
@@ -0,0 +1,19 @@
#! /usr/bin/env perl
# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (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
use strict;
use OpenSSL::Test; # get 'plan'
use OpenSSL::Test::Simple;
use OpenSSL::Test::Utils;
setup("test_internal_bn");
plan skip_all => "This test is unsupported in a shared library build on Windows"
if $^O eq 'MSWin32' && !disabled("shared");
simple_test("test_internal_bn", "bn_internal_test");
@@ -0,0 +1,19 @@
#! /usr/bin/env perl
# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (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
use strict;
use OpenSSL::Test; # get 'plan'
use OpenSSL::Test::Simple;
use OpenSSL::Test::Utils;
setup("test_internal_rsa_sp800_56b");
plan skip_all => "This test is unsupported in a shared library build on Windows"
if $^O eq 'MSWin32' && !disabled("shared");
simple_test("test_internal_rsa_sp800_56b", "rsa_sp800_56b_test");
+12
View File
@@ -0,0 +1,12 @@
#! /usr/bin/env perl
# Copyright 2019 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
use OpenSSL::Test::Simple;
simple_test("test_params_api", "params_api_test");
+15
View File
@@ -0,0 +1,15 @@
#! /usr/bin/env perl
# Copyright 2019 The OpenSSL Project Authors. 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
use strict;
use OpenSSL::Test;
use OpenSSL::Test::Simple;
setup("test_params");
simple_test("test_params", "params_test");
+18
View File
@@ -0,0 +1,18 @@
#! /usr/bin/env perl
# Copyright 2019 The OpenSSL Project Authors. 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
use strict;
use OpenSSL::Test qw(:DEFAULT bldtop_dir);
use OpenSSL::Test::Simple;
use OpenSSL::Test::Utils;
setup("test_provider");
$ENV{"OPENSSL_MODULES"} = bldtop_dir("test");
simple_test("test_provider", "provider_test");
+194
View File
@@ -0,0 +1,194 @@
#! /usr/bin/env perl
# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (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
use strict;
use warnings;
use OpenSSL::Test;
use OpenSSL::Test::Utils;
use Storable qw(dclone);
setup("test_mac");
my @mac_tests = (
{ cmd => [qw{openssl mac -macopt digest:SHA1 -macopt hexkey:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F}],
type => 'HMAC',
input => unpack("H*", "Sample message for keylen=blocklen"),
expected => '5FD596EE78D5553C8FF4E72D266DFD192366DA29',
desc => 'HMAC SHA1' },
{ cmd => [qw{openssl mac -macopt cipher:AES-256-GCM -macopt hexkey:4C973DBC7364621674F8B5B89E5C15511FCED9216490FB1C1A2CAA0FFE0407E5 -macopt hexiv:7AE8E2CA4EC500012E58495C}],
type => 'GMAC',
input => '68F2E77696CE7AE8E2CA4EC588E541002E58495C08000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D0007',
expected => '00BDA1B7E87608BCBF470F12157F4C07',
desc => 'GMAC' },
{ cmd => [qw{openssl mac -macopt hexkey:404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F -macopt xof:0}],
type => 'KMAC128',
input => '00010203',
expected => 'E5780B0D3EA6F7D3A429C5706AA43A00FADBD7D49628839E3187243F456EE14E',
desc => 'KMAC128' },
{ cmd => [qw{openssl mac -macopt hexkey:404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F -macopt }, 'custom:My Tagged Application'],
type => 'KMAC256',
input => '00010203',
expected => '20C570C31346F703C9AC36C61C03CB64C3970D0CFC787E9B79599D273A68D2F7F69D4CC3DE9D104A351689F27CF6F5951F0103F33F4F24871024D9C27773A8DD',
desc => 'KMAC256' },
{ cmd => [qw{openssl mac -macopt hexkey:404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F -macopt xof:1 -macopt}, 'custom:My Tagged Application'],
type => 'KMAC256',
input => '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7',
expected => 'D5BE731C954ED7732846BB59DBE3A8E30F83E77A4BFF4459F2F1C2B4ECEBB8CE67BA01C62E8AB8578D2D499BD1BB276768781190020A306A97DE281DCC30305D',
desc => 'KMAC256 with xof len of 64' },
);
my @siphash_tests = (
{ cmd => [qw{openssl mac -macopt hexkey:000102030405060708090A0B0C0D0E0F}],
type => 'SipHash',
input => '00',
expected => 'da87c1d86b99af44347659119b22fc45',
desc => 'SipHash No input' }
);
my @cmac_tests = (
{ cmd => [qw{openssl mac -macopt cipher:AES-256-CBC -macopt hexkey:0B122AC8F34ED1FE082A3625D157561454167AC145A10BBF77C6A70596D574F1}],
type => 'CMAC',
input => '498B53FDEC87EDCBF07097DCCDE93A084BAD7501A224E388DF349CE18959FE8485F8AD1537F0D896EA73BEDC7214713F',
expected => 'F62C46329B41085625669BAF51DEA66A',
desc => 'CMAC AES-256-CBC' }
);
my @poly1305_tests = (
{ cmd => [qw{openssl mac -macopt hexkey:02000000000000000000000000000000ffffffffffffffffffffffffffffffff}],
type => 'Poly1305',
input => '02000000000000000000000000000000',
expected => '03000000000000000000000000000000',
desc => 'Poly1305 (wrap 2^128)' },
);
push @mac_tests, @siphash_tests unless disabled("siphash");
push @mac_tests, @cmac_tests unless disabled("cmac");
push @mac_tests, @poly1305_tests unless disabled("poly1305");
my @mac_fail_tests = (
{ cmd => [qw{openssl mac}],
type => 'KMAC128',
input => '00',
err => 'EVP_MAC_Init',
desc => 'KMAC128 Fail no key' },
);
my @siphash_fail_tests = (
{ cmd => [qw{openssl mac}],
type => 'SipHash',
input => '00',
err => '',
desc => 'SipHash Fail no key' },
);
push @mac_fail_tests, @siphash_fail_tests unless disabled("siphash");
plan tests => (scalar @mac_tests * 2) + scalar @mac_fail_tests;
foreach (@mac_tests) {
ok(compareline($_->{cmd}, $_->{type}, $_->{input}, $_->{expected}, $_->{err}), $_->{desc});
}
foreach (@mac_tests) {
ok(comparefile($_->{cmd}, $_->{type}, $_->{input}, $_->{expected}), $_->{desc});
}
foreach (@mac_fail_tests) {
ok(compareline($_->{cmd}, $_->{type}, $_->{input}, $_->{expected}, $_->{err}), $_->{desc});
}
# Create a temp input file and save the input data into it, and
# then compare the stdout output matches the expected value.
sub compareline {
my $tmpfile = 'tmp.bin';
my ($cmdarray_orig, $type, $input, $expect, $err) = @_;
my $cmdarray = dclone $cmdarray_orig;
if (defined($expect)) {
$expect = uc $expect;
}
# Open a temporary input file and write $input to it
open(my $in, '>', $tmpfile) or die "Could not open file";
binmode($in);
my $bin = pack("H*", $input);
print $in $bin;
close $in;
# The last cmd parameter is the temporary input file we just created.
my @other = ('-in', $tmpfile, $type);
push @$cmdarray, @other;
my @lines = run(app($cmdarray), capture => 1);
unlink $tmpfile;
if (defined($expect)) {
if ($lines[1] =~ m|^\Q${expect}\E\R$|) {
return 1;
} else {
print "Got: $lines[1]";
print "Exp: $expect\n";
return 0;
}
}
if (defined($err)) {
if (defined($lines[0])) {
$lines[0] =~ s/\s+$//;
if ($lines[0] eq $err) {
return 1;
} else {
print "Got: $lines[0]";
print "Exp: $err\n";
return 0;
}
} else {
# expected an error
return 1;
}
}
return 0;
}
# Create a temp input file and save the input data into it, and
# use the '-bin -out <file>' commandline options to save results out to a file.
# Read this file back in and check its output matches the expected value.
sub comparefile {
my $tmpfile = 'tmp.bin';
my $outfile = 'out.bin';
my ($cmdarray, $type, $input, $expect) = @_;
$expect = uc $expect;
# Open a temporary input file and write $input to it
open(my $in, '>', $tmpfile) or die "Could not open file";
binmode($in);
my $bin = pack("H*", $input);
print $in $bin;
close $in;
my @other = ("-binary", "-in", $tmpfile, "-out", $outfile, $type);
push @$cmdarray, @other;
run(app($cmdarray));
unlink $tmpfile;
open(my $out, '<', $outfile) or die "Could not open file";
binmode($out);
my $buffer;
my $BUFSIZE = 1024;
read($out, $buffer, $BUFSIZE) or die "unable to read";
my $line = uc unpack("H*", $buffer);
close($out);
unlink $outfile;
if ($line eq $expect) {
return 1;
} else {
print "Got: $line\n";
print "Exp: $expect\n";
return 0;
}
}
+45 -23
View File
@@ -15,34 +15,56 @@ use OpenSSL::Test::Utils;
setup("test_pkeyutl");
plan tests => 2;
plan tests => 6;
sub sign
{
# Utilize the sm2.crt as the TBS file
return run(app(([ 'openssl', 'pkeyutl', '-sign',
'-in', srctop_file('test', 'certs', 'sm2.crt'),
'-inkey', srctop_file('test', 'certs', 'sm2.key'),
'-out', 'signature.sm2', '-rawin',
'-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
}
sub verify
{
# Utilize the sm2.crt as the TBS file
return run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin',
'-in', srctop_file('test', 'certs', 'sm2.crt'),
'-inkey', srctop_file('test', 'certs', 'sm2.crt'),
'-sigfile', 'signature.sm2', '-rawin',
'-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
}
# For the tests below we use the cert itself as the TBS file
SKIP: {
skip "Skipping tests that require EC, SM2 or SM3", 2
if disabled("ec") || disabled("sm2") || disabled("sm3");
ok(sign, "Sign a piece of data using SM2");
ok(verify, "Verify an SM2 signature against a piece of data");
# SM2
ok(run(app(([ 'openssl', 'pkeyutl', '-sign',
'-in', srctop_file('test', 'certs', 'sm2.crt'),
'-inkey', srctop_file('test', 'certs', 'sm2.key'),
'-out', 'signature.dat', '-rawin',
'-digest', 'sm3', '-pkeyopt', 'sm2_id:someid']))),
"Sign a piece of data using SM2");
ok(run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin',
'-in', srctop_file('test', 'certs', 'sm2.crt'),
'-inkey', srctop_file('test', 'certs', 'sm2.crt'),
'-sigfile', 'signature.dat', '-rawin',
'-digest', 'sm3', '-pkeyopt', 'sm2_id:someid']))),
"Verify an SM2 signature against a piece of data");
}
unlink 'signature.sm2';
SKIP: {
skip "Skipping tests that require EC", 4
if disabled("ec");
# Ed25519
ok(run(app(([ 'openssl', 'pkeyutl', '-sign', '-in',
srctop_file('test', 'certs', 'server-ed25519-cert.pem'),
'-inkey', srctop_file('test', 'certs', 'server-ed25519-key.pem'),
'-out', 'signature.dat', '-rawin']))),
"Sign a piece of data using Ed25519");
ok(run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin', '-in',
srctop_file('test', 'certs', 'server-ed25519-cert.pem'),
'-inkey', srctop_file('test', 'certs', 'server-ed25519-cert.pem'),
'-sigfile', 'signature.dat', '-rawin']))),
"Verify an Ed25519 signature against a piece of data");
# Ed448
ok(run(app(([ 'openssl', 'pkeyutl', '-sign', '-in',
srctop_file('test', 'certs', 'server-ed448-cert.pem'),
'-inkey', srctop_file('test', 'certs', 'server-ed448-key.pem'),
'-out', 'signature.dat', '-rawin']))),
"Sign a piece of data using Ed448");
ok(run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin', '-in',
srctop_file('test', 'certs', 'server-ed448-cert.pem'),
'-inkey', srctop_file('test', 'certs', 'server-ed448-cert.pem'),
'-sigfile', 'signature.dat', '-rawin']))),
"Verify an Ed448 signature against a piece of data");
}
unlink 'signature.dat';
+634
View File
@@ -0,0 +1,634 @@
/*
* Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (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 <stdio.h>
#include <string.h>
#include "internal/nelem.h"
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/bn.h>
#include "testutil.h"
#ifdef OPENSSL_NO_RSA
int setup_tests(void)
{
/* No tests */
return 1;
}
#else
# include "rsa_locl.h"
# include <openssl/rsa.h>
/* taken from RSA2 cavs data */
static const unsigned char cav_e[] = {
0x01,0x00,0x01
};
static const unsigned char cav_Xp[] = {
0xcf,0x72,0x1b,0x9a,0xfd,0x0d,0x22,0x1a,0x74,0x50,0x97,0x22,0x76,0xd8,0xc0,
0xc2,0xfd,0x08,0x81,0x05,0xdd,0x18,0x21,0x99,0x96,0xd6,0x5c,0x79,0xe3,0x02,
0x81,0xd7,0x0e,0x3f,0x3b,0x34,0xda,0x61,0xc9,0x2d,0x84,0x86,0x62,0x1e,0x3d,
0x5d,0xbf,0x92,0x2e,0xcd,0x35,0x3d,0x6e,0xb9,0x59,0x16,0xc9,0x82,0x50,0x41,
0x30,0x45,0x67,0xaa,0xb7,0xbe,0xec,0xea,0x4b,0x9e,0xa0,0xc3,0x05,0xb3,0x88,
0xd4,0x4c,0xac,0xeb,0xe4,0x03,0xc6,0xca,0xcb,0xd9,0xd3,0x4e,0xf6,0x7f,0x2c,
0x27,0x1e,0x08,0x6c,0xc2,0xd6,0x45,0x1f,0x84,0xe4,0x3c,0x97,0x19,0xde,0xb8,
0x55,0xaf,0x0e,0xcf,0x9e,0xb0,0x9c,0x20,0xd3,0x1f,0xa8,0xd7,0x52,0xc2,0x95,
0x1c,0x80,0x15,0x42,0x4d,0x4f,0x19,0x16
};
static const unsigned char cav_Xp1[] = {
0xac,0x5f,0x7f,0x6e,0x33,0x3e,0x97,0x3a,0xb3,0x17,0x44,0xa9,0x0f,0x7a,0x54,
0x70,0x27,0x06,0x93,0xd5,0x49,0xde,0x91,0x83,0xbc,0x8a,0x7b,0x95
};
static const unsigned char cav_Xp2[] = {
0x0b,0xf6,0xe8,0x79,0x5a,0x81,0xae,0x90,0x1d,0xa4,0x38,0x74,0x9c,0x0e,0x6f,
0xe0,0x03,0xcf,0xc4,0x53,0x16,0x32,0x17,0xf7,0x09,0x5f,0xd9
};
static const unsigned char cav_Xq[] = {
0xfe,0xab,0xf2,0x7c,0x16,0x4a,0xf0,0x8d,0x31,0xc6,0x0a,0x82,0xe2,0xae,0xbb,
0x03,0x7e,0x7b,0x20,0x4e,0x64,0xb0,0x16,0xad,0x3c,0x01,0x1a,0xd3,0x54,0xbf,
0x2b,0xa4,0x02,0x9e,0xc3,0x0d,0x60,0x3d,0x1f,0xb9,0xc0,0x0d,0xe6,0x97,0x68,
0xbb,0x8c,0x81,0xd5,0xc1,0x54,0x96,0x0f,0x99,0xf0,0xa8,0xa2,0xf3,0xc6,0x8e,
0xec,0xbc,0x31,0x17,0x70,0x98,0x24,0xa3,0x36,0x51,0xa8,0x54,0xbd,0x9a,0x89,
0x99,0x6e,0x57,0x5e,0xd0,0x39,0x86,0xc3,0xa3,0x1b,0xc7,0xcf,0xc4,0x4f,0x47,
0x25,0x9e,0x2c,0x79,0xe1,0x2c,0xcc,0xe4,0x63,0xf4,0x02,0x84,0xf8,0xf6,0xa1,
0x5c,0x93,0x14,0xf2,0x68,0x5f,0x3a,0x90,0x2f,0x4e,0x5e,0xf9,0x16,0x05,0xcf,
0x21,0x63,0xca,0xfa,0xb0,0x08,0x02,0xc0
};
static const unsigned char cav_Xq1[] = {
0x9b,0x02,0xd4,0xba,0xf0,0xaa,0x14,0x99,0x6d,0xc0,0xb7,0xa5,0xe1,0xd3,0x70,
0xb6,0x5a,0xa2,0x9b,0x59,0xd5,0x8c,0x1e,0x9f,0x3f,0x9a,0xde,0xeb,0x9e,0x9c,
0x61,0xd6,0x5a,0xe1
};
static const unsigned char cav_Xq2[] = {
0x06,0x81,0x53,0xfd,0xa8,0x7b,0xa3,0x85,0x90,0x15,0x2c,0x97,0xb2,0xa0,0x17,
0x48,0xb0,0x7f,0x0a,0x01,0x6d
};
/* expected values */
static const unsigned char cav_p1[] = {
0xac,0x5f,0x7f,0x6e,0x33,0x3e,0x97,0x3a,0xb3,0x17,0x44,0xa9,0x0f,0x7a,0x54,
0x70,0x27,0x06,0x93,0xd5,0x49,0xde,0x91,0x83,0xbc,0x8a,0x7b,0xc3
};
static const unsigned char cav_p2[] = {
0x0b,0xf6,0xe8,0x79,0x5a,0x81,0xae,0x90,0x1d,0xa4,0x38,0x74,0x9c,0x0e,0x6f,
0xe0,0x03,0xcf,0xc4,0x53,0x16,0x32,0x17,0xf7,0x09,0x5f,0xd9
};
static const unsigned char cav_q1[] = {
0x9b,0x02,0xd4,0xba,0xf0,0xaa,0x14,0x99,0x6d,0xc0,0xb7,0xa5,0xe1,0xd3,0x70,
0xb6,0x5a,0xa2,0x9b,0x59,0xd5,0x8c,0x1e,0x9f,0x3f,0x9a,0xde,0xeb,0x9e,0x9c,
0x61,0xd6,0x5d,0x47
};
static const unsigned char cav_q2[] = {
0x06,0x81,0x53,0xfd,0xa8,0x7b,0xa3,0x85,0x90,0x15,0x2c,0x97,0xb2,0xa0,0x17,
0x48,0xb0,0x7f,0x0a,0x01,0x8f
};
static const unsigned char cav_p[] = {
0xcf,0x72,0x1b,0x9a,0xfd,0x0d,0x22,0x1a,0x74,0x50,0x97,0x22,0x76,0xd8,0xc0,
0xc2,0xfd,0x08,0x81,0x05,0xdd,0x18,0x21,0x99,0x96,0xd6,0x5c,0x79,0xe3,0x02,
0x81,0xd7,0x0e,0x3f,0x3b,0x34,0xda,0x61,0xc9,0x2d,0x84,0x86,0x62,0x1e,0x3d,
0x5d,0xbf,0x92,0x2e,0xcd,0x35,0x3d,0x6e,0xb9,0x59,0x16,0xc9,0x82,0x50,0x41,
0x30,0x45,0x67,0xaa,0xb7,0xbe,0xec,0xea,0x4b,0x9e,0xa0,0xc3,0x05,0xbc,0x4c,
0x01,0xa5,0x4b,0xbd,0xa4,0x20,0xb5,0x20,0xd5,0x59,0x6f,0x82,0x5c,0x8f,0x4f,
0xe0,0x3a,0x4e,0x7e,0xfe,0x44,0xf3,0x3c,0xc0,0x0e,0x14,0x2b,0x32,0xe6,0x28,
0x8b,0x63,0x87,0x00,0xc3,0x53,0x4a,0x5b,0x71,0x7a,0x5b,0x28,0x40,0xc4,0x18,
0xb6,0x77,0x0b,0xab,0x59,0xa4,0x96,0x7d
};
static const unsigned char cav_q[] = {
0xfe,0xab,0xf2,0x7c,0x16,0x4a,0xf0,0x8d,0x31,0xc6,0x0a,0x82,0xe2,0xae,0xbb,
0x03,0x7e,0x7b,0x20,0x4e,0x64,0xb0,0x16,0xad,0x3c,0x01,0x1a,0xd3,0x54,0xbf,
0x2b,0xa4,0x02,0x9e,0xc3,0x0d,0x60,0x3d,0x1f,0xb9,0xc0,0x0d,0xe6,0x97,0x68,
0xbb,0x8c,0x81,0xd5,0xc1,0x54,0x96,0x0f,0x99,0xf0,0xa8,0xa2,0xf3,0xc6,0x8e,
0xec,0xbc,0x31,0x17,0x70,0x98,0x24,0xa3,0x36,0x51,0xa8,0x54,0xc4,0x44,0xdd,
0xf7,0x7e,0xda,0x47,0x4a,0x67,0x44,0x5d,0x4e,0x75,0xf0,0x4d,0x00,0x68,0xe1,
0x4a,0xec,0x1f,0x45,0xf9,0xe6,0xca,0x38,0x95,0x48,0x6f,0xdc,0x9d,0x1b,0xa3,
0x4b,0xfd,0x08,0x4b,0x54,0xcd,0xeb,0x3d,0xef,0x33,0x11,0x6e,0xce,0xe4,0x5d,
0xef,0xa9,0x58,0x5c,0x87,0x4d,0xc8,0xcf
};
static const unsigned char cav_n[] = {
0xce,0x5e,0x8d,0x1a,0xa3,0x08,0x7a,0x2d,0xb4,0x49,0x48,0xf0,0x06,0xb6,0xfe,
0xba,0x2f,0x39,0x7c,0x7b,0xe0,0x5d,0x09,0x2d,0x57,0x4e,0x54,0x60,0x9c,0xe5,
0x08,0x4b,0xe1,0x1a,0x73,0xc1,0x5e,0x2f,0xb6,0x46,0xd7,0x81,0xca,0xbc,0x98,
0xd2,0xf9,0xef,0x1c,0x92,0x8c,0x8d,0x99,0x85,0x28,0x52,0xd6,0xd5,0xab,0x70,
0x7e,0x9e,0xa9,0x87,0x82,0xc8,0x95,0x64,0xeb,0xf0,0x6c,0x0f,0x3f,0xe9,0x02,
0x29,0x2e,0x6d,0xa1,0xec,0xbf,0xdc,0x23,0xdf,0x82,0x4f,0xab,0x39,0x8d,0xcc,
0xac,0x21,0x51,0x14,0xf8,0xef,0xec,0x73,0x80,0x86,0xa3,0xcf,0x8f,0xd5,0xcf,
0x22,0x1f,0xcc,0x23,0x2f,0xba,0xcb,0xf6,0x17,0xcd,0x3a,0x1f,0xd9,0x84,0xb9,
0x88,0xa7,0x78,0x0f,0xaa,0xc9,0x04,0x01,0x20,0x72,0x5d,0x2a,0xfe,0x5b,0xdd,
0x16,0x5a,0xed,0x83,0x02,0x96,0x39,0x46,0x37,0x30,0xc1,0x0d,0x87,0xc2,0xc8,
0x33,0x38,0xed,0x35,0x72,0xe5,0x29,0xf8,0x1f,0x23,0x60,0xe1,0x2a,0x5b,0x1d,
0x6b,0x53,0x3f,0x07,0xc4,0xd9,0xbb,0x04,0x0c,0x5c,0x3f,0x0b,0xc4,0xd4,0x61,
0x96,0x94,0xf1,0x0f,0x4a,0x49,0xac,0xde,0xd2,0xe8,0x42,0xb3,0x4a,0x0b,0x64,
0x7a,0x32,0x5f,0x2b,0x5b,0x0f,0x8b,0x8b,0xe0,0x33,0x23,0x34,0x64,0xf8,0xb5,
0x7f,0x69,0x60,0xb8,0x71,0xe9,0xff,0x92,0x42,0xb1,0xf7,0x23,0xa8,0xa7,0x92,
0x04,0x3d,0x6b,0xff,0xf7,0xab,0xbb,0x14,0x1f,0x4c,0x10,0x97,0xd5,0x6b,0x71,
0x12,0xfd,0x93,0xa0,0x4a,0x3b,0x75,0x72,0x40,0x96,0x1c,0x5f,0x40,0x40,0x57,
0x13
};
static const unsigned char cav_d[] = {
0x47,0x47,0x49,0x1d,0x66,0x2a,0x4b,0x68,0xf5,0xd8,0x4a,0x24,0xfd,0x6c,0xbf,
0x56,0xb7,0x70,0xf7,0x9a,0x21,0xc8,0x80,0x9e,0xf4,0x84,0xcd,0x88,0x01,0x28,
0xea,0x50,0xab,0x13,0x63,0xdf,0xea,0x14,0x38,0xb5,0x07,0x42,0x81,0x2f,0xda,
0xe9,0x24,0x02,0x7e,0xaf,0xef,0x74,0x09,0x0e,0x80,0xfa,0xfb,0xd1,0x19,0x41,
0xe5,0xba,0x0f,0x7c,0x0a,0xa4,0x15,0x55,0xa2,0x58,0x8c,0x3a,0x48,0x2c,0xc6,
0xde,0x4a,0x76,0xfb,0x72,0xb6,0x61,0xe6,0xd2,0x10,0x44,0x4c,0x33,0xb8,0xd2,
0x74,0xb1,0x9d,0x3b,0xcd,0x2f,0xb1,0x4f,0xc3,0x98,0xbd,0x83,0xb7,0x7e,0x75,
0xe8,0xa7,0x6a,0xee,0xcc,0x51,0x8c,0x99,0x17,0x67,0x7f,0x27,0xf9,0x0d,0x6a,
0xb7,0xd4,0x80,0x17,0x89,0x39,0x9c,0xf3,0xd7,0x0f,0xdf,0xb0,0x55,0x80,0x1d,
0xaf,0x57,0x2e,0xd0,0xf0,0x4f,0x42,0x69,0x55,0xbc,0x83,0xd6,0x97,0x83,0x7a,
0xe6,0xc6,0x30,0x6d,0x3d,0xb5,0x21,0xa7,0xc4,0x62,0x0a,0x20,0xce,0x5e,0x5a,
0x17,0x98,0xb3,0x6f,0x6b,0x9a,0xeb,0x6b,0xa3,0xc4,0x75,0xd8,0x2b,0xdc,0x5c,
0x6f,0xec,0x5d,0x49,0xac,0xa8,0xa4,0x2f,0xb8,0x8c,0x4f,0x2e,0x46,0x21,0xee,
0x72,0x6a,0x0e,0x22,0x80,0x71,0xc8,0x76,0x40,0x44,0x61,0x16,0xbf,0xa5,0xf8,
0x89,0xc7,0xe9,0x87,0xdf,0xbd,0x2e,0x4b,0x4e,0xc2,0x97,0x53,0xe9,0x49,0x1c,
0x05,0xb0,0x0b,0x9b,0x9f,0x21,0x19,0x41,0xe9,0xf5,0x61,0xd7,0x33,0x2e,0x2c,
0x94,0xb8,0xa8,0x9a,0x3a,0xcc,0x6a,0x24,0x8d,0x19,0x13,0xee,0xb9,0xb0,0x48,
0x61
};
/* helper function */
static BIGNUM *bn_load_new(const unsigned char *data, int sz)
{
BIGNUM *ret = BN_new();
if (ret != NULL)
BN_bin2bn(data, sz, ret);
return ret;
}
/* helper function */
static BIGNUM *bn_load(BN_CTX *ctx, const unsigned char *data, int sz)
{
BIGNUM *ret = BN_CTX_get(ctx);
if (ret != NULL)
BN_bin2bn(data, sz, ret);
return ret;
}
static int test_check_public_exponent(void)
{
int ret = 0;
BIGNUM *e = NULL;
ret = TEST_ptr(e = BN_new())
/* e is too small */
&& TEST_true(BN_set_word(e, 65535))
&& TEST_false(rsa_check_public_exponent(e))
/* e is even will fail */
&& TEST_true(BN_set_word(e, 65536))
&& TEST_false(rsa_check_public_exponent(e))
/* e is ok */
&& TEST_true(BN_set_word(e, 65537))
&& TEST_true(rsa_check_public_exponent(e))
/* e = 2^256 is too big */
&& TEST_true(BN_lshift(e, BN_value_one(), 256))
&& TEST_false(rsa_check_public_exponent(e))
/* e = 2^256-1 is odd and in range */
&& TEST_true(BN_sub(e, e, BN_value_one()))
&& TEST_true(rsa_check_public_exponent(e));
BN_free(e);
return ret;
}
static int test_check_prime_factor_range(void)
{
int ret = 0;
BN_CTX *ctx = NULL;
BIGNUM *p = NULL;
BIGNUM *bn_p1 = NULL, *bn_p2 = NULL, *bn_p3 = NULL, *bn_p4 = NULL;
/* Some range checks that are larger than 32 bits */
static const unsigned char p1[] = { 0x0B, 0x50, 0x4F, 0x33, 0x3F };
static const unsigned char p2[] = { 0x10, 0x00, 0x00, 0x00, 0x00 };
static const unsigned char p3[] = { 0x0B, 0x50, 0x4F, 0x33, 0x40 };
static const unsigned char p4[] = { 0x0F, 0xFF, 0xFF, 0xFF, 0xFF };
/* (√2)(2^(nbits/2 - 1) <= p <= 2^(nbits/2) - 1
* For 8 bits: 0xB.504F <= p <= 0xF
* for 72 bits: 0xB504F333F. <= p <= 0xF_FFFF_FFFF
*/
ret = TEST_ptr(p = BN_new())
&& TEST_ptr(bn_p1 = bn_load_new(p1, sizeof(p1)))
&& TEST_ptr(bn_p2 = bn_load_new(p2, sizeof(p2)))
&& TEST_ptr(bn_p3 = bn_load_new(p3, sizeof(p3)))
&& TEST_ptr(bn_p4 = bn_load_new(p4, sizeof(p4)))
&& TEST_ptr(ctx = BN_CTX_new())
&& TEST_true(BN_set_word(p, 0xA))
&& TEST_false(rsa_check_prime_factor_range(p, 8, ctx))
&& TEST_true(BN_set_word(p, 0x10))
&& TEST_false(rsa_check_prime_factor_range(p, 8, ctx))
&& TEST_true(BN_set_word(p, 0xB))
&& TEST_true(rsa_check_prime_factor_range(p, 8, ctx))
&& TEST_true(BN_set_word(p, 0xF))
&& TEST_true(rsa_check_prime_factor_range(p, 8, ctx))
&& TEST_false(rsa_check_prime_factor_range(bn_p1, 72, ctx))
&& TEST_false(rsa_check_prime_factor_range(bn_p2, 72, ctx))
&& TEST_true(rsa_check_prime_factor_range(bn_p3, 72, ctx))
&& TEST_true(rsa_check_prime_factor_range(bn_p4, 72, ctx));
BN_free(bn_p4);
BN_free(bn_p3);
BN_free(bn_p2);
BN_free(bn_p1);
BN_free(p);
BN_CTX_free(ctx);
return ret;
}
static int test_check_prime_factor(void)
{
int ret = 0;
BN_CTX *ctx = NULL;
BIGNUM *p = NULL, *e = NULL;
BIGNUM *bn_p1 = NULL, *bn_p2 = NULL, *bn_p3 = NULL;
/* Some range checks that are larger than 32 bits */
static const unsigned char p1[] = { 0x0B, 0x50, 0x4f, 0x33, 0x73 };
static const unsigned char p2[] = { 0x0B, 0x50, 0x4f, 0x33, 0x75 };
static const unsigned char p3[] = { 0x0F, 0x50, 0x00, 0x03, 0x75 };
ret = TEST_ptr(p = BN_new())
&& TEST_ptr(bn_p1 = bn_load_new(p1, sizeof(p1)))
&& TEST_ptr(bn_p2 = bn_load_new(p2, sizeof(p2)))
&& TEST_ptr(bn_p3 = bn_load_new(p3, sizeof(p3)))
&& TEST_ptr(e = BN_new())
&& TEST_ptr(ctx = BN_CTX_new())
/* Fails the prime test */
&& TEST_true(BN_set_word(e, 0x1))
&& TEST_false(rsa_check_prime_factor(bn_p1, e, 72, ctx))
/* p is prime and in range and gcd(p-1, e) = 1 */
&& TEST_true(rsa_check_prime_factor(bn_p2, e, 72, ctx))
/* gcd(p-1,e) = 1 test fails */
&& TEST_true(BN_set_word(e, 0x2))
&& TEST_false(rsa_check_prime_factor(p, e, 72, ctx))
/* p fails the range check */
&& TEST_true(BN_set_word(e, 0x1))
&& TEST_false(rsa_check_prime_factor(bn_p3, e, 72, ctx));
BN_free(bn_p3);
BN_free(bn_p2);
BN_free(bn_p1);
BN_free(e);
BN_free(p);
BN_CTX_free(ctx);
return ret;
}
static int test_check_private_exponent(void)
{
int ret = 0;
RSA *key = NULL;
BN_CTX *ctx = NULL;
BIGNUM *p = NULL, *q = NULL, *e = NULL, *d = NULL, *n = NULL;
ret = TEST_ptr(key = RSA_new())
&& TEST_ptr(ctx = BN_CTX_new())
&& TEST_ptr(p = BN_new())
&& TEST_ptr(q = BN_new())
&& TEST_ptr(e = BN_new())
&& TEST_ptr(d = BN_new())
&& TEST_ptr(n = BN_new())
/* lcm(15-1,17-1) = 14*16 / 2 = 112 */
&& TEST_true(BN_set_word(p, 15))
&& TEST_true(BN_set_word(q, 17))
&& TEST_true(BN_set_word(e, 5))
&& TEST_true(BN_set_word(d, 157))
&& TEST_true(BN_set_word(n, 15*17))
&& TEST_true(RSA_set0_factors(key, p, q))
&& TEST_true(RSA_set0_key(key, n, e, d))
/* fails since d >= lcm(p-1, q-1) */
&& TEST_false(rsa_check_private_exponent(key, 8, ctx))
&& TEST_true(BN_set_word(d, 45))
/* d is correct size and 1 = e.d mod lcm(p-1, q-1) */
&& TEST_true(rsa_check_private_exponent(key, 8, ctx))
/* d is too small compared to nbits */
&& TEST_false(rsa_check_private_exponent(key, 16, ctx))
/* d is too small compared to nbits */
&& TEST_true(BN_set_word(d, 16))
&& TEST_false(rsa_check_private_exponent(key, 8, ctx))
/* fail if 1 != e.d mod lcm(p-1, q-1) */
&& TEST_true(BN_set_word(d, 46))
&& TEST_false(rsa_check_private_exponent(key, 8, ctx));
RSA_free(key);
BN_CTX_free(ctx);
return ret;
}
static int test_check_crt_components(void)
{
const int P = 15;
const int Q = 17;
const int E = 5;
const int N = P*Q;
const int DP = 3;
const int DQ = 13;
const int QINV = 8;
int ret = 0;
RSA *key = NULL;
BN_CTX *ctx = NULL;
BIGNUM *p = NULL, *q = NULL, *e = NULL;
ret = TEST_ptr(key = RSA_new())
&& TEST_ptr(ctx = BN_CTX_new())
&& TEST_ptr(p = BN_new())
&& TEST_ptr(q = BN_new())
&& TEST_ptr(e = BN_new())
&& TEST_true(BN_set_word(p, P))
&& TEST_true(BN_set_word(q, Q))
&& TEST_true(BN_set_word(e, E))
&& TEST_true(RSA_set0_factors(key, p, q))
&& TEST_true(rsa_sp800_56b_derive_params_from_pq(key, 8, e, ctx))
&& TEST_BN_eq_word(key->n, N)
&& TEST_BN_eq_word(key->dmp1, DP)
&& TEST_BN_eq_word(key->dmq1, DQ)
&& TEST_BN_eq_word(key->iqmp, QINV)
&& TEST_true(rsa_check_crt_components(key, ctx))
/* (a) 1 < dP < (p 1). */
&& TEST_true(BN_set_word(key->dmp1, 1))
&& TEST_false(rsa_check_crt_components(key, ctx))
&& TEST_true(BN_set_word(key->dmp1, P-1))
&& TEST_false(rsa_check_crt_components(key, ctx))
&& TEST_true(BN_set_word(key->dmp1, DP))
/* (b) 1 < dQ < (q - 1). */
&& TEST_true(BN_set_word(key->dmq1, 1))
&& TEST_false(rsa_check_crt_components(key, ctx))
&& TEST_true(BN_set_word(key->dmq1, Q-1))
&& TEST_false(rsa_check_crt_components(key, ctx))
&& TEST_true(BN_set_word(key->dmq1, DQ))
/* (c) 1 < qInv < p */
&& TEST_true(BN_set_word(key->iqmp, 1))
&& TEST_false(rsa_check_crt_components(key, ctx))
&& TEST_true(BN_set_word(key->iqmp, P))
&& TEST_false(rsa_check_crt_components(key, ctx))
&& TEST_true(BN_set_word(key->iqmp, QINV))
/* (d) 1 = (dP . e) mod (p - 1)*/
&& TEST_true(BN_set_word(key->dmp1, DP+1))
&& TEST_false(rsa_check_crt_components(key, ctx))
&& TEST_true(BN_set_word(key->dmp1, DP))
/* (e) 1 = (dQ . e) mod (q - 1) */
&& TEST_true(BN_set_word(key->dmq1, DQ-1))
&& TEST_false(rsa_check_crt_components(key, ctx))
&& TEST_true(BN_set_word(key->dmq1, DQ))
/* (f) 1 = (qInv . q) mod p */
&& TEST_true(BN_set_word(key->iqmp, QINV+1))
&& TEST_false(rsa_check_crt_components(key, ctx))
&& TEST_true(BN_set_word(key->iqmp, QINV))
/* check defaults are still valid */
&& TEST_true(rsa_check_crt_components(key, ctx));
BN_free(e);
RSA_free(key);
BN_CTX_free(ctx);
return ret;
}
static int test_pq_diff(void)
{
int ret = 0;
BIGNUM *tmp = NULL, *p = NULL, *q = NULL;
ret = TEST_ptr(tmp = BN_new())
&& TEST_ptr(p = BN_new())
&& TEST_ptr(q = BN_new())
/* |1-(2+1)| > 2^1 */
&& TEST_true(BN_set_word(p, 1))
&& TEST_true(BN_set_word(q, 1+2))
&& TEST_false(rsa_check_pminusq_diff(tmp, p, q, 202))
/* Check |p - q| > 2^(nbits/2 - 100) */
&& TEST_true(BN_set_word(q, 1+3))
&& TEST_true(rsa_check_pminusq_diff(tmp, p, q, 202))
&& TEST_true(BN_set_word(p, 1+3))
&& TEST_true(BN_set_word(q, 1))
&& TEST_true(rsa_check_pminusq_diff(tmp, p, q, 202));
BN_free(p);
BN_free(q);
BN_free(tmp);
return ret;
}
static int test_invalid_keypair(void)
{
int ret = 0;
RSA *key = NULL;
BN_CTX *ctx = NULL;
BIGNUM *p = NULL, *q = NULL, *n = NULL, *e = NULL, *d = NULL;
ret = TEST_ptr(key = RSA_new())
&& TEST_ptr(ctx = BN_CTX_new())
/* NULL parameters */
&& TEST_false(rsa_sp800_56b_check_keypair(key, NULL, -1, 2048))
/* load key */
&& TEST_ptr(p = bn_load_new(cav_p, sizeof(cav_p)))
&& TEST_ptr(q = bn_load_new(cav_q, sizeof(cav_q)))
&& TEST_ptr(e = bn_load_new(cav_e, sizeof(cav_e)))
&& TEST_ptr(n = bn_load_new(cav_n, sizeof(cav_n)))
&& TEST_ptr(d = bn_load_new(cav_d, sizeof(cav_d)))
&& TEST_true(RSA_set0_key(key, n, e, d))
&& TEST_true(RSA_set0_factors(key, p, q))
/* bad strength/key size */
&& TEST_false(rsa_sp800_56b_check_keypair(key, NULL, 100, 2048))
&& TEST_false(rsa_sp800_56b_check_keypair(key, NULL, 112, 1024))
&& TEST_false(rsa_sp800_56b_check_keypair(key, NULL, 128, 2048))
&& TEST_false(rsa_sp800_56b_check_keypair(key, NULL, 140, 3072))
/* mismatching exponent */
&& TEST_false(rsa_sp800_56b_check_keypair(key, BN_value_one(), -1,
2048))
/* bad exponent */
&& TEST_true(BN_add_word(e, 1))
&& TEST_false(rsa_sp800_56b_check_keypair(key, NULL, -1,
2048))
&& TEST_true(BN_sub_word(e, 1))
/* mismatch between bits and modulus */
&& TEST_false(rsa_sp800_56b_check_keypair(key, NULL, -1, 3072))
&& TEST_true(rsa_sp800_56b_check_keypair(key, e, 112, 2048))
/* check n == pq failure */
&& TEST_true(BN_add_word(n, 1))
&& TEST_false(rsa_sp800_56b_check_keypair(key, NULL, -1, 2048))
&& TEST_true(BN_sub_word(n, 1))
/* check p */
&& TEST_true(BN_sub_word(p, 2))
&& TEST_true(BN_mul(n, p, q, ctx))
&& TEST_false(rsa_sp800_56b_check_keypair(key, NULL, -1, 2048))
&& TEST_true(BN_add_word(p, 2))
&& TEST_true(BN_mul(n, p, q, ctx))
/* check q */
&& TEST_true(BN_sub_word(q, 2))
&& TEST_true(BN_mul(n, p, q, ctx))
&& TEST_false(rsa_sp800_56b_check_keypair(key, NULL, -1, 2048))
&& TEST_true(BN_add_word(q, 2))
&& TEST_true(BN_mul(n, p, q, ctx));
RSA_free(key);
BN_CTX_free(ctx);
return ret;
}
static int test_fips1864_keygen_kat(void)
{
int ret = 0;
RSA *key = NULL;
BN_CTX *ctx = NULL;
BIGNUM *e, *Xp, *Xp1, *Xp2, *Xq, *Xq1, *Xq2;
BIGNUM *p1, *p2, *q1, *q2;
BIGNUM *p1_exp, *p2_exp, *q1_exp, *q2_exp;
BIGNUM *p_exp, *q_exp, *n_exp, *d_exp;
const BIGNUM *p, *q, *n, *d, *e2;
if (!(TEST_ptr(key = RSA_new()) && TEST_ptr(ctx = BN_CTX_new())))
goto err;
BN_CTX_start(ctx);
e = bn_load(ctx, cav_e, sizeof(cav_e));
Xp = bn_load(ctx, cav_Xp, sizeof(cav_Xp));
Xp1 = bn_load(ctx, cav_Xp1, sizeof(cav_Xp1));
Xp2 = bn_load(ctx, cav_Xp2, sizeof(cav_Xp2));
Xq = bn_load(ctx, cav_Xq, sizeof(cav_Xq));
Xq1 = bn_load(ctx, cav_Xq1, sizeof(cav_Xq1));
Xq2 = bn_load(ctx, cav_Xq2, sizeof(cav_Xq2));
p1_exp = bn_load(ctx, cav_p1, sizeof(cav_p1));
p2_exp = bn_load(ctx, cav_p2, sizeof(cav_p2));
q1_exp = bn_load(ctx, cav_q1, sizeof(cav_q1));
q2_exp = bn_load(ctx, cav_q2, sizeof(cav_q2));
p_exp = bn_load(ctx, cav_p, sizeof(cav_p));
q_exp = bn_load(ctx, cav_q, sizeof(cav_q));
n_exp = bn_load(ctx, cav_n, sizeof(cav_n));
d_exp = bn_load(ctx, cav_d, sizeof(cav_d));
p1 = BN_CTX_get(ctx);
p2 = BN_CTX_get(ctx);
q1 = BN_CTX_get(ctx);
q2 = BN_CTX_get(ctx);
ret = TEST_ptr(q2)
&& TEST_true(rsa_fips186_4_gen_prob_primes(key, p1, p2, NULL, Xp, Xp1,
Xp2, q1, q2, NULL, Xq, Xq1,
Xq2, 2048, e, ctx, NULL))
&& TEST_true(rsa_sp800_56b_derive_params_from_pq(key, 2048, e, ctx))
&& TEST_BN_eq(p1_exp, p1)
&& TEST_BN_eq(p2_exp, p2)
&& TEST_BN_eq(q1_exp, q1)
&& TEST_BN_eq(q2_exp, q2);
if (!ret)
goto err;
RSA_get0_key(key, &n, &e2, &d);
RSA_get0_factors(key, &p, &q);
ret = TEST_BN_eq(e, e2)
&& TEST_BN_eq(p_exp, p)
&& TEST_BN_eq(q_exp, q)
&& TEST_BN_eq(n_exp, n)
&& TEST_BN_eq(d_exp, d);
err:
RSA_free(key);
BN_CTX_end(ctx);
BN_CTX_free(ctx);
return ret;
}
static int keygen_size[] =
{
2048, 3072
};
static int test_sp80056b_keygen(int id)
{
RSA *key = NULL;
int ret;
int sz = keygen_size[id];
ret = TEST_ptr(key = RSA_new())
&& TEST_true(rsa_sp800_56b_generate_key(key, sz, NULL, NULL))
&& TEST_true(rsa_sp800_56b_check_public(key))
&& TEST_true(rsa_sp800_56b_check_private(key))
&& TEST_true(rsa_sp800_56b_check_keypair(key, NULL, -1, sz));
RSA_free(key);
return ret;
}
static int test_check_private_key(void)
{
int ret = 0;
BIGNUM *n = NULL, *d = NULL, *e = NULL;
RSA *key = NULL;
ret = TEST_ptr(key = RSA_new())
/* check NULL pointers fail */
&& TEST_false(rsa_sp800_56b_check_private(key))
/* load private key */
&& TEST_ptr(n = bn_load_new(cav_n, sizeof(cav_n)))
&& TEST_ptr(d = bn_load_new(cav_d, sizeof(cav_d)))
&& TEST_ptr(e = bn_load_new(cav_e, sizeof(cav_e)))
&& TEST_true(RSA_set0_key(key, n, e, d))
/* check d is in range */
&& TEST_true(rsa_sp800_56b_check_private(key))
/* check d is too low */
&& TEST_true(BN_set_word(d, 0))
&& TEST_false(rsa_sp800_56b_check_private(key))
/* check d is too high */
&& TEST_ptr(BN_copy(d, n))
&& TEST_false(rsa_sp800_56b_check_private(key));
RSA_free(key);
return ret;
}
static int test_check_public_key(void)
{
int ret = 0;
BIGNUM *n = NULL, *e = NULL;
RSA *key = NULL;
ret = TEST_ptr(key = RSA_new())
/* check NULL pointers fail */
&& TEST_false(rsa_sp800_56b_check_public(key))
/* load public key */
&& TEST_ptr(e = bn_load_new(cav_e, sizeof(cav_e)))
&& TEST_ptr(n = bn_load_new(cav_n, sizeof(cav_n)))
&& TEST_true(RSA_set0_key(key, n, e, NULL))
/* check public key is valid */
&& TEST_true(rsa_sp800_56b_check_public(key))
/* check fail if n is even */
&& TEST_true(BN_add_word(n, 1))
&& TEST_false(rsa_sp800_56b_check_public(key))
&& TEST_true(BN_sub_word(n, 1))
/* check fail if n is wrong number of bits */
&& TEST_true(BN_lshift1(n, n))
&& TEST_false(rsa_sp800_56b_check_public(key))
&& TEST_true(BN_rshift1(n, n))
/* test odd exponent fails */
&& TEST_true(BN_add_word(e, 1))
&& TEST_false(rsa_sp800_56b_check_public(key))
&& TEST_true(BN_sub_word(e, 1))
/* modulus fails composite check */
&& TEST_true(BN_add_word(n, 2))
&& TEST_false(rsa_sp800_56b_check_public(key));
RSA_free(key);
return ret;
}
int setup_tests(void)
{
ADD_TEST(test_check_public_exponent);
ADD_TEST(test_check_prime_factor_range);
ADD_TEST(test_check_prime_factor);
ADD_TEST(test_check_private_exponent);
ADD_TEST(test_check_crt_components);
ADD_TEST(test_check_private_key);
ADD_TEST(test_check_public_key);
ADD_TEST(test_invalid_keypair);
ADD_TEST(test_pq_diff);
ADD_TEST(test_fips1864_keygen_kat);
ADD_ALL_TESTS(test_sp80056b_keygen, (int)OSSL_NELEM(keygen_size));
return 1;
}
#endif
+34 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1999-2019 The OpenSSL Project Authors. 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
@@ -42,6 +42,8 @@ int setup_tests(void)
BN_bin2bn(dmp1, sizeof(dmp1)-1, NULL), \
BN_bin2bn(dmq1, sizeof(dmq1)-1, NULL), \
BN_bin2bn(iqmp, sizeof(iqmp)-1, NULL)); \
if (c == NULL) \
return 0; \
memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \
return sizeof(ctext_ex) - 1;
@@ -268,6 +270,36 @@ err:
return ret;
}
static int test_rsa_sslv23(int idx)
{
int ret = 0;
RSA *key;
unsigned char ptext[256];
unsigned char ctext[256];
static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
unsigned char ctext_ex[256];
int plen;
int clen = 0;
int num;
plen = sizeof(ptext_ex) - 1;
clen = rsa_setkey(&key, ctext_ex, idx);
num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
RSA_SSLV23_PADDING);
if (!TEST_int_eq(num, clen))
goto err;
num = RSA_private_decrypt(num, ctext, ptext, key, RSA_SSLV23_PADDING);
if (!TEST_mem_eq(ptext, num, ptext_ex, plen))
goto err;
ret = 1;
err:
RSA_free(key);
return ret;
}
static int test_rsa_oaep(int idx)
{
int ret = 0;
@@ -391,6 +423,7 @@ err:
int setup_tests(void)
{
ADD_ALL_TESTS(test_rsa_pkcs1, 3);
ADD_ALL_TESTS(test_rsa_sslv23, 3);
ADD_ALL_TESTS(test_rsa_oaep, 3);
ADD_ALL_TESTS(test_rsa_security_bit, OSSL_NELEM(rsa_security_bits_cases));
return 1;
+9
View File
@@ -255,7 +255,9 @@ DECLARE_COMPARISONS(char, char)
DECLARE_COMPARISONS(unsigned char, uchar)
DECLARE_COMPARISONS(long, long)
DECLARE_COMPARISONS(unsigned long, ulong)
DECLARE_COMPARISONS(double, double)
DECLARE_COMPARISONS(time_t, time_t)
/*
* Because this comparison uses a printf format specifier that's not
* universally known (yet), we provide an option to not have it declared.
@@ -406,6 +408,13 @@ void test_perror(const char *s);
# define TEST_size_t_gt(a, b) test_size_t_gt(__FILE__, __LINE__, #a, #b, a, b)
# define TEST_size_t_ge(a, b) test_size_t_ge(__FILE__, __LINE__, #a, #b, a, b)
# define TEST_double_eq(a, b) test_double_eq(__FILE__, __LINE__, #a, #b, a, b)
# define TEST_double_ne(a, b) test_double_ne(__FILE__, __LINE__, #a, #b, a, b)
# define TEST_double_lt(a, b) test_double_lt(__FILE__, __LINE__, #a, #b, a, b)
# define TEST_double_le(a, b) test_double_le(__FILE__, __LINE__, #a, #b, a, b)
# define TEST_double_gt(a, b) test_double_gt(__FILE__, __LINE__, #a, #b, a, b)
# define TEST_double_ge(a, b) test_double_ge(__FILE__, __LINE__, #a, #b, a, b)
# define TEST_time_t_eq(a, b) test_time_t_eq(__FILE__, __LINE__, #a, #b, a, b)
# define TEST_time_t_ne(a, b) test_time_t_ne(__FILE__, __LINE__, #a, #b, a, b)
# define TEST_time_t_lt(a, b) test_time_t_lt(__FILE__, __LINE__, #a, #b, a, b)
+1
View File
@@ -213,6 +213,7 @@ DEFINE_COMPARISONS(unsigned char, uchar, "%u")
DEFINE_COMPARISONS(long, long, "%ld")
DEFINE_COMPARISONS(unsigned long, ulong, "%lu")
DEFINE_COMPARISONS(size_t, size_t, "%zu")
DEFINE_COMPARISONS(double, double, "%g")
DEFINE_COMPARISON(void *, ptr, eq, ==, "%p")
DEFINE_COMPARISON(void *, ptr, ne, !=, "%p")