diff options
author | tb <> | 2023-11-29 13:39:34 +0000 |
---|---|---|
committer | tb <> | 2023-11-29 13:39:34 +0000 |
commit | 5fc61c757deaae46e25cc163ae9e92831528fbc8 (patch) | |
tree | f6fe9a9fb0e2f88a15ec1b3eb39c745c2618710c /src/lib/libssl/s3_lib.c | |
parent | 49adf1fb564c33009eb18992e86dac6577364047 (diff) | |
download | openbsd-5fc61c757deaae46e25cc163ae9e92831528fbc8.tar.gz openbsd-5fc61c757deaae46e25cc163ae9e92831528fbc8.tar.bz2 openbsd-5fc61c757deaae46e25cc163ae9e92831528fbc8.zip |
Convert ssl3_cipher_by_id() to bsearch()
This was previously the only user of OBJ_bsearch_ssl_cipher_id(), which
in turn is the one remaining user of OBJ_bsearch_() outside of libcrypto.
OBJ_bsearch_() is OpenSSL's idiosyncratic reimplementation of ANSI C89's
bsearch(). Since this used to be hidden behind macro insanity, the result
was three inscrutable layers of comparison functions.
It is much simpler and cleaner to use the standard API. Move all the code
to s3_lib.c, since it's ony used there.
In a few further diffs, OBJ_bsearch_() will be removed from libcrypto.
Unfortunately, we'll need to keep OBJ_bsearch_ex(), because it is
exposed via sk_find_ex(), which is exposed by M2Crypto...
ok jsing
Diffstat (limited to 'src/lib/libssl/s3_lib.c')
-rw-r--r-- | src/lib/libssl/s3_lib.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c index 9ac02f3e1b..1ae2d047bc 100644 --- a/src/lib/libssl/s3_lib.c +++ b/src/lib/libssl/s3_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: s3_lib.c,v 1.247 2023/11/29 13:29:34 tb Exp $ */ | 1 | /* $OpenBSD: s3_lib.c,v 1.248 2023/11/29 13:39:34 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 | * |
@@ -150,6 +150,7 @@ | |||
150 | 150 | ||
151 | #include <limits.h> | 151 | #include <limits.h> |
152 | #include <stdio.h> | 152 | #include <stdio.h> |
153 | #include <stdlib.h> | ||
153 | 154 | ||
154 | #include <openssl/bn.h> | 155 | #include <openssl/bn.h> |
155 | #include <openssl/curve25519.h> | 156 | #include <openssl/curve25519.h> |
@@ -1413,18 +1414,26 @@ ssl3_get_cipher(unsigned int u) | |||
1413 | return (NULL); | 1414 | return (NULL); |
1414 | } | 1415 | } |
1415 | 1416 | ||
1417 | static int | ||
1418 | ssl3_cipher_id_cmp(const void *id, const void *cipher) | ||
1419 | { | ||
1420 | unsigned long a = *(const unsigned long *)id; | ||
1421 | unsigned long b = ((const SSL_CIPHER *)cipher)->id; | ||
1422 | |||
1423 | return a < b ? -1 : a > b; | ||
1424 | } | ||
1425 | |||
1416 | const SSL_CIPHER * | 1426 | const SSL_CIPHER * |
1417 | ssl3_get_cipher_by_id(unsigned long id) | 1427 | ssl3_get_cipher_by_id(unsigned long id) |
1418 | { | 1428 | { |
1419 | const SSL_CIPHER *cp; | 1429 | const SSL_CIPHER *cipher; |
1420 | SSL_CIPHER c; | ||
1421 | 1430 | ||
1422 | c.id = id; | 1431 | cipher = bsearch(&id, ssl3_ciphers, SSL3_NUM_CIPHERS, sizeof(*cipher), |
1423 | cp = OBJ_bsearch_ssl_cipher_id(&c, ssl3_ciphers, SSL3_NUM_CIPHERS); | 1432 | ssl3_cipher_id_cmp); |
1424 | if (cp != NULL && cp->valid == 1) | 1433 | if (cipher != NULL && cipher->valid == 1) |
1425 | return (cp); | 1434 | return cipher; |
1426 | 1435 | ||
1427 | return (NULL); | 1436 | return NULL; |
1428 | } | 1437 | } |
1429 | 1438 | ||
1430 | const SSL_CIPHER * | 1439 | const SSL_CIPHER * |