diff options
author | Richard Levitte <levitte@openssl.org> | 2019-10-17 23:53:44 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-11-07 11:50:39 +0100 |
commit | ab14d2af5386897eba8307c9f3220a6d775c0898 (patch) | |
tree | c9b9a8493e3d7d7f6499da08d59c4a58163fd22c /test | |
parent | 46e2dd05ef1456e3e8fc3d12bd839bae01576c19 (diff) | |
download | openssl-new-ab14d2af5386897eba8307c9f3220a6d775c0898.tar.gz |
Add a test for EVP_PKEY_keymake() and EVP_PKEY_make()
This test is a bit lame, but will either be completed as functionality
is added in the default provider, or the new functions may start
getting used in evp_test.c and this program will disappear.
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/10187)
Diffstat (limited to 'test')
-rw-r--r-- | test/build.info | 7 | ||||
-rw-r--r-- | test/evp_fromdata_test.c | 87 | ||||
-rw-r--r-- | test/recipes/30-test_evp_fromdata.t | 13 |
3 files changed, 106 insertions, 1 deletions
diff --git a/test/build.info b/test/build.info index 2623358bc7..85a888d226 100644 --- a/test/build.info +++ b/test/build.info @@ -38,7 +38,8 @@ IF[{- !$disabled{tests} -}] destest mdc2test \ dhtest enginetest casttest \ bftest ssltest_old dsatest dsa_no_digest_size_test exptest rsa_test \ - evp_test evp_extra_test evp_fetch_prov_test igetest v3nametest v3ext \ + evp_fromdata_test evp_test evp_extra_test evp_fetch_prov_test \ + igetest v3nametest v3ext \ crltest danetest bad_dtls_test lhash_test sparse_array_test \ conf_include_test params_api_test params_conversion_test \ constant_time_test verify_extra_test clienthellotest \ @@ -204,6 +205,10 @@ IF[{- !$disabled{tests} -}] DEFINE[evp_extra_test]=NO_FIPS_MODULE ENDIF + SOURCE[evp_fromdata_test]=evp_fromdata_test.c + INCLUDE[evp_fromdata_test]=../include ../apps/include + DEPEND[evp_fromdata_test]=../libcrypto libtestutil.a + SOURCE[igetest]=igetest.c INCLUDE[igetest]=../include ../apps/include DEPEND[igetest]=../libcrypto libtestutil.a diff --git a/test/evp_fromdata_test.c b/test/evp_fromdata_test.c new file mode 100644 index 0000000000..74da50d3d3 --- /dev/null +++ b/test/evp_fromdata_test.c @@ -0,0 +1,87 @@ +/* + * 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 <openssl/evp.h> +#include <openssl/provider.h> +#include <openssl/params.h> +#include <openssl/core_names.h> +#include "internal/nelem.h" +#include "crypto/evp.h" /* For the internal API */ +#include "testutil.h" + +/* Array indexes used in test_fromdata_rsa */ +#define N 0 +#define E 1 +#define D 2 +#define P 3 +#define Q 4 +#define DP 5 +#define DQ 6 +#define QINV 7 + +static int test_fromdata_rsa(void) +{ + int ret = 0; + EVP_PKEY_CTX *ctx = NULL; + EVP_PKEY *pk = NULL; + /* + * 32-bit RSA key, extracted from this command, + * executed with OpenSSL 1.0.2: + * + * openssl genrsa 32 | openssl rsa -text + */ + static unsigned long key_numbers[] = { + 0xbc747fc5, /* N */ + 0x10001, /* E */ + 0x7b133399, /* D */ + 0xe963, /* P */ + 0xceb7, /* Q */ + 0x8599, /* DP */ + 0xbd87, /* DQ */ + 0xcc3b, /* QINV */ + }; + OSSL_PARAM fromdata_params[] = { + OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_N, &key_numbers[N]), + OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_E, &key_numbers[E]), + OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_D, &key_numbers[D]), + OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_FACTOR, &key_numbers[P]), + OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_FACTOR, &key_numbers[Q]), + OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_EXPONENT, &key_numbers[DP]), + OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_EXPONENT, &key_numbers[DQ]), + OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_COEFFICIENT, &key_numbers[QINV]), + OSSL_PARAM_END + }; + + if (!TEST_ptr(ctx = EVP_PKEY_CTX_new_provided(NULL, "RSA", NULL))) + goto err; + + if (!TEST_true(EVP_PKEY_key_fromdata_init(ctx)) + || !TEST_true(EVP_PKEY_fromdata(ctx, &pk, fromdata_params))) + goto err; + + /* + * TODO(3.0) We can't do much more at this point without using internals, + * because RSA functionality is still missing. When the time comes, it + * would be nice to try and do something "useful" with this key, such + * as signing a small piece of data. + */ + ret = 1; + + err: + EVP_PKEY_free(pk); + EVP_PKEY_CTX_free(ctx); + + return ret; +} + +int setup_tests(void) +{ + ADD_TEST(test_fromdata_rsa); + return 1; +} diff --git a/test/recipes/30-test_evp_fromdata.t b/test/recipes/30-test_evp_fromdata.t new file mode 100644 index 0000000000..0662de4cdd --- /dev/null +++ b/test/recipes/30-test_evp_fromdata.t @@ -0,0 +1,13 @@ +#! /usr/bin/env perl +# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. +# Copyright (c) 2018, 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_evp_fromdata", "evp_fromdata_test"); |