2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/evp.h>
11 #include <openssl/provider.h>
12 #include <openssl/params.h>
13 #include <openssl/core_names.h>
14 #include "internal/nelem.h"
15 #include "crypto/evp.h" /* For the internal API */
18 /* Array indexes used in test_fromdata_rsa */
28 static int test_fromdata_rsa(void)
31 EVP_PKEY_CTX *ctx = NULL;
34 * 32-bit RSA key, extracted from this command,
35 * executed with OpenSSL 1.0.2:
37 * openssl genrsa 32 | openssl rsa -text
39 static unsigned long key_numbers[] = {
49 OSSL_PARAM fromdata_params[] = {
50 OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_N, &key_numbers[N]),
51 OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_E, &key_numbers[E]),
52 OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_D, &key_numbers[D]),
53 OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_FACTOR, &key_numbers[P]),
54 OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_FACTOR, &key_numbers[Q]),
55 OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_EXPONENT, &key_numbers[DP]),
56 OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_EXPONENT, &key_numbers[DQ]),
57 OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_COEFFICIENT, &key_numbers[QINV]),
61 if (!TEST_ptr(ctx = EVP_PKEY_CTX_new_provided(NULL, "RSA", NULL)))
64 if (!TEST_true(EVP_PKEY_key_fromdata_init(ctx))
65 || !TEST_true(EVP_PKEY_fromdata(ctx, &pk, fromdata_params)))
69 * TODO(3.0) We can't do much more at this point without using internals,
70 * because RSA functionality is still missing. When the time comes, it
71 * would be nice to try and do something "useful" with this key, such
72 * as signing a small piece of data.
78 EVP_PKEY_CTX_free(ctx);
85 ADD_TEST(test_fromdata_rsa);