summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/pmeth_gn.c
diff options
context:
space:
mode:
authortb <>2022-01-10 11:52:43 +0000
committertb <>2022-01-10 11:52:43 +0000
commitc4f6925dc73274ba5f411d30fbd78b6be1580782 (patch)
tree1fec6a88d05f741604c6f6549798d45c11a3aef3 /src/lib/libcrypto/evp/pmeth_gn.c
parentb1042d763c8d1442a3bbd1098fe10bbb13206ca4 (diff)
downloadopenbsd-c4f6925dc73274ba5f411d30fbd78b6be1580782.tar.gz
openbsd-c4f6925dc73274ba5f411d30fbd78b6be1580782.tar.bz2
openbsd-c4f6925dc73274ba5f411d30fbd78b6be1580782.zip
Prepare to provide EVP_PKEY_check()
This allows checking the validity of an EVP_PKEY. Only RSA and EC keys are supported. If a check function is set the EVP_PKEY_METHOD, it will be used, otherwise the check function on the EVP_PKEY_ASN1_METHOD is used. The default ASN.1 methods wrap RSA_check_key() and EC_KEY_check_key(), respectively. The corresponding setters are EVP_PKEY_{asn1,meth}_set_check(). It is unclear why the PKEY method has no const while the ASN.1 method has const. Requested by tobhe and used by PHP 8.1. Based on OpenSSL commit 2aee35d3 ok inoguchi jsing
Diffstat (limited to 'src/lib/libcrypto/evp/pmeth_gn.c')
-rw-r--r--src/lib/libcrypto/evp/pmeth_gn.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/lib/libcrypto/evp/pmeth_gn.c b/src/lib/libcrypto/evp/pmeth_gn.c
index 066291b800..a8a4cc97db 100644
--- a/src/lib/libcrypto/evp/pmeth_gn.c
+++ b/src/lib/libcrypto/evp/pmeth_gn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pmeth_gn.c,v 1.8 2021/12/04 16:08:32 tb Exp $ */ 1/* $OpenBSD: pmeth_gn.c,v 1.9 2022/01/10 11:52:43 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -64,6 +64,7 @@
64#include <openssl/evp.h> 64#include <openssl/evp.h>
65#include <openssl/objects.h> 65#include <openssl/objects.h>
66 66
67#include "asn1_locl.h"
67#include "bn_lcl.h" 68#include "bn_lcl.h"
68#include "evp_locl.h" 69#include "evp_locl.h"
69 70
@@ -222,3 +223,24 @@ merr:
222 EVP_PKEY_CTX_free(mac_ctx); 223 EVP_PKEY_CTX_free(mac_ctx);
223 return mac_key; 224 return mac_key;
224} 225}
226
227int
228EVP_PKEY_check(EVP_PKEY_CTX *ctx)
229{
230 EVP_PKEY *pkey;
231
232 if ((pkey = ctx->pkey) == NULL) {
233 EVPerror(EVP_R_NO_KEY_SET);
234 return 0;
235 }
236
237 if (ctx->pmeth->check != NULL)
238 return ctx->pmeth->check(pkey);
239
240 if (pkey->ameth == NULL || pkey->ameth->pkey_check == NULL) {
241 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
242 return -2;
243 }
244
245 return pkey->ameth->pkey_check(pkey);
246}