Select Git revision
bignum-next-prime.c
Forked from
Nettle / nettle
Source project has a limited visibility.
bignum-next-prime.c 4.08 KiB
/* bignum-next-prime.c
*
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Mller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <limits.h>
/* Needed for alloca on freebsd */
#include <stdlib.h>
#include "bignum.h"
#include "nettle-internal.h"
/* From gmp.h */
/* Test for gcc >= maj.min, as per __GNUC_PREREQ in glibc */
#if defined (__GNUC__) && defined (__GNUC_MINOR__)
#define GNUC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
#define GNUC_PREREQ(maj, min) 0
#endif
#if GNUC_PREREQ (3,0)
# define UNLIKELY(cond) __builtin_expect ((cond) != 0, 0)
#else
# define UNLIKELY(cond) cond
#endif
/* From some benchmarking using the examples nextprime(200!) and
nextprime(240!), it seems that it pays off to use a prime list up
to around 5000--10000 primes. There are 6541 odd primes less than
2^16. */
static const uint16_t primes[] = {
/* Generated by
./examples/eratosthenes 65535 \
| awk '{ if (NR % 10 == 2) printf ("\n"); if (NR > 1) printf("%d, ", $1); }
END { printf("\n"); }' > prime-list.h
*/
#include "prime-list.h"
};
#define NUMBER_OF_PRIMES (sizeof(primes) / sizeof(primes[0]))
#ifdef mpz_millerrabin
# define PRIME_P mpz_millerrabin
#else