2 * Copyright 2006-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
12 #include "internal/cryptlib.h"
13 #include <openssl/objects.h>
14 #include <openssl/evp.h>
15 #include "crypto/bn.h"
16 #include "crypto/asn1.h"
17 #include "crypto/evp.h"
18 #include "evp_local.h"
20 int EVP_PKEY_public_check(EVP_PKEY_CTX *ctx)
22 EVP_PKEY *pkey = ctx->pkey;
27 EVPerr(EVP_F_EVP_PKEY_PUBLIC_CHECK, EVP_R_NO_KEY_SET);
31 keymgmt = pkey->keymgmt;
34 if (key != NULL && keymgmt != NULL)
35 return evp_keymgmt_validate(keymgmt, key,
36 OSSL_KEYMGMT_SELECT_PUBLIC_KEY);
38 if (pkey->type == EVP_PKEY_NONE)
43 /* call customized public key check function first */
44 if (ctx->pmeth->public_check != NULL)
45 return ctx->pmeth->public_check(pkey);
47 /* use default public key check function in ameth */
48 if (pkey->ameth == NULL || pkey->ameth->pkey_public_check == NULL)
51 return pkey->ameth->pkey_public_check(pkey);
54 EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
58 int EVP_PKEY_param_check(EVP_PKEY_CTX *ctx)
60 EVP_PKEY *pkey = ctx->pkey;
65 EVPerr(EVP_F_EVP_PKEY_PARAM_CHECK, EVP_R_NO_KEY_SET);
69 keymgmt = pkey->keymgmt;
72 if (key != NULL && keymgmt != NULL)
73 return evp_keymgmt_validate(keymgmt, key,
74 OSSL_KEYMGMT_SELECT_ALL_PARAMETERS);
76 if (pkey->type == EVP_PKEY_NONE)
81 /* call customized param check function first */
82 if (ctx->pmeth->param_check != NULL)
83 return ctx->pmeth->param_check(pkey);
85 /* use default param check function in ameth */
86 if (pkey->ameth == NULL || pkey->ameth->pkey_param_check == NULL)
89 return pkey->ameth->pkey_param_check(pkey);
92 EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
96 int EVP_PKEY_private_check(EVP_PKEY_CTX *ctx)
98 EVP_PKEY *pkey = ctx->pkey;
100 EVP_KEYMGMT *keymgmt;
103 EVPerr(0, EVP_R_NO_KEY_SET);
107 keymgmt = pkey->keymgmt;
110 if (key != NULL && keymgmt != NULL)
111 return evp_keymgmt_validate(keymgmt, key,
112 OSSL_KEYMGMT_SELECT_PRIVATE_KEY);
113 /* not supported for legacy keys */
114 EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
118 int EVP_PKEY_pairwise_check(EVP_PKEY_CTX *ctx)
120 EVP_PKEY *pkey = ctx->pkey;
122 EVP_KEYMGMT *keymgmt;
125 EVPerr(0, EVP_R_NO_KEY_SET);
129 keymgmt = pkey->keymgmt;
132 if (key != NULL && keymgmt != NULL)
133 return evp_keymgmt_validate(keymgmt, key, OSSL_KEYMGMT_SELECT_KEYPAIR);
134 /* not supported for legacy keys */
135 EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
139 int EVP_PKEY_check(EVP_PKEY_CTX *ctx)
141 EVP_PKEY *pkey = ctx->pkey;
143 EVP_KEYMGMT *keymgmt;
146 EVPerr(EVP_F_EVP_PKEY_CHECK, EVP_R_NO_KEY_SET);
150 keymgmt = pkey->keymgmt;
153 if (key != NULL && keymgmt != NULL)
154 return evp_keymgmt_validate(keymgmt, key, OSSL_KEYMGMT_SELECT_ALL);
156 if (pkey->type == EVP_PKEY_NONE)
161 /* call customized check function first */
162 if (ctx->pmeth->check != NULL)
163 return ctx->pmeth->check(pkey);
165 /* use default check function in ameth */
166 if (pkey->ameth == NULL || pkey->ameth->pkey_check == NULL)
169 return pkey->ameth->pkey_check(pkey);
172 EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);