I am running into a problem where BN_generate_prime
always returns a BIGNUM with the value 35879 if the
number of bits is less than 16. Here is an example
program that illustrates this:

$ ./BNTest 15
Bits: 15
1287302641 = 35879 * 35879
1287302641 = 35879 * 35879
1287302641 = 35879 * 35879
1287302641 = 35879 * 35879

$ ./BNTest 16 #works as expected
Bits: 16
3319015657 = 57503 * 57719
3203515489 = 61343 * 52223
2981297941 = 58403 * 51047
3599545897 = 58679 * 61343

$ cat BNTest.cpp

#include
#include

int main (int argc, char**argv)
{
if (argc < 2)
{
std::cerr << "Usage: BNTest " << std::endl;

return 1;
}

int bits = atoi (argv[1]);

std::cout << "Bits: " << bits << std::endl;

BN_CTX* ctx = BN_CTX_new();

BN_CTX_init (ctx);

BIGNUM* prime1 = BN_new();
BIGNUM* prime2 = BN_new();
BIGNUM* product = BN_new();

BN_init (prime1);
BN_init (prime2);
BN_init (product);

for (int i=0; i<4; ++i)
{
BN_generate_prime (prime1, bits, 0, 0, 0, 0, 0);
BN_generate_prime (prime2, bits, 0, 0, 0, 0, 0);

BN_mul (product, prime1, prime2, ctx);

char* pz_Prime1 = BN_bn2dec (prime1);
char* pz_Prime2 = BN_bn2dec (prime2);
char* pz_Product = BN_bn2dec (product);

std::cout << pz_Product << " = " << pz_Prime1 << " * ";
std::cout << pz_Prime2 << std::endl;
}

return 0;
}
__________________________________________________ ____________________
OpenSSL Project http://www.openssl.org
Development Mailing List openssl-dev@openssl.org
Automated List Manager majordomo@openssl.org