Type-safe OBJ_bsearch_ex.
diff --git a/crypto/stack/safestack.h b/crypto/stack/safestack.h
index 9ed5fc2..58597c4 100644
--- a/crypto/stack/safestack.h
+++ b/crypto/stack/safestack.h
@@ -69,7 +69,7 @@
     ((void (*)(void *)) ((1 ? p : (void (*)(type))0)))
 
 #define CHECKED_SK_CMP_FUNC(type, p) \
-    ((int (*)(const void * const *, const void * const *)) \
+    ((int (*)(const void *, const void *)) \
 	((1 ? p : (int (*)(const type * const *, const type * const *))0)))
 
 #define STACK_OF(type) struct stack_st_##type
diff --git a/crypto/stack/stack.c b/crypto/stack/stack.c
index a58229a..76cf1a1 100644
--- a/crypto/stack/stack.c
+++ b/crypto/stack/stack.c
@@ -77,11 +77,10 @@
 
 #include <errno.h>
 
-int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void * const *,
-					   const void * const *)))
-		(const void * const *, const void * const *)
+int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *)))
+		(const void *, const void *)
 	{
-	int (*old)(const void * const *,const void * const *)=sk->comp;
+	int (*old)(const void *,const void *)=sk->comp;
 
 	if (sk->comp != c)
 		sk->sorted=0;
@@ -115,10 +114,10 @@
 
 _STACK *sk_new_null(void)
 	{
-	return sk_new((int (*)(const void * const *, const void * const *))0);
+	return sk_new((int (*)(const void *, const void *))0);
 	}
 
-_STACK *sk_new(int (*c)(const void * const *, const void * const *))
+_STACK *sk_new(int (*c)(const void *, const void *))
 	{
 	_STACK *ret;
 	int i;
@@ -213,9 +212,9 @@
 
 static int internal_find(_STACK *st, void *data, int ret_val_options)
 	{
-	char **r;
+	const void * const *r;
 	int i;
-	int (*comp_func)(const void *,const void *);
+
 	if(st == NULL) return -1;
 
 	if (st->comp == NULL)
@@ -227,17 +226,10 @@
 		}
 	sk_sort(st);
 	if (data == NULL) return(-1);
-	/* This (and the "qsort" below) are the two places in OpenSSL
-	 * where we need to convert from our standard (type **,type **)
-	 * compare callback type to the (void *,void *) type required by
-	 * bsearch. However, the "data" it is being called(back) with are
-	 * not (type *) pointers, but the *pointers* to (type *) pointers,
-	 * so we get our extra level of pointer dereferencing that way. */
-	comp_func=(int (*)(const void *,const void *))(st->comp);
-	r=(char **)OBJ_bsearch_ex((char *)&data,(char *)st->data,
-		st->num,sizeof(char *),comp_func,ret_val_options);
+	r=OBJ_bsearch_ex_(&data,st->data,st->num,sizeof(void *),st->comp,
+			  ret_val_options);
 	if (r == NULL) return(-1);
-	return((int)(r-st->data));
+	return (int)((char **)r-st->data);
 	}
 
 int sk_find(_STACK *st, void *data)
diff --git a/crypto/stack/stack.h b/crypto/stack/stack.h
index 70f78aa..ce35e55 100644
--- a/crypto/stack/stack.h
+++ b/crypto/stack/stack.h
@@ -70,7 +70,7 @@
 	int sorted;
 
 	int num_alloc;
-	int (*comp)(const void * const *, const void * const *);
+	int (*comp)(const void *, const void *);
 	} _STACK;  /* Use STACK_OF(...) instead */
 
 #define M_sk_num(sk)		((sk) ? (sk)->num:-1)
@@ -81,7 +81,7 @@
 
 void *sk_set(_STACK *, int, void *);
 
-_STACK *sk_new(int (*cmp)(const void * const *, const void * const *));
+_STACK *sk_new(int (*cmp)(const void *, const void *));
 _STACK *sk_new_null(void);
 void sk_free(_STACK *);
 void sk_pop_free(_STACK *st, void (*func)(void *));
@@ -95,9 +95,8 @@
 void *sk_shift(_STACK *st);
 void *sk_pop(_STACK *st);
 void sk_zero(_STACK *st);
-int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void * const *,
-					   const void * const *)))
-	(const void * const *, const void * const *);
+int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *)))
+	(const void *, const void *);
 _STACK *sk_dup(_STACK *st);
 void sk_sort(_STACK *st);
 int sk_is_sorted(const _STACK *st);