]>
Commit | Line | Data |
---|---|---|
0abae163 RL |
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" | |
b03ec3b5 | 12 | #include "internal/sizes.h" |
0abae163 RL |
13 | |
14 | /* | |
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. | |
18 | */ | |
19 | ||
b03ec3b5 | 20 | int ffc_params_fromdata(FFC_PARAMS *ffc, const OSSL_PARAM params[]) |
0abae163 | 21 | { |
b03ec3b5 | 22 | const OSSL_PARAM *prm; |
0abae163 | 23 | const OSSL_PARAM *param_p, *param_q, *param_g; |
b03ec3b5 | 24 | BIGNUM *p = NULL, *q = NULL, *g = NULL, *j = NULL; |
b03ec3b5 | 25 | int i; |
0abae163 RL |
26 | |
27 | if (ffc == NULL) | |
28 | return 0; | |
29 | ||
b03ec3b5 SL |
30 | prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_GROUP); |
31 | if (prm != NULL) { | |
7165593c | 32 | if (prm->data_type != OSSL_PARAM_UTF8_STRING) |
b03ec3b5 | 33 | goto err; |
7165593c | 34 | if (!ffc_set_group_pqg(ffc, prm->data)) |
b03ec3b5 SL |
35 | goto err; |
36 | } | |
7165593c | 37 | |
0abae163 | 38 | param_p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_P); |
0abae163 | 39 | param_g = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_G); |
b03ec3b5 | 40 | param_q = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_Q); |
0abae163 RL |
41 | |
42 | if ((param_p != NULL && !OSSL_PARAM_get_BN(param_p, &p)) | |
43 | || (param_q != NULL && !OSSL_PARAM_get_BN(param_q, &q)) | |
44 | || (param_g != NULL && !OSSL_PARAM_get_BN(param_g, &g))) | |
45 | goto err; | |
46 | ||
b03ec3b5 SL |
47 | prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_GINDEX); |
48 | if (prm != NULL) { | |
49 | if (!OSSL_PARAM_get_int(prm, &i)) | |
50 | goto err; | |
51 | ffc->gindex = i; | |
52 | } | |
53 | prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_PCOUNTER); | |
54 | if (prm != NULL) { | |
55 | if (!OSSL_PARAM_get_int(prm, &i)) | |
56 | goto err; | |
57 | ffc->pcounter = i; | |
58 | } | |
59 | prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_COFACTOR); | |
60 | if (prm != NULL) { | |
61 | if (!OSSL_PARAM_get_BN(prm, &j)) | |
62 | goto err; | |
7165593c | 63 | j = NULL; |
b03ec3b5 SL |
64 | } |
65 | prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_H); | |
66 | if (prm != NULL) { | |
67 | if (!OSSL_PARAM_get_int(prm, &i)) | |
68 | goto err; | |
69 | ffc->h = i; | |
70 | } | |
71 | prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_SEED); | |
72 | if (prm != NULL) { | |
73 | if (prm->data_type != OSSL_PARAM_OCTET_STRING) | |
74 | goto err; | |
75 | if (!ffc_params_set_seed(ffc, prm->data, prm->data_size)) | |
76 | goto err; | |
77 | } | |
0abae163 | 78 | ffc_params_set0_pqg(ffc, p, q, g); |
b03ec3b5 | 79 | ffc_params_set0_j(ffc, j); |
0abae163 RL |
80 | return 1; |
81 | ||
82 | err: | |
b03ec3b5 | 83 | BN_free(j); |
0abae163 RL |
84 | BN_free(p); |
85 | BN_free(q); | |
86 | BN_free(g); | |
87 | return 0; | |
88 | } |