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 "crypto/ecx.h"
13 #include "ecx_backend.h"
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.
21 int ecx_key_fromdata(ECX_KEY *ecx, const OSSL_PARAM params[],
24 size_t privkeylen = 0, pubkeylen;
25 const OSSL_PARAM *param_priv_key = NULL, *param_pub_key;
26 unsigned char *pubkey;
31 param_pub_key = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
34 OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
36 * If a private key is present then a public key must also be present.
37 * Alternatively we've just got a public key.
39 if (param_pub_key == NULL)
42 if (param_priv_key != NULL
43 && !OSSL_PARAM_get_octet_string(param_priv_key,
44 (void **)&ecx->privkey, ecx->keylen,
49 if (!OSSL_PARAM_get_octet_string(param_pub_key,
51 sizeof(ecx->pubkey), &pubkeylen))
54 if (pubkeylen != ecx->keylen
55 || (param_priv_key != NULL && privkeylen != ecx->keylen))