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 <openssl/params.h>
12 #include <openssl/ec.h>
13 #include <openssl/err.h>
14 #include "crypto/ecx.h"
15 #include "ecx_backend.h"
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.
23 int ossl_ecx_public_from_private(ECX_KEY
*key
)
26 case ECX_KEY_TYPE_X25519
:
27 X25519_public_from_private(key
->pubkey
, key
->privkey
);
29 case ECX_KEY_TYPE_ED25519
:
30 if (!ED25519_public_from_private(key
->libctx
, key
->pubkey
, key
->privkey
,
32 ERR_raise(ERR_LIB_EC
, EC_R_FAILED_MAKING_PUBLIC_KEY
);
36 case ECX_KEY_TYPE_X448
:
37 X448_public_from_private(key
->pubkey
, key
->privkey
);
39 case ECX_KEY_TYPE_ED448
:
40 if (!ED448_public_from_private(key
->libctx
, key
->pubkey
, key
->privkey
,
42 ERR_raise(ERR_LIB_EC
, EC_R_FAILED_MAKING_PUBLIC_KEY
);
50 int ossl_ecx_key_fromdata(ECX_KEY
*ecx
, const OSSL_PARAM params
[],
53 size_t privkeylen
= 0, pubkeylen
= 0;
54 const OSSL_PARAM
*param_priv_key
= NULL
, *param_pub_key
;
55 unsigned char *pubkey
;
60 param_pub_key
= OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_PUB_KEY
);
63 OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_PRIV_KEY
);
65 if (param_pub_key
== NULL
&& param_priv_key
== NULL
)
68 if (param_priv_key
!= NULL
69 && !OSSL_PARAM_get_octet_string(param_priv_key
,
70 (void **)&ecx
->privkey
, ecx
->keylen
,
75 if (param_pub_key
!= NULL
76 && !OSSL_PARAM_get_octet_string(param_pub_key
,
78 sizeof(ecx
->pubkey
), &pubkeylen
))
81 if ((param_pub_key
!= NULL
&& pubkeylen
!= ecx
->keylen
)
82 || (param_priv_key
!= NULL
&& privkeylen
!= ecx
->keylen
))
85 if (param_pub_key
== NULL
&& !ossl_ecx_public_from_private(ecx
))