BigInt::random_integer hangs
guidovranken opened this issue · 3 comments
guidovranken commented
#include <botan/bigint.h>
#include <botan/system_rng.h>
int main(void)
{
using namespace Botan;
System_RNG rng;
BigInt A("0x1fec2433a4401374b0220cf2f92f7ac3a5a84610ff4896118525dfc6a556dfbf9ce2698c20cfc780");
BigInt B("0x1fec2433a4401374b0220cf2f92f8735d4b73fe909f5fa3658d30b423d4630b4dce2698c20cfc780");
BigInt::random_integer(rng, A, B);
return 0;
}
guidovranken commented
This is random_integer
:
const size_t bits = max.bits();
do {
r.randomize(rng, bits, false);
} while(r < min || r >= max);
I guess it will finish eventually, but it might be better to do generate an int in the range 0..max-min
and then add min
.
randombit commented
Confirmed, thanks. We'll have to be careful about changing the logic as a number of tests rely on the current behavior, but obviously taking forever on certain inputs is no good. I'll take a look.
randombit commented
@guidovranken Fixed now