2 * Copyright 2020-2021 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/core_names.h>
11 #include "internal/ffc.h"
12 #include "internal/sizes.h"
15 * The intention with the "backend" source file is to offer backend support
16 * for legacy backends (EVP_PKEY_ASN1_METHOD and EVP_PKEY_METHOD) and provider
17 * implementations alike.
20 int ossl_ffc_params_fromdata(FFC_PARAMS *ffc, const OSSL_PARAM params[])
22 const OSSL_PARAM *prm;
23 const OSSL_PARAM *param_p, *param_q, *param_g;
24 BIGNUM *p = NULL, *q = NULL, *g = NULL, *j = NULL;
30 prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_GROUP_NAME);
33 * In a no-dh build we just go straight to err because we have no
37 const DH_NAMED_GROUP *group = NULL;
39 if (prm->data_type != OSSL_PARAM_UTF8_STRING
41 || (group = ossl_ffc_name_to_dh_named_group(prm->data)) == NULL
42 || !ossl_ffc_named_group_set_pqg(ffc, group))
47 param_p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_P);
48 param_g = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_G);
49 param_q = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_Q);
51 if ((param_p != NULL && !OSSL_PARAM_get_BN(param_p, &p))
52 || (param_q != NULL && !OSSL_PARAM_get_BN(param_q, &q))
53 || (param_g != NULL && !OSSL_PARAM_get_BN(param_g, &g)))
56 prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_GINDEX);
58 if (!OSSL_PARAM_get_int(prm, &i))
62 prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_PCOUNTER);
64 if (!OSSL_PARAM_get_int(prm, &i))
68 prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_COFACTOR);
69 if (prm != NULL && !OSSL_PARAM_get_BN(prm, &j))
71 prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_H);
73 if (!OSSL_PARAM_get_int(prm, &i))
77 prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_SEED);
79 if (prm->data_type != OSSL_PARAM_OCTET_STRING)
81 if (!ossl_ffc_params_set_seed(ffc, prm->data, prm->data_size))
84 prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_VALIDATE_PQ);
86 if (!OSSL_PARAM_get_int(prm, &i))
88 ossl_ffc_params_enable_flags(ffc, FFC_PARAM_FLAG_VALIDATE_PQ, i);
90 prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_VALIDATE_G);
92 if (!OSSL_PARAM_get_int(prm, &i))
94 ossl_ffc_params_enable_flags(ffc, FFC_PARAM_FLAG_VALIDATE_G, i);
96 prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_VALIDATE_LEGACY);
98 if (!OSSL_PARAM_get_int(prm, &i))
100 ossl_ffc_params_enable_flags(ffc, FFC_PARAM_FLAG_VALIDATE_LEGACY, i);
103 prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_DIGEST);
105 const OSSL_PARAM *p1;
106 const char *props = NULL;
108 if (prm->data_type != OSSL_PARAM_UTF8_STRING)
110 p1 = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_DIGEST_PROPS);
112 if (p1->data_type != OSSL_PARAM_UTF8_STRING)
115 if (!ossl_ffc_set_digest(ffc, prm->data, props))
119 ossl_ffc_params_set0_pqg(ffc, p, q, g);
120 ossl_ffc_params_set0_j(ffc, j);