]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/ffc/ffc_backend.c
cde9e43da345a3eab5784427fa4189ff5ecde751
[thirdparty/openssl.git] / crypto / ffc / ffc_backend.c
1 /*
2 * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
10 #include <openssl/core_names.h>
11 #include "internal/ffc.h"
12
13 /*
14 * The intention with the "backend" source file is to offer backend support
15 * for legacy backends (EVP_PKEY_ASN1_METHOD and EVP_PKEY_METHOD) and provider
16 * implementations alike.
17 */
18
19 int ffc_fromdata(FFC_PARAMS *ffc, const OSSL_PARAM params[])
20 {
21 const OSSL_PARAM *param_p, *param_q, *param_g;
22 BIGNUM *p = NULL, *q = NULL, *g = NULL;
23
24 if (ffc == NULL)
25 return 0;
26
27 param_p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_P);
28 param_q = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_Q);
29 param_g = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_G);
30
31 if ((param_p != NULL && !OSSL_PARAM_get_BN(param_p, &p))
32 || (param_q != NULL && !OSSL_PARAM_get_BN(param_q, &q))
33 || (param_g != NULL && !OSSL_PARAM_get_BN(param_g, &g)))
34 goto err;
35
36 ffc_params_set0_pqg(ffc, p, q, g);
37 return 1;
38
39 err:
40 BN_free(p);
41 BN_free(q);
42 BN_free(g);
43 return 0;
44 }