How to seed the PRNG for BN_generate_prime

◇◆丶佛笑我妖孽 提交于 2019-12-06 03:45:39

问题


I have not been able to find an answer as to what is used to generate the primes with BN_generate_prime in openssl/bn.h. Also, how would I seed whatever PRNG that this function uses?

Separate question but relevant to my code (I'm writing a program to generate RSA key pairs): how would I check if the high order bit is set in a BIGNUM? Say I generate a 512 bit prime. Would I use BN_is_bit_set(prime, 512)?

Thanks


回答1:


BN_generate_prime is a deprecated function, says here. Also, it is defined in crypto/bn_depr.c. You shouldn't use it to generate primes. Instead, you should use BN_generate_prime_ex. Here's the sample usage of BN_generate_prime_ex:

BIGNUM *r;
static const char rnd_seed[] = "string to make the random number generator think it has entropy";

r = BN_new();
RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_generate_prime_ex may fail */

BN_generate_prime_ex(r, 512, 0, NULL, NULL, NULL);

BN_free(r);

Then you'll have a 512-bit pseudo-random prime number. As the above example, you can seed the PRNG by RAND_seed.

For the second question, try BN_num_bits.



来源:https://stackoverflow.com/questions/18245901/how-to-seed-the-prng-for-bn-generate-prime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!