-/* $OpenBSD: s3_lib.c,v 1.247 2023/11/29 13:29:34 tb Exp $ */
+/* $OpenBSD: s3_lib.c,v 1.248 2023/11/29 13:39:34 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#include <limits.h>
#include <stdio.h>
+#include <stdlib.h>
#include <openssl/bn.h>
#include <openssl/curve25519.h>
return (NULL);
}
+static int
+ssl3_cipher_id_cmp(const void *id, const void *cipher)
+{
+ unsigned long a = *(const unsigned long *)id;
+ unsigned long b = ((const SSL_CIPHER *)cipher)->id;
+
+ return a < b ? -1 : a > b;
+}
+
const SSL_CIPHER *
ssl3_get_cipher_by_id(unsigned long id)
{
- const SSL_CIPHER *cp;
- SSL_CIPHER c;
+ const SSL_CIPHER *cipher;
- c.id = id;
- cp = OBJ_bsearch_ssl_cipher_id(&c, ssl3_ciphers, SSL3_NUM_CIPHERS);
- if (cp != NULL && cp->valid == 1)
- return (cp);
+ cipher = bsearch(&id, ssl3_ciphers, SSL3_NUM_CIPHERS, sizeof(*cipher),
+ ssl3_cipher_id_cmp);
+ if (cipher != NULL && cipher->valid == 1)
+ return cipher;
- return (NULL);
+ return NULL;
}
const SSL_CIPHER *
-/* $OpenBSD: ssl_lib.c,v 1.316 2023/11/25 12:05:08 tb Exp $ */
+/* $OpenBSD: ssl_lib.c,v 1.317 2023/11/29 13:39:34 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
/* Not supported. */
}
LSSL_ALIAS(SSL_set_quic_use_legacy_codepoint);
-
-static int
-ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b)
-{
- long l;
-
- l = a->id - b->id;
- if (l == 0L)
- return (0);
- else
- return ((l > 0) ? 1:-1);
-}
-
-static int
-ssl_cipher_id_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)
-{
- SSL_CIPHER const *a = a_;
- SSL_CIPHER const *b = b_;
- return ssl_cipher_id_cmp(a, b);
-}
-
-SSL_CIPHER *
-OBJ_bsearch_ssl_cipher_id(SSL_CIPHER *key, SSL_CIPHER const *base, int num)
-{
- return (SSL_CIPHER *)OBJ_bsearch_(key, base, num, sizeof(SSL_CIPHER),
- ssl_cipher_id_cmp_BSEARCH_CMP_FN);
-}
-/* $OpenBSD: ssl_local.h,v 1.10 2023/11/29 13:29:34 tb Exp $ */
+/* $OpenBSD: ssl_local.h,v 1.11 2023/11/29 13:39:34 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
int ssl_get_new_session(SSL *s, int session);
int ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block,
int *alert);
-SSL_CIPHER *OBJ_bsearch_ssl_cipher_id(SSL_CIPHER *key, SSL_CIPHER const *base,
- int num);
int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *ciphers, CBB *cbb);
STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, CBS *cbs);
STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,