Skip to content

Commit 23866ac

Browse files
committed
include wrappers for deprecated openssl functions in openssl_missing.g
1 parent c98741a commit 23866ac

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

ext/openssl/extconf.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@
7171
have_func("BN_mod_sub")
7272
have_func("BN_pseudo_rand_range")
7373
have_func("BN_rand_range")
74+
have_func("BN_generate_prime")
75+
have_func("BN_generate_prime_ex")
76+
have_func("BN_is_prime")
77+
have_func("BN_is_prime_ex")
78+
have_func("BN_is_prime_fasttest")
79+
have_func("BN_is_prime_fasttest_ex")
7480
have_func("CONF_get1_default_config_file")
7581
have_func("EVP_CIPHER_CTX_copy")
7682
have_func("EVP_CIPHER_CTX_set_padding")
@@ -88,6 +94,8 @@
8894
have_func("PEM_def_callback")
8995
have_func("PKCS5_PBKDF2_HMAC")
9096
have_func("PKCS5_PBKDF2_HMAC_SHA1")
97+
have_func("RSA_generate_key")
98+
have_func("RSA_generate_key_ex")
9199
have_func("X509V3_set_nconf")
92100
have_func("X509V3_EXT_nconf_nid")
93101
have_func("X509_CRL_add0_revoked")

ext/openssl/openssl_missing.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,86 @@ ASN1_put_eoc(unsigned char **pp)
354354
}
355355
#endif
356356

357+
#if !defined(HAVE_BN_GENERATE_PRIME) && defined(HAVE_BN_GENERATE_PRIME_EX)
358+
BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe,
359+
const BIGNUM *add, const BIGNUM *rem,
360+
void (*callback)(int,int,void *), void *cb_arg)
361+
{
362+
BN_GENCB cb;
363+
BIGNUM *rnd=NULL;
364+
int found = 0;
365+
366+
BN_GENCB_set_old(&cb, callback, cb_arg);
367+
368+
if (ret == NULL)
369+
{
370+
if ((rnd=BN_new()) == NULL) goto err;
371+
}
372+
else
373+
rnd=ret;
374+
if(!BN_generate_prime_ex(rnd, bits, safe, add, rem, &cb))
375+
goto err;
376+
377+
/* we have a prime :-) */
378+
found = 1;
379+
err:
380+
if (!found && (ret == NULL) && (rnd != NULL)) BN_free(rnd);
381+
return(found ? rnd : NULL);
382+
}
383+
#endif
384+
385+
#if !defined(HAVE_BN_IS_PRIME) && defined(HAVE_BN_IS_PRIME_EX)
386+
int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int,int,void *),
387+
BN_CTX *ctx_passed, void *cb_arg)
388+
{
389+
BN_GENCB cb;
390+
BN_GENCB_set_old(&cb, callback, cb_arg);
391+
return BN_is_prime_ex(a, checks, ctx_passed, &cb);
392+
}
393+
#endif
394+
395+
#if !defined(HAVE_BN_IS_PRIME_FASTTEST) && defined(HAVE_BN_IS_PRIME_FASTTEST_EX)
396+
int BN_is_prime_fasttest(const BIGNUM *a, int checks,
397+
void (*callback)(int,int,void *),
398+
BN_CTX *ctx_passed, void *cb_arg,
399+
int do_trial_division)
400+
{
401+
BN_GENCB cb;
402+
BN_GENCB_set_old(&cb, callback, cb_arg);
403+
return BN_is_prime_fasttest_ex(a, checks, ctx_passed,
404+
do_trial_division, &cb);
405+
}
406+
#endif
407+
408+
#if !defined(HAVE_RSA_GENERATE_KEY) && defined(HAVE_RSA_GENERATE_KEY_EX)
409+
RSA *RSA_generate_key(int bits, unsigned long e_value,
410+
void (*callback)(int,int,void *), void *cb_arg)
411+
{
412+
BN_GENCB cb;
413+
int i;
414+
RSA *rsa = RSA_new();
415+
BIGNUM *e = BN_new();
416+
417+
if(!rsa || !e) goto err;
418+
419+
/* The problem is when building with 8, 16, or 32 BN_ULONG,
420+
* unsigned long can be larger */
421+
for (i=0; i<(int)sizeof(unsigned long)*8; i++)
422+
{
423+
if (e_value & (1UL<<i))
424+
if (BN_set_bit(e,i) == 0)
425+
goto err;
426+
}
427+
428+
BN_GENCB_set_old(&cb, callback, cb_arg);
429+
430+
if(RSA_generate_key_ex(rsa, bits, e, &cb)) {
431+
BN_free(e);
432+
return rsa;
433+
}
434+
err:
435+
if(e) BN_free(e);
436+
if(rsa) RSA_free(rsa);
437+
return 0;
438+
}
439+
#endif

0 commit comments

Comments
 (0)