]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/ec/ecx_backend.c
Fix external symbols related to dsa keys
[thirdparty/openssl.git] / crypto / ec / ecx_backend.c
CommitLineData
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>
969024b4
MC
12#include <openssl/ec.h>
13#include <openssl/err.h>
0abae163
RL
14#include "crypto/ecx.h"
15#include "ecx_backend.h"
16
17/*
18 * The intention with the "backend" source file is to offer backend support
19 * for legacy backends (EVP_PKEY_ASN1_METHOD and EVP_PKEY_METHOD) and provider
20 * implementations alike.
21 */
22
969024b4
MC
23int ecx_public_from_private(ECX_KEY *key)
24{
25 switch (key->type) {
26 case ECX_KEY_TYPE_X25519:
27 X25519_public_from_private(key->pubkey, key->privkey);
28 break;
29 case ECX_KEY_TYPE_ED25519:
8dbef010
SL
30 if (!ED25519_public_from_private(key->libctx, key->pubkey, key->privkey,
31 key->propq)) {
9311d0c4 32 ERR_raise(ERR_LIB_EC, EC_R_FAILED_MAKING_PUBLIC_KEY);
969024b4
MC
33 return 0;
34 }
35 break;
36 case ECX_KEY_TYPE_X448:
37 X448_public_from_private(key->pubkey, key->privkey);
38 break;
39 case ECX_KEY_TYPE_ED448:
8dbef010
SL
40 if (!ED448_public_from_private(key->libctx, key->pubkey, key->privkey,
41 key->propq)) {
9311d0c4 42 ERR_raise(ERR_LIB_EC, EC_R_FAILED_MAKING_PUBLIC_KEY);
969024b4
MC
43 return 0;
44 }
45 break;
46 }
47 return 1;
48}
49
0abae163
RL
50int ecx_key_fromdata(ECX_KEY *ecx, const OSSL_PARAM params[],
51 int include_private)
52{
969024b4 53 size_t privkeylen = 0, pubkeylen = 0;
0abae163
RL
54 const OSSL_PARAM *param_priv_key = NULL, *param_pub_key;
55 unsigned char *pubkey;
56
57 if (ecx == NULL)
58 return 0;
59
60 param_pub_key = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
61 if (include_private)
62 param_priv_key =
63 OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
969024b4
MC
64
65 if (param_pub_key == NULL && param_priv_key == NULL)
0abae163
RL
66 return 0;
67
68 if (param_priv_key != NULL
69 && !OSSL_PARAM_get_octet_string(param_priv_key,
70 (void **)&ecx->privkey, ecx->keylen,
71 &privkeylen))
72 return 0;
73
74 pubkey = ecx->pubkey;
969024b4
MC
75 if (param_pub_key != NULL
76 && !OSSL_PARAM_get_octet_string(param_pub_key,
77 (void **)&pubkey,
78 sizeof(ecx->pubkey), &pubkeylen))
0abae163
RL
79 return 0;
80
969024b4 81 if ((param_pub_key != NULL && pubkeylen != ecx->keylen)
0abae163
RL
82 || (param_priv_key != NULL && privkeylen != ecx->keylen))
83 return 0;
84
969024b4
MC
85 if (param_pub_key == NULL && !ecx_public_from_private(ecx))
86 return 0;
87
0abae163
RL
88 ecx->haspubkey = 1;
89
90 return 1;
91}
92