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->pkeys[0].keymgmt;
32 key = pkey->pkeys[0].provdata;
34 if (key != NULL && keymgmt != NULL)
35 return evp_keymgmt_validate_public(keymgmt, key);
38 /* call customized public key check function first */
39 if (ctx->pmeth->public_check != NULL)
40 return ctx->pmeth->public_check(pkey);
42 /* use default public key check function in ameth */
43 if (pkey->ameth == NULL || pkey->ameth->pkey_public_check == NULL) {
44 EVPerr(EVP_F_EVP_PKEY_PUBLIC_CHECK,
45 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
49 return pkey->ameth->pkey_public_check(pkey);
52 int EVP_PKEY_param_check(EVP_PKEY_CTX *ctx)
54 EVP_PKEY *pkey = ctx->pkey;
59 EVPerr(EVP_F_EVP_PKEY_PARAM_CHECK, EVP_R_NO_KEY_SET);
63 keymgmt = pkey->pkeys[0].keymgmt;
64 key = pkey->pkeys[0].provdata;
66 if (key != NULL && keymgmt != NULL)
67 return evp_keymgmt_validate_domparams(keymgmt, key);
69 /* call customized param check function first */
70 if (ctx->pmeth->param_check != NULL)
71 return ctx->pmeth->param_check(pkey);
74 /* use default param check function in ameth */
75 if (pkey->ameth == NULL || pkey->ameth->pkey_param_check == NULL) {
76 EVPerr(EVP_F_EVP_PKEY_PARAM_CHECK,
77 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
81 return pkey->ameth->pkey_param_check(pkey);
84 int EVP_PKEY_private_check(EVP_PKEY_CTX *ctx)
86 EVP_PKEY *pkey = ctx->pkey;
91 EVPerr(0, EVP_R_NO_KEY_SET);
95 keymgmt = pkey->pkeys[0].keymgmt;
96 key = pkey->pkeys[0].provdata;
98 if (key != NULL && keymgmt != NULL)
99 return evp_keymgmt_validate_private(keymgmt, key);
100 /* not supported for legacy keys */
104 int EVP_PKEY_pairwise_check(EVP_PKEY_CTX *ctx)
106 EVP_PKEY *pkey = ctx->pkey;
108 EVP_KEYMGMT *keymgmt;
111 EVPerr(0, EVP_R_NO_KEY_SET);
115 keymgmt = pkey->pkeys[0].keymgmt;
116 key = pkey->pkeys[0].provdata;
118 if (key != NULL && keymgmt != NULL)
119 return evp_keymgmt_validate_pairwise(keymgmt, key);
120 /* not supported for legacy keys */
124 int EVP_PKEY_check(EVP_PKEY_CTX *ctx)
126 EVP_PKEY *pkey = ctx->pkey;
128 EVP_KEYMGMT *keymgmt;
131 EVPerr(EVP_F_EVP_PKEY_CHECK, EVP_R_NO_KEY_SET);
135 keymgmt = pkey->pkeys[0].keymgmt;
136 key = pkey->pkeys[0].provdata;
138 if (key != NULL && keymgmt != NULL) {
139 return evp_keymgmt_validate_domparams(keymgmt, key)
140 && evp_keymgmt_validate_public(keymgmt, key)
141 && evp_keymgmt_validate_private(keymgmt, key)
142 && evp_keymgmt_validate_pairwise(keymgmt, key);
145 /* call customized check function first */
146 if (ctx->pmeth->check != NULL)
147 return ctx->pmeth->check(pkey);
149 /* use default check function in ameth */
150 if (pkey->ameth == NULL || pkey->ameth->pkey_check == NULL) {
151 EVPerr(EVP_F_EVP_PKEY_CHECK,
152 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
156 return pkey->ameth->pkey_check(pkey);