summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec
diff options
context:
space:
mode:
authortb <>2022-01-10 11:52:43 +0000
committertb <>2022-01-10 11:52:43 +0000
commita447c077ad67d6e81ed1a4fbe9003875add773c2 (patch)
tree1fec6a88d05f741604c6f6549798d45c11a3aef3 /src/lib/libcrypto/ec
parent0af4f789497e3f3ba6818138f64585c080464044 (diff)
downloadopenbsd-a447c077ad67d6e81ed1a4fbe9003875add773c2.tar.gz
openbsd-a447c077ad67d6e81ed1a4fbe9003875add773c2.tar.bz2
openbsd-a447c077ad67d6e81ed1a4fbe9003875add773c2.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/ec')
-rw-r--r--src/lib/libcrypto/ec/ec_ameth.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/lib/libcrypto/ec/ec_ameth.c b/src/lib/libcrypto/ec/ec_ameth.c
index c96c46dd53..8316683f8f 100644
--- a/src/lib/libcrypto/ec/ec_ameth.c
+++ b/src/lib/libcrypto/ec/ec_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_ameth.c,v 1.29 2021/12/12 21:30:13 tb Exp $ */ 1/* $OpenBSD: ec_ameth.c,v 1.30 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 */
@@ -67,6 +67,7 @@
67#include <openssl/x509.h> 67#include <openssl/x509.h>
68 68
69#include "asn1_locl.h" 69#include "asn1_locl.h"
70#include "ec_lcl.h"
70#include "evp_locl.h" 71#include "evp_locl.h"
71 72
72#ifndef OPENSSL_NO_CMS 73#ifndef OPENSSL_NO_CMS
@@ -620,6 +621,19 @@ ec_pkey_ctrl(EVP_PKEY * pkey, int op, long arg1, void *arg2)
620 621
621} 622}
622 623
624static int
625ec_pkey_check(const EVP_PKEY *pkey)
626{
627 EC_KEY *eckey = pkey->pkey.ec;
628
629 if (eckey->priv_key == NULL) {
630 ECerror(EC_R_MISSING_PRIVATE_KEY);
631 return 0;
632 }
633
634 return EC_KEY_check_key(eckey);
635}
636
623#ifndef OPENSSL_NO_CMS 637#ifndef OPENSSL_NO_CMS
624 638
625static int 639static int
@@ -981,5 +995,7 @@ const EVP_PKEY_ASN1_METHOD eckey_asn1_meth = {
981 .pkey_free = int_ec_free, 995 .pkey_free = int_ec_free,
982 .pkey_ctrl = ec_pkey_ctrl, 996 .pkey_ctrl = ec_pkey_ctrl,
983 .old_priv_decode = old_ec_priv_decode, 997 .old_priv_decode = old_ec_priv_decode,
984 .old_priv_encode = old_ec_priv_encode 998 .old_priv_encode = old_ec_priv_encode,
999
1000 .pkey_check = ec_pkey_check,
985}; 1001};