Skip to content

Commit 81027b7

Browse files
committed
pkey: remove unused ossl_generate_cb_2() helper function
The previous series of commits re-implemented key generation with the low level API with the EVP API. The BN_GENCB-based callback function is no longer used.
1 parent 1800a8d commit 81027b7

File tree

4 files changed

+15
-81
lines changed

4 files changed

+15
-81
lines changed

ext/openssl/extconf.rb

-3
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ def find_openssl_library
130130
if !have_struct_member("SSL", "ctx", "openssl/ssl.h") || is_libressl
131131
$defs.push("-DHAVE_OPAQUE_OPENSSL")
132132
end
133-
have_func("BN_GENCB_new")
134-
have_func("BN_GENCB_free")
135-
have_func("BN_GENCB_get_arg")
136133
have_func("EVP_MD_CTX_new")
137134
have_func("EVP_MD_CTX_free")
138135
have_func("EVP_MD_CTX_pkey_ctx")

ext/openssl/openssl_missing.h

-12
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@
1313
#include "ruby/config.h"
1414

1515
/* added in 1.1.0 */
16-
#if !defined(HAVE_BN_GENCB_NEW)
17-
# define BN_GENCB_new() ((BN_GENCB *)OPENSSL_malloc(sizeof(BN_GENCB)))
18-
#endif
19-
20-
#if !defined(HAVE_BN_GENCB_FREE)
21-
# define BN_GENCB_free(cb) OPENSSL_free(cb)
22-
#endif
23-
24-
#if !defined(HAVE_BN_GENCB_GET_ARG)
25-
# define BN_GENCB_get_arg(cb) (cb)->arg
26-
#endif
27-
2816
#if !defined(HAVE_EVP_MD_CTX_NEW)
2917
# define EVP_MD_CTX_new EVP_MD_CTX_create
3018
#endif

ext/openssl/ossl_pkey.c

+15-58
Original file line numberDiff line numberDiff line change
@@ -17,64 +17,6 @@ VALUE cPKey;
1717
VALUE ePKeyError;
1818
static ID id_private_q;
1919

20-
/*
21-
* callback for generating keys
22-
*/
23-
static VALUE
24-
call_check_ints0(VALUE arg)
25-
{
26-
rb_thread_check_ints();
27-
return Qnil;
28-
}
29-
30-
static void *
31-
call_check_ints(void *arg)
32-
{
33-
int state;
34-
rb_protect(call_check_ints0, Qnil, &state);
35-
return (void *)(VALUE)state;
36-
}
37-
38-
int
39-
ossl_generate_cb_2(int p, int n, BN_GENCB *cb)
40-
{
41-
VALUE ary;
42-
struct ossl_generate_cb_arg *arg;
43-
int state;
44-
45-
arg = (struct ossl_generate_cb_arg *)BN_GENCB_get_arg(cb);
46-
if (arg->yield) {
47-
ary = rb_ary_new2(2);
48-
rb_ary_store(ary, 0, INT2NUM(p));
49-
rb_ary_store(ary, 1, INT2NUM(n));
50-
51-
/*
52-
* can be break by raising exception or 'break'
53-
*/
54-
rb_protect(rb_yield, ary, &state);
55-
if (state) {
56-
arg->state = state;
57-
return 0;
58-
}
59-
}
60-
if (arg->interrupted) {
61-
arg->interrupted = 0;
62-
state = (int)(VALUE)rb_thread_call_with_gvl(call_check_ints, NULL);
63-
if (state) {
64-
arg->state = state;
65-
return 0;
66-
}
67-
}
68-
return 1;
69-
}
70-
71-
void
72-
ossl_generate_cb_stop(void *ptr)
73-
{
74-
struct ossl_generate_cb_arg *arg = (struct ossl_generate_cb_arg *)ptr;
75-
arg->interrupted = 1;
76-
}
77-
7820
static void
7921
ossl_evp_pkey_free(void *ptr)
8022
{
@@ -247,6 +189,21 @@ pkey_gen_cb_yield(VALUE ctx_v)
247189
return rb_yield_values2(info_num, argv);
248190
}
249191

192+
static VALUE
193+
call_check_ints0(VALUE arg)
194+
{
195+
rb_thread_check_ints();
196+
return Qnil;
197+
}
198+
199+
static void *
200+
call_check_ints(void *arg)
201+
{
202+
int state;
203+
rb_protect(call_check_ints0, Qnil, &state);
204+
return (void *)(VALUE)state;
205+
}
206+
250207
static int
251208
pkey_gen_cb(EVP_PKEY_CTX *ctx)
252209
{

ext/openssl/ossl_pkey.h

-8
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ extern const rb_data_type_t ossl_evp_pkey_type;
3535
} \
3636
} while (0)
3737

38-
struct ossl_generate_cb_arg {
39-
int yield;
40-
int interrupted;
41-
int state;
42-
};
43-
int ossl_generate_cb_2(int p, int n, BN_GENCB *cb);
44-
void ossl_generate_cb_stop(void *ptr);
45-
4638
VALUE ossl_pkey_new(EVP_PKEY *);
4739
void ossl_pkey_check_public_key(const EVP_PKEY *);
4840
EVP_PKEY *ossl_pkey_read_generic(BIO *, VALUE);

0 commit comments

Comments
 (0)