|
Packit |
5c3484 |
/* gmp_randinit_lc_2exp_size -- initialize a random state with a linear
|
|
Packit |
5c3484 |
congruential generator of a requested size.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
Copyright 1999-2001 Free Software Foundation, Inc.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
This file is part of the GNU MP Library.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
The GNU MP Library is free software; you can redistribute it and/or modify
|
|
Packit |
5c3484 |
it under the terms of either:
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
* the GNU Lesser General Public License as published by the Free
|
|
Packit |
5c3484 |
Software Foundation; either version 3 of the License, or (at your
|
|
Packit |
5c3484 |
option) any later version.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
or
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
* the GNU General Public License as published by the Free Software
|
|
Packit |
5c3484 |
Foundation; either version 2 of the License, or (at your option) any
|
|
Packit |
5c3484 |
later version.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
or both in parallel, as here.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
The GNU MP Library is distributed in the hope that it will be useful, but
|
|
Packit |
5c3484 |
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
Packit |
5c3484 |
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
Packit |
5c3484 |
for more details.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
You should have received copies of the GNU General Public License and the
|
|
Packit |
5c3484 |
GNU Lesser General Public License along with the GNU MP Library. If not,
|
|
Packit |
5c3484 |
see https://www.gnu.org/licenses/. */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
#include <stdio.h> /* for NULL */
|
|
Packit |
5c3484 |
#include "gmp.h"
|
|
Packit |
5c3484 |
#include "gmp-impl.h"
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
/* Array of LC-schemes, ordered in increasing order of the first
|
|
Packit |
5c3484 |
member (the 'm2exp' value). The end of the array is indicated with
|
|
Packit |
5c3484 |
an entry containing all zeros. */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
/* All multipliers are in the range 0.01*m and 0.99*m, and are
|
|
Packit |
5c3484 |
congruent to 5 (mod 8).
|
|
Packit |
5c3484 |
They all pass the spectral test with Vt >= 2^(30/t) and merit >= 1.
|
|
Packit |
5c3484 |
(Up to and including 196 bits, merit is >= 3.) */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
struct __gmp_rand_lc_scheme_struct
|
|
Packit |
5c3484 |
{
|
|
Packit |
5c3484 |
unsigned long int m2exp; /* Modulus is 2 ^ m2exp. */
|
|
Packit |
5c3484 |
const char *astr; /* Multiplier in string form. */
|
|
Packit |
5c3484 |
unsigned long int c; /* Addend. */
|
|
Packit |
5c3484 |
};
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
static const struct __gmp_rand_lc_scheme_struct __gmp_rand_lc_scheme[] =
|
|
Packit |
5c3484 |
{
|
|
Packit |
5c3484 |
{32, "29CF535", 1},
|
|
Packit |
5c3484 |
{33, "51F666D", 1},
|
|
Packit |
5c3484 |
{34, "A3D73AD", 1},
|
|
Packit |
5c3484 |
{35, "147E5B85", 1},
|
|
Packit |
5c3484 |
{36, "28F725C5", 1},
|
|
Packit |
5c3484 |
{37, "51EE3105", 1},
|
|
Packit |
5c3484 |
{38, "A3DD5CDD", 1},
|
|
Packit |
5c3484 |
{39, "147AF833D", 1},
|
|
Packit |
5c3484 |
{40, "28F5DA175", 1},
|
|
Packit |
5c3484 |
{56, "AA7D735234C0DD", 1},
|
|
Packit |
5c3484 |
{64, "BAECD515DAF0B49D", 1},
|
|
Packit |
5c3484 |
{100, "292787EBD3329AD7E7575E2FD", 1},
|
|
Packit |
5c3484 |
{128, "48A74F367FA7B5C8ACBB36901308FA85", 1},
|
|
Packit |
5c3484 |
{156, "78A7FDDDC43611B527C3F1D760F36E5D7FC7C45", 1},
|
|
Packit |
5c3484 |
{196, "41BA2E104EE34C66B3520CE706A56498DE6D44721E5E24F5", 1},
|
|
Packit |
5c3484 |
{200, "4E5A24C38B981EAFE84CD9D0BEC48E83911362C114F30072C5", 1},
|
|
Packit |
5c3484 |
{256, "AF66BA932AAF58A071FD8F0742A99A0C76982D648509973DB802303128A14CB5", 1},
|
|
Packit |
5c3484 |
{0, NULL, 0} /* End of array. */
|
|
Packit |
5c3484 |
};
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
int
|
|
Packit |
5c3484 |
gmp_randinit_lc_2exp_size (gmp_randstate_t rstate, mp_bitcnt_t size)
|
|
Packit |
5c3484 |
{
|
|
Packit |
5c3484 |
const struct __gmp_rand_lc_scheme_struct *sp;
|
|
Packit |
5c3484 |
mpz_t a;
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
/* Pick a scheme. */
|
|
Packit |
5c3484 |
for (sp = __gmp_rand_lc_scheme; sp->m2exp != 0; sp++)
|
|
Packit |
5c3484 |
if (sp->m2exp / 2 >= size)
|
|
Packit |
5c3484 |
goto found;
|
|
Packit |
5c3484 |
return 0;
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
found:
|
|
Packit |
5c3484 |
/* Install scheme. */
|
|
Packit |
5c3484 |
mpz_init_set_str (a, sp->astr, 16);
|
|
Packit |
5c3484 |
gmp_randinit_lc_2exp (rstate, a, sp->c, sp->m2exp);
|
|
Packit |
5c3484 |
mpz_clear (a);
|
|
Packit |
5c3484 |
return 1;
|
|
Packit |
5c3484 |
}
|