version 1.1.1.1, 2000/09/09 14:12:27 |
version 1.1.1.2, 2003/08/25 16:06:20 |
|
|
/* mpn_random -- Generate random numbers. |
/* mpn_random -- Generate random numbers. |
|
|
Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc. |
Copyright 2001, 2002 Free Software Foundation, Inc. |
|
|
This file is part of the GNU MP Library. |
This file is part of the GNU MP Library. |
|
|
Line 21 MA 02111-1307, USA. */ |
|
Line 21 MA 02111-1307, USA. */ |
|
|
|
#include "gmp.h" |
#include "gmp.h" |
#include "gmp-impl.h" |
#include "gmp-impl.h" |
#include "urandom.h" |
|
|
|
void |
void |
#if __STDC__ |
mpn_random (mp_ptr ptr, mp_size_t size) |
mpn_random (mp_ptr res_ptr, mp_size_t size) |
|
#else |
|
mpn_random (res_ptr, size) |
|
mp_ptr res_ptr; |
|
mp_size_t size; |
|
#endif |
|
{ |
{ |
mp_size_t i; |
gmp_randstate_ptr rands; |
|
|
for (i = 0; i < size; i++) |
/* FIXME: Is size==0 supposed to be allowed? */ |
res_ptr[i] = urandom (); |
ASSERT (size >= 0); |
|
|
|
if (size == 0) |
|
return; |
|
|
|
rands = RANDS; |
|
_gmp_rand (ptr, rands, size * GMP_NUMB_BITS); |
|
|
/* Make sure the most significant limb is non-zero. */ |
/* Make sure the most significant limb is non-zero. */ |
while (res_ptr[size - 1] == 0) |
while (ptr[size-1] == 0) |
res_ptr[size - 1] = urandom (); |
_gmp_rand (&ptr[size-1], rands, GMP_NUMB_BITS); |
} |
} |