diff options
author | tb <> | 2023-12-31 07:10:50 +0000 |
---|---|---|
committer | tb <> | 2023-12-31 07:10:50 +0000 |
commit | d83edf70858d6ac0a41bd10ccb0cdbf2d3e50d65 (patch) | |
tree | b67ab2a9271b85b97d7399af3b6372543e9fef0e /src | |
parent | 3b2fc95f50e9b969801ba433a5bfb320d1e5cd62 (diff) | |
download | openbsd-d83edf70858d6ac0a41bd10ccb0cdbf2d3e50d65.tar.gz openbsd-d83edf70858d6ac0a41bd10ccb0cdbf2d3e50d65.tar.bz2 openbsd-d83edf70858d6ac0a41bd10ccb0cdbf2d3e50d65.zip |
Replace the sorted extensions lookup with a switch
If all you have is OBJ_bsearch_(), everything looks like a nail. This
changes a binary search over a list of 12 elements with a lookup via
a switch.
switch suggested by claudio
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/x509/x509_purp.c | 81 |
1 files changed, 23 insertions, 58 deletions
diff --git a/src/lib/libcrypto/x509/x509_purp.c b/src/lib/libcrypto/x509/x509_purp.c index 999ba639c5..8b8075b00e 100644 --- a/src/lib/libcrypto/x509/x509_purp.c +++ b/src/lib/libcrypto/x509/x509_purp.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_purp.c,v 1.30 2023/11/13 10:33:00 tb Exp $ */ | 1 | /* $OpenBSD: x509_purp.c,v 1.31 2023/12/31 07:10:50 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 2001. | 3 | * project 2001. |
4 | */ | 4 | */ |
@@ -386,68 +386,33 @@ X509_PURPOSE_get_trust(const X509_PURPOSE *xp) | |||
386 | } | 386 | } |
387 | LCRYPTO_ALIAS(X509_PURPOSE_get_trust); | 387 | LCRYPTO_ALIAS(X509_PURPOSE_get_trust); |
388 | 388 | ||
389 | static int | 389 | /* |
390 | nid_cmp(const int *a, const int *b) | 390 | * List of NIDs of extensions supported by the verifier. If an extension |
391 | { | 391 | * is critical and doesn't appear in this list, then the certificate will |
392 | return *a - *b; | 392 | * normally be rejected. |
393 | } | 393 | */ |
394 | |||
395 | static int nid_cmp_BSEARCH_CMP_FN(const void *, const void *); | ||
396 | static int nid_cmp(int const *, int const *); | ||
397 | static int *OBJ_bsearch_nid(int *key, int const *base, int num); | ||
398 | |||
399 | static int | ||
400 | nid_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) | ||
401 | { | ||
402 | int const *a = a_; | ||
403 | int const *b = b_; | ||
404 | return nid_cmp(a, b); | ||
405 | } | ||
406 | |||
407 | static int * | ||
408 | OBJ_bsearch_nid(int *key, int const *base, int num) | ||
409 | { | ||
410 | return (int *)OBJ_bsearch_(key, base, num, sizeof(int), | ||
411 | nid_cmp_BSEARCH_CMP_FN); | ||
412 | } | ||
413 | |||
414 | int | 394 | int |
415 | X509_supported_extension(X509_EXTENSION *ex) | 395 | X509_supported_extension(X509_EXTENSION *ext) |
416 | { | 396 | { |
417 | /* This table is a list of the NIDs of supported extensions: | 397 | switch(OBJ_obj2nid(X509_EXTENSION_get_object(ext))) { |
418 | * that is those which are used by the verify process. If | 398 | case NID_netscape_cert_type: |
419 | * an extension is critical and doesn't appear in this list | 399 | case NID_key_usage: |
420 | * then the verify process will normally reject the certificate. | 400 | case NID_subject_alt_name: |
421 | * The list must be kept in numerical order because it will be | 401 | case NID_basic_constraints: |
422 | * searched using bsearch. | 402 | case NID_certificate_policies: |
423 | */ | 403 | case NID_ext_key_usage: |
424 | |||
425 | static const int supported_nids[] = { | ||
426 | NID_netscape_cert_type, /* 71 */ | ||
427 | NID_key_usage, /* 83 */ | ||
428 | NID_subject_alt_name, /* 85 */ | ||
429 | NID_basic_constraints, /* 87 */ | ||
430 | NID_certificate_policies, /* 89 */ | ||
431 | NID_ext_key_usage, /* 126 */ | ||
432 | #ifndef OPENSSL_NO_RFC3779 | 404 | #ifndef OPENSSL_NO_RFC3779 |
433 | NID_sbgp_ipAddrBlock, /* 290 */ | 405 | case NID_sbgp_ipAddrBlock: |
434 | NID_sbgp_autonomousSysNum, /* 291 */ | 406 | case NID_sbgp_autonomousSysNum: |
435 | #endif | 407 | #endif |
436 | NID_policy_constraints, /* 401 */ | 408 | case NID_policy_constraints: |
437 | NID_name_constraints, /* 666 */ | 409 | case NID_name_constraints: |
438 | NID_policy_mappings, /* 747 */ | 410 | case NID_policy_mappings: |
439 | NID_inhibit_any_policy /* 748 */ | 411 | case NID_inhibit_any_policy: |
440 | }; | ||
441 | |||
442 | int ex_nid = OBJ_obj2nid(X509_EXTENSION_get_object(ex)); | ||
443 | |||
444 | if (ex_nid == NID_undef) | ||
445 | return 0; | ||
446 | |||
447 | if (OBJ_bsearch_nid(&ex_nid, supported_nids, | ||
448 | sizeof(supported_nids) / sizeof(int))) | ||
449 | return 1; | 412 | return 1; |
450 | return 0; | 413 | default: |
414 | return 0; | ||
415 | } | ||
451 | } | 416 | } |
452 | LCRYPTO_ALIAS(X509_supported_extension); | 417 | LCRYPTO_ALIAS(X509_supported_extension); |
453 | 418 | ||