In article <M_GdnQ_nKqkQECPRnZ2dnUVZ8n->,
says...
>
> superpollo wrote:
> > Ben Bacarisse ha scritto:
> [...]
> >> I spoke too soon about the cast. It may well do some good in that
> >>
> >> b <= (unsigned long)sqrt(*n)
> >>
> >> might be faster than
> >>
> >> b <= sqtr(*n)
> >>
> >
> > maybe b*b <= *n could be even faster...
>
> Be aware that if (*n > 4294836225), once b reaches the value of
> 65535, the next iteration will assign b the number 65536, but
> 65536 * 65536 == 4294967296. So, if ULONG_MAX == 4294967295, as it
> is on most 32bit architectures, the product (b * b) overflows. That
> means that (b * b) yields 0, because the exact arithmetic result of
> (b * b) will be reduced modulo ULONG_MAX + 1. Therefore, the loop
> becomes infinite.
The problem as stated at the site is preposterous.
For an integer to be useful for cryptographic purposes, it should
{generally} be hundreds of bits in length.
Crypto systems typically use libraries like MPIR for large integers.
Perusal of these openssl archives (for instance) will show that tiny, 32
bit integers are not useful for crypto purposes (other than things like
a loop counter in the source code):
http://www.openssl.org/source/
Hence, as a lower bound for primes, even something like this is much too
small for cryptographic purposes:
5773711106117539064689094729932307
Most of the time type unsigned long long is not large enough. There are
exceptions, of course (e.g. someone might get by with even a 64 bit
message digest like UMAC if the information transmitted is not of great
value).