[BACK]Return to rand.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp

Annotation of OpenXM_contrib/gmp/rand.c, Revision 1.1.1.2

1.1       maekawa     1: /* gmp_randinit (state, algorithm, ...) -- Initialize a random state.
                      2:
1.1.1.2 ! ohara       3: Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
1.1       maekawa     4:
                      5: This file is part of the GNU MP Library.
                      6:
                      7: The GNU MP Library is free software; you can redistribute it and/or modify
                      8: it under the terms of the GNU Lesser General Public License as published by
                      9: the Free Software Foundation; either version 2.1 of the License, or (at your
                     10: option) any later version.
                     11:
                     12: The GNU MP Library is distributed in the hope that it will be useful, but
                     13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     14: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
                     15: License for more details.
                     16:
                     17: You should have received a copy of the GNU Lesser General Public License
                     18: along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
                     19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
                     20: MA 02111-1307, USA. */
                     21:
1.1.1.2 ! ohara      22: #include "config.h"
        !            23:
1.1       maekawa    24: #include <stdio.h> /* for NULL */
1.1.1.2 ! ohara      25:
        !            26: #if HAVE_STDARG
        !            27: #include <stdarg.h>
1.1       maekawa    28: #else
1.1.1.2 ! ohara      29: #include <varargs.h>
1.1       maekawa    30: #endif
                     31:
                     32: #include "gmp.h"
                     33: #include "gmp-impl.h"
                     34:
                     35: void
1.1.1.2 ! ohara      36: #if HAVE_STDARG
1.1       maekawa    37: gmp_randinit (gmp_randstate_t rstate,
                     38:              gmp_randalg_t alg,
                     39:              ...)
                     40: #else
                     41: gmp_randinit (va_alist)
                     42:      va_dcl
                     43: #endif
                     44: {
                     45:   va_list ap;
1.1.1.2 ! ohara      46: #if HAVE_STDARG
        !            47:   va_start (ap, alg);
1.1       maekawa    48: #else
                     49:   __gmp_randstate_struct *rstate;
                     50:   gmp_randalg_t alg;
                     51:   va_start (ap);
                     52:   rstate = va_arg (ap, __gmp_randstate_struct *);
                     53:   alg = va_arg (ap, gmp_randalg_t);
                     54: #endif
                     55:
1.1.1.2 ! ohara      56:   switch (alg) {
        !            57:   case GMP_RAND_ALG_LC:
        !            58:     if (! gmp_randinit_lc_2exp_size (rstate, va_arg (ap, unsigned long)))
        !            59:       gmp_errno |= GMP_ERROR_INVALID_ARGUMENT;
        !            60:     break;
        !            61:   default:
        !            62:     gmp_errno |= GMP_ERROR_UNSUPPORTED_ARGUMENT;
        !            63:     break;
        !            64:   }
        !            65:   va_end (ap);
        !            66: }
1.1       maekawa    67:
                     68:
                     69:
                     70: #if 0
                     71:     case GMP_RAND_ALG_BBS:     /* Blum, Blum, and Shub. */
1.1.1.2 ! ohara      72:       {
1.1       maekawa    73:        mpz_t p, q;
                     74:        mpz_t ztmp;
                     75:
                     76:        /* FIXME: Generate p and q.  They must be ``large'' primes,
                     77:            congruent to 3 mod 4.  Should we ensure that they meet some
                     78:            of the criterias for being ``hard primes''?*/
                     79:
                     80:        /* These are around 128 bits. */
                     81:        mpz_init_set_str (p, "148028650191182616877187862194899201391", 10);
                     82:        mpz_init_set_str (q, "315270837425234199477225845240496832591", 10);
1.1.1.2 ! ohara      83:
1.1       maekawa    84:        /* Allocate algorithm specific data. */
                     85:        rstate->data.bbs = (__gmp_rand_data_bbs *)
1.1.1.2 ! ohara      86:          (*__gmp_allocate_func) (sizeof (__gmp_rand_data_bbs));
1.1       maekawa    87:
                     88:        mpz_init (rstate->data.bbs->bi); /* The Blum integer. */
                     89:        mpz_mul (rstate->data.bbs->bi, p, q);
                     90:
                     91:        /* Find a seed, x, with gcd (x, bi) == 1. */
                     92:        mpz_init (ztmp);
                     93:        while (1)
                     94:          {
                     95:            mpz_gcd (ztmp, seed, rstate->data.bbs->bi);
                     96:            if (!mpz_cmp_ui (ztmp, 1))
                     97:              break;
                     98:            mpz_add_ui (seed, seed, 1);
                     99:          }
                    100:
                    101:        rstate->alg = alg;
                    102:        rstate->size = size;            /* FIXME: Remove. */
                    103:        mpz_set (rstate->seed, seed);
                    104:
                    105:        mpz_clear (p);
                    106:        mpz_clear (q);
                    107:        mpz_clear (ztmp);
                    108:        break;
                    109:       }
                    110: #endif /* 0 */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>