2 * Copyright 2020 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 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)) {
31 ECerr(0, EC_R_FAILED_MAKING_PUBLIC_KEY);
35 case ECX_KEY_TYPE_X448:
36 X448_public_from_private(key->pubkey, key->privkey);
38 case ECX_KEY_TYPE_ED448:
39 if (!ED448_public_from_private(key->libctx, key->pubkey, key->privkey)) {
40 ECerr(0, EC_R_FAILED_MAKING_PUBLIC_KEY);
48 int ecx_key_fromdata(ECX_KEY *ecx, const OSSL_PARAM params[],
51 size_t privkeylen = 0, pubkeylen = 0;
52 const OSSL_PARAM *param_priv_key = NULL, *param_pub_key;
53 unsigned char *pubkey;
58 param_pub_key = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
61 OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
63 if (param_pub_key == NULL && param_priv_key == NULL)
66 if (param_priv_key != NULL
67 && !OSSL_PARAM_get_octet_string(param_priv_key,
68 (void **)&ecx->privkey, ecx->keylen,
73 if (param_pub_key != NULL
74 && !OSSL_PARAM_get_octet_string(param_pub_key,
76 sizeof(ecx->pubkey), &pubkeylen))
79 if ((param_pub_key != NULL && pubkeylen != ecx->keylen)
80 || (param_priv_key != NULL && privkeylen != ecx->keylen))
83 if (param_pub_key == NULL && !ecx_public_from_private(ecx))