diff options
author | tb <> | 2023-12-18 13:12:43 +0000 |
---|---|---|
committer | tb <> | 2023-12-18 13:12:43 +0000 |
commit | 0e07bfe346298d2a344167ad16d300f830c4b9ea (patch) | |
tree | d84d92c0267ba7d14fe9563c90cec3cf8a34f5db /src | |
parent | c26db91390a6a2fa9512451cc31a041ce2aaa23d (diff) | |
download | openbsd-0e07bfe346298d2a344167ad16d300f830c4b9ea.tar.gz openbsd-0e07bfe346298d2a344167ad16d300f830c4b9ea.tar.bz2 openbsd-0e07bfe346298d2a344167ad16d300f830c4b9ea.zip |
Clean up EVP_PBE_CipherInit() a little
This is mostly stylistic cleanup, making the control flow a bit more
obvious. There's one user-visible change: we no longer go out of our
way to provide info about the unknown algorithm. The nid is enough.
ok joshua jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/evp/evp_pbe.c | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c index 94658f8797..8553478bc4 100644 --- a/src/lib/libcrypto/evp/evp_pbe.c +++ b/src/lib/libcrypto/evp/evp_pbe.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp_pbe.c,v 1.33 2023/12/16 14:09:33 tb Exp $ */ | 1 | /* $OpenBSD: evp_pbe.c,v 1.34 2023/12/18 13:12: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 1999. | 3 | * project 1999. |
4 | */ | 4 | */ |
@@ -269,43 +269,35 @@ int | |||
269 | EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, | 269 | EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, |
270 | ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de) | 270 | ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de) |
271 | { | 271 | { |
272 | const EVP_CIPHER *cipher; | 272 | const EVP_CIPHER *cipher = NULL; |
273 | const EVP_MD *md; | 273 | const EVP_MD *md = NULL; |
274 | int cipher_nid, md_nid; | 274 | int pbe_nid, cipher_nid, md_nid; |
275 | EVP_PBE_KEYGEN *keygen; | 275 | EVP_PBE_KEYGEN *keygen; |
276 | 276 | ||
277 | if (!EVP_PBE_find(EVP_PBE_TYPE_OUTER, OBJ_obj2nid(pbe_obj), | 277 | if ((pbe_nid = OBJ_obj2nid(pbe_obj)) == NID_undef) { |
278 | &cipher_nid, &md_nid, &keygen)) { | ||
279 | char obj_tmp[80]; | ||
280 | EVPerror(EVP_R_UNKNOWN_PBE_ALGORITHM); | 278 | EVPerror(EVP_R_UNKNOWN_PBE_ALGORITHM); |
281 | if (!pbe_obj) | 279 | return 0; |
282 | strlcpy(obj_tmp, "NULL", sizeof obj_tmp); | 280 | } |
283 | else | 281 | if (!EVP_PBE_find(EVP_PBE_TYPE_OUTER, pbe_nid, &cipher_nid, &md_nid, |
284 | i2t_ASN1_OBJECT(obj_tmp, sizeof obj_tmp, pbe_obj); | 282 | &keygen)) { |
285 | ERR_asprintf_error_data("TYPE=%s", obj_tmp); | 283 | EVPerror(EVP_R_UNKNOWN_PBE_ALGORITHM); |
284 | ERR_asprintf_error_data("NID=%d", pbe_nid); | ||
286 | return 0; | 285 | return 0; |
287 | } | 286 | } |
288 | 287 | ||
289 | if (!pass) | 288 | if (pass == NULL) |
290 | passlen = 0; | 289 | passlen = 0; |
291 | else if (passlen == -1) | 290 | if (passlen == -1) |
292 | passlen = strlen(pass); | 291 | passlen = strlen(pass); |
293 | 292 | ||
294 | if (cipher_nid == -1) | 293 | if (cipher_nid != -1) { |
295 | cipher = NULL; | 294 | if ((cipher = EVP_get_cipherbynid(cipher_nid)) == NULL) { |
296 | else { | ||
297 | cipher = EVP_get_cipherbynid(cipher_nid); | ||
298 | if (!cipher) { | ||
299 | EVPerror(EVP_R_UNKNOWN_CIPHER); | 295 | EVPerror(EVP_R_UNKNOWN_CIPHER); |
300 | return 0; | 296 | return 0; |
301 | } | 297 | } |
302 | } | 298 | } |
303 | 299 | if (md_nid != -1) { | |
304 | if (md_nid == -1) | 300 | if ((md = EVP_get_digestbynid(md_nid)) == NULL) { |
305 | md = NULL; | ||
306 | else { | ||
307 | md = EVP_get_digestbynid(md_nid); | ||
308 | if (!md) { | ||
309 | EVPerror(EVP_R_UNKNOWN_DIGEST); | 301 | EVPerror(EVP_R_UNKNOWN_DIGEST); |
310 | return 0; | 302 | return 0; |
311 | } | 303 | } |
@@ -315,6 +307,7 @@ EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, | |||
315 | EVPerror(EVP_R_KEYGEN_FAILURE); | 307 | EVPerror(EVP_R_KEYGEN_FAILURE); |
316 | return 0; | 308 | return 0; |
317 | } | 309 | } |
310 | |||
318 | return 1; | 311 | return 1; |
319 | } | 312 | } |
320 | 313 | ||