2 * Copyright 2020 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 <string.h> /* memcpy */
11 #include <openssl/core_names.h>
12 #include <openssl/param_build.h>
13 #include "crypto/rsa.h"
14 #include "rsa_local.h"
16 int rsa_acvp_test_gen_params_new(OSSL_PARAM **dst, const OSSL_PARAM src[])
18 const OSSL_PARAM *p, *s;
19 OSSL_PARAM *d, *alloc = NULL;
22 static const OSSL_PARAM settable[] = {
23 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_TEST_XP, NULL, 0),
24 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_TEST_XP1, NULL, 0),
25 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_TEST_XP2, NULL, 0),
26 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_TEST_XQ, NULL, 0),
27 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_TEST_XQ1, NULL, 0),
28 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_TEST_XQ2, NULL, 0),
32 /* Assume the first element is a required field if this feature is used */
33 p = OSSL_PARAM_locate_const(src, settable[0].key);
37 /* Zeroing here means the terminator is always set at the end */
38 alloc = OPENSSL_zalloc(sizeof(settable));
43 for (s = settable; s->key != NULL; ++s) {
44 /* If src contains a key from settable then copy the src to the dest */
45 p = OSSL_PARAM_locate_const(src, s->key);
47 *d = *s; /* shallow copy from the static settable[] */
48 d->data_size = p->data_size;
49 d->data = OPENSSL_memdup(p->data, p->data_size);
56 rsa_acvp_test_gen_params_free(alloc);
60 rsa_acvp_test_gen_params_free(*dst);
65 void rsa_acvp_test_gen_params_free(OSSL_PARAM *dst)
72 for (p = dst; p->key != NULL; ++p) {
73 OPENSSL_free(p->data);
79 int rsa_acvp_test_set_params(RSA *r, const OSSL_PARAM params[])
84 if (r->acvp_test != NULL) {
85 rsa_acvp_test_free(r->acvp_test);
89 t = OPENSSL_zalloc(sizeof(*t));
93 /* Set the input parameters */
94 if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_TEST_XP1)) != NULL
95 && !OSSL_PARAM_get_BN(p, &t->Xp1))
97 if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_TEST_XP2)) != NULL
98 && !OSSL_PARAM_get_BN(p, &t->Xp2))
100 if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_TEST_XP)) != NULL
101 && !OSSL_PARAM_get_BN(p, &t->Xp))
103 if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_TEST_XQ1)) != NULL
104 && !OSSL_PARAM_get_BN(p, &t->Xq1))
106 if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_TEST_XQ2)) != NULL
107 && !OSSL_PARAM_get_BN(p, &t->Xq2))
109 if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_TEST_XQ)) != NULL
110 && !OSSL_PARAM_get_BN(p, &t->Xq))
113 /* Setup the output parameters */
121 rsa_acvp_test_free(t);
125 int rsa_acvp_test_get_params(RSA *r, OSSL_PARAM params[])
135 if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_RSA_TEST_P1)) != NULL
136 && !OSSL_PARAM_set_BN(p, t->p1))
138 if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_RSA_TEST_P2)) != NULL
139 && !OSSL_PARAM_set_BN(p, t->p2))
141 if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_RSA_TEST_Q1)) != NULL
142 && !OSSL_PARAM_set_BN(p, t->q1))
144 if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_RSA_TEST_Q2)) != NULL
145 && !OSSL_PARAM_set_BN(p, t->q2))
151 void rsa_acvp_test_free(RSA_ACVP_TEST *t)