]>
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 <openssl/params.h> | |
12 | #include "crypto/ecx.h" | |
13 | #include "ecx_backend.h" | |
14 | ||
15 | /* | |
16 | * The intention with the "backend" source file is to offer backend support | |
17 | * for legacy backends (EVP_PKEY_ASN1_METHOD and EVP_PKEY_METHOD) and provider | |
18 | * implementations alike. | |
19 | */ | |
20 | ||
21 | int ecx_key_fromdata(ECX_KEY *ecx, const OSSL_PARAM params[], | |
22 | int include_private) | |
23 | { | |
24 | size_t privkeylen = 0, pubkeylen; | |
25 | const OSSL_PARAM *param_priv_key = NULL, *param_pub_key; | |
26 | unsigned char *pubkey; | |
27 | ||
28 | if (ecx == NULL) | |
29 | return 0; | |
30 | ||
31 | param_pub_key = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY); | |
32 | if (include_private) | |
33 | param_priv_key = | |
34 | OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY); | |
35 | /* | |
36 | * If a private key is present then a public key must also be present. | |
37 | * Alternatively we've just got a public key. | |
38 | */ | |
39 | if (param_pub_key == NULL) | |
40 | return 0; | |
41 | ||
42 | if (param_priv_key != NULL | |
43 | && !OSSL_PARAM_get_octet_string(param_priv_key, | |
44 | (void **)&ecx->privkey, ecx->keylen, | |
45 | &privkeylen)) | |
46 | return 0; | |
47 | ||
48 | pubkey = ecx->pubkey; | |
49 | if (!OSSL_PARAM_get_octet_string(param_pub_key, | |
50 | (void **)&pubkey, | |
51 | sizeof(ecx->pubkey), &pubkeylen)) | |
52 | return 0; | |
53 | ||
54 | if (pubkeylen != ecx->keylen | |
55 | || (param_priv_key != NULL && privkeylen != ecx->keylen)) | |
56 | return 0; | |
57 | ||
58 | ecx->haspubkey = 1; | |
59 | ||
60 | return 1; | |
61 | } | |
62 |