summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2024-05-09 14:27:21 +0000
committertb <>2024-05-09 14:27:21 +0000
commit793963e6b67e060c4c0be063f9979e33d9761067 (patch)
treed9258e245c1b566a09ca60758ab951dfdd46c830 /src
parentd34c548d5800925083879ebf7ad4cd4f3513eca5 (diff)
downloadopenbsd-793963e6b67e060c4c0be063f9979e33d9761067.tar.gz
openbsd-793963e6b67e060c4c0be063f9979e33d9761067.tar.bz2
openbsd-793963e6b67e060c4c0be063f9979e33d9761067.zip
Streamline X509_REQ_check_private_key() a bit
Use better variable names, split the success from the error path and return directly rather than using an ok variable. ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/x509/x509_req.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c
index 06d445f18c..3d19c9ee4f 100644
--- a/src/lib/libcrypto/x509/x509_req.c
+++ b/src/lib/libcrypto/x509/x509_req.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_req.c,v 1.39 2024/05/09 14:22:16 tb Exp $ */ 1/* $OpenBSD: x509_req.c,v 1.40 2024/05/09 14:27:21 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -129,42 +129,43 @@ X509_REQ_get0_pubkey(X509_REQ *req)
129LCRYPTO_ALIAS(X509_REQ_get0_pubkey); 129LCRYPTO_ALIAS(X509_REQ_get0_pubkey);
130 130
131int 131int
132X509_REQ_check_private_key(X509_REQ *x, EVP_PKEY *k) 132X509_REQ_check_private_key(X509_REQ *req, EVP_PKEY *pkey)
133{ 133{
134 EVP_PKEY *xk = NULL; 134 EVP_PKEY *req_pubkey = NULL;
135 int ok = 0; 135 int ret;
136 136
137 if ((xk = X509_REQ_get0_pubkey(x)) == NULL) 137 if ((req_pubkey = X509_REQ_get0_pubkey(req)) == NULL)
138 return 0; 138 return 0;
139 139
140 switch (EVP_PKEY_cmp(xk, k)) { 140 if ((ret = EVP_PKEY_cmp(req_pubkey, pkey)) == 1)
141 case 1: 141 return 1;
142 ok = 1; 142
143 break; 143 switch (ret) {
144 case 0: 144 case 0:
145 X509error(X509_R_KEY_VALUES_MISMATCH); 145 X509error(X509_R_KEY_VALUES_MISMATCH);
146 break; 146 return 0;
147 case -1: 147 case -1:
148 X509error(X509_R_KEY_TYPE_MISMATCH); 148 X509error(X509_R_KEY_TYPE_MISMATCH);
149 break; 149 return 0;
150 case -2: 150 case -2:
151#ifndef OPENSSL_NO_EC 151#ifndef OPENSSL_NO_EC
152 if (k->type == EVP_PKEY_EC) { 152 if (pkey->type == EVP_PKEY_EC) {
153 X509error(ERR_R_EC_LIB); 153 X509error(ERR_R_EC_LIB);
154 break; 154 return 0;
155 } 155 }
156#endif 156#endif
157#ifndef OPENSSL_NO_DH 157#ifndef OPENSSL_NO_DH
158 if (k->type == EVP_PKEY_DH) { 158 if (pkey->type == EVP_PKEY_DH) {
159 /* No idea */ 159 /* No idea */
160 X509error(X509_R_CANT_CHECK_DH_KEY); 160 X509error(X509_R_CANT_CHECK_DH_KEY);
161 break; 161 return 0;
162 } 162 }
163#endif 163#endif
164 X509error(X509_R_UNKNOWN_KEY_TYPE); 164 X509error(X509_R_UNKNOWN_KEY_TYPE);
165 return 0;
165 } 166 }
166 167
167 return (ok); 168 return 0;
168} 169}
169LCRYPTO_ALIAS(X509_REQ_check_private_key); 170LCRYPTO_ALIAS(X509_REQ_check_private_key);
170 171