ruby-changes:43199
From: rhe <ko1@a...>
Date: Sat, 4 Jun 2016 11:35:14 +0900 (JST)
Subject: [ruby-changes:43199] rhe:r55273 (trunk): openssl: avoid deprecated BN_*prime* functions
rhe 2016-06-04 11:35:09 +0900 (Sat, 04 Jun 2016) New Revision: 55273 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55273 Log: openssl: avoid deprecated BN_*prime* functions * ext/openssl/ossl_bn.c (ossl_bn_s_generate_prime, ossl_bn_is_prime, ossl_bn_is_prime_fasttest): Avoid deprecated BN_generate_prime(), BN_is_prime{,_fasttest}(). They are deprecated because they expect an old style callback function (we don't use it here). They can be simply replaced by _ex suffixed functions. Modified files: trunk/ext/openssl/ossl_bn.c Index: ext/openssl/ossl_bn.c =================================================================== --- ext/openssl/ossl_bn.c (revision 55272) +++ ext/openssl/ossl_bn.c (revision 55273) @@ -743,6 +743,10 @@ BIGNUM_RAND_RANGE(pseudo_rand) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bn.c#L743 * call-seq: * BN.generate_prime(bits, [, safe [, add [, rem]]]) => bn * + * Generates a random prime number of bit length +bits+. If +safe+ is true, + * generates a safe prime. If +add+ is specified, generates a prime that + * fulfills condition <tt>p % add = rem</tt>. + * * === Parameters * * +bits+ - integer * * +safe+ - boolean @@ -771,7 +775,7 @@ ossl_bn_s_generate_prime(int argc, VALUE https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bn.c#L775 if (!(result = BN_new())) { ossl_raise(eBNError, NULL); } - if (!BN_generate_prime(result, num, safe, add, rem, NULL, NULL)) { + if (!BN_generate_prime_ex(result, num, safe, add, rem, NULL)) { BN_free(result); ossl_raise(eBNError, NULL); } @@ -922,6 +926,10 @@ ossl_bn_hash(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bn.c#L926 * bn.prime? => true | false * bn.prime?(checks) => true | false * + * Performs a Miller-Rabin probabilistic primality test with +checks+ + * iterations. If +nchecks+ is not specified, a number of iterations is used + * that yields a false positive rate of at most 2^-80 for random input. + * * === Parameters * * +checks+ - integer */ @@ -936,7 +944,7 @@ ossl_bn_is_prime(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bn.c#L944 checks = NUM2INT(vchecks); } GetBN(self, bn); - switch (BN_is_prime(bn, checks, NULL, ossl_bn_ctx, NULL)) { + switch (BN_is_prime_ex(bn, checks, ossl_bn_ctx, NULL)) { case 1: return Qtrue; case 0: @@ -954,6 +962,9 @@ ossl_bn_is_prime(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bn.c#L962 * bn.prime_fasttest?(checks) => true | false * bn.prime_fasttest?(checks, trial_div) => true | false * + * Performs a Miller-Rabin primality test. This is same as #prime? except this + * first attempts trial divisions with some small primes. + * * === Parameters * * +checks+ - integer * * +trial_div+ - boolean @@ -975,7 +986,7 @@ ossl_bn_is_prime_fasttest(int argc, VALU https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bn.c#L986 if (vtrivdiv == Qfalse) { do_trial_division = 0; } - switch (BN_is_prime_fasttest(bn, checks, NULL, ossl_bn_ctx, NULL, do_trial_division)) { + switch (BN_is_prime_fasttest_ex(bn, checks, ossl_bn_ctx, do_trial_division, NULL)) { case 1: return Qtrue; case 0: @@ -1065,6 +1076,7 @@ Init_ossl_bn(void) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bn.c#L1076 rb_define_singleton_method(cBN, "generate_prime", ossl_bn_s_generate_prime, -1); rb_define_method(cBN, "prime?", ossl_bn_is_prime, -1); + rb_define_method(cBN, "prime_fasttest?", ossl_bn_is_prime_fasttest, -1); rb_define_method(cBN, "set_bit!", ossl_bn_set_bit, 1); rb_define_method(cBN, "clear_bit!", ossl_bn_clear_bit, 1); @@ -1106,10 +1118,4 @@ Init_ossl_bn(void) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bn.c#L1118 /* RECiProcal * MONTgomery */ - - /* - * TODO: - * Where to belong these? - */ - rb_define_method(cBN, "prime_fasttest?", ossl_bn_is_prime_fasttest, -1); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/