randombit / botan

Cryptography Toolkit

Home Page:https://botan.randombit.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BigInt::random_integer hangs

guidovranken opened this issue · comments

#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;
}

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.

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.