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"
24 * -1 Unsupported (use legacy path)
26 static int try_provided_check(EVP_PKEY_CTX
*ctx
, int selection
)
31 if (evp_pkey_ctx_is_legacy(ctx
))
34 keymgmt
= ctx
->keymgmt
;
35 keydata
= evp_pkey_export_to_provider(ctx
->pkey
, ctx
->libctx
,
36 &keymgmt
, ctx
->propquery
);
37 if (keydata
== NULL
) {
38 ERR_raise(ERR_LIB_EVP
, EVP_R_INITIALIZATION_ERROR
);
42 return evp_keymgmt_validate(keymgmt
, keydata
, selection
);
45 int EVP_PKEY_public_check(EVP_PKEY_CTX
*ctx
)
47 EVP_PKEY
*pkey
= ctx
->pkey
;
51 EVPerr(EVP_F_EVP_PKEY_PUBLIC_CHECK
, EVP_R_NO_KEY_SET
);
55 if ((ok
= try_provided_check(ctx
, OSSL_KEYMGMT_SELECT_PUBLIC_KEY
)) != -1)
58 if (pkey
->type
== EVP_PKEY_NONE
)
63 /* call customized public key check function first */
64 if (ctx
->pmeth
->public_check
!= NULL
)
65 return ctx
->pmeth
->public_check(pkey
);
67 /* use default public key check function in ameth */
68 if (pkey
->ameth
== NULL
|| pkey
->ameth
->pkey_public_check
== NULL
)
71 return pkey
->ameth
->pkey_public_check(pkey
);
74 EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
78 int EVP_PKEY_param_check(EVP_PKEY_CTX
*ctx
)
80 EVP_PKEY
*pkey
= ctx
->pkey
;
84 EVPerr(EVP_F_EVP_PKEY_PARAM_CHECK
, EVP_R_NO_KEY_SET
);
88 if ((ok
= try_provided_check(ctx
,
89 OSSL_KEYMGMT_SELECT_ALL_PARAMETERS
)) != -1)
92 if (pkey
->type
== EVP_PKEY_NONE
)
97 /* call customized param check function first */
98 if (ctx
->pmeth
->param_check
!= NULL
)
99 return ctx
->pmeth
->param_check(pkey
);
101 /* use default param check function in ameth */
102 if (pkey
->ameth
== NULL
|| pkey
->ameth
->pkey_param_check
== NULL
)
105 return pkey
->ameth
->pkey_param_check(pkey
);
108 EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
112 int EVP_PKEY_private_check(EVP_PKEY_CTX
*ctx
)
114 EVP_PKEY
*pkey
= ctx
->pkey
;
118 EVPerr(0, EVP_R_NO_KEY_SET
);
122 if ((ok
= try_provided_check(ctx
, OSSL_KEYMGMT_SELECT_PRIVATE_KEY
)) != -1)
125 /* not supported for legacy keys */
126 EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
130 int EVP_PKEY_pairwise_check(EVP_PKEY_CTX
*ctx
)
132 EVP_PKEY
*pkey
= ctx
->pkey
;
136 EVPerr(0, EVP_R_NO_KEY_SET
);
140 if ((ok
= try_provided_check(ctx
, OSSL_KEYMGMT_SELECT_KEYPAIR
)) != -1)
143 /* not supported for legacy keys */
144 EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
148 int EVP_PKEY_check(EVP_PKEY_CTX
*ctx
)
150 EVP_PKEY
*pkey
= ctx
->pkey
;
154 EVPerr(EVP_F_EVP_PKEY_CHECK
, EVP_R_NO_KEY_SET
);
158 if ((ok
= try_provided_check(ctx
, OSSL_KEYMGMT_SELECT_KEYPAIR
)) != -1)
161 if (pkey
->type
== EVP_PKEY_NONE
)
166 /* call customized check function first */
167 if (ctx
->pmeth
->check
!= NULL
)
168 return ctx
->pmeth
->check(pkey
);
170 /* use default check function in ameth */
171 if (pkey
->ameth
== NULL
|| pkey
->ameth
->pkey_check
== NULL
)
174 return pkey
->ameth
->pkey_check(pkey
);
177 EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);