@@ -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