File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 1111#define BIGINT_TCC_
1212#include < cassert>
1313#include < cstring>
14+ #include < random>
1415
1516namespace libff {
1617
@@ -165,11 +166,14 @@ bool bigint<n>::test_bit(const std::size_t bitno) const
165166template <mp_size_t n>
166167bigint<n>& bigint<n>::randomize()
167168{
168- assert (GMP_NUMB_BITS == sizeof (mp_limb_t ) * 8 );
169- FILE *fp = fopen (" /dev/urandom" , " r" ); // TODO Remove hard-coded use of /dev/urandom.
170- size_t bytes_read = fread (this ->data , 1 , sizeof (mp_limb_t ) * n, fp);
171- assert (bytes_read == sizeof (mp_limb_t ) * n);
172- fclose (fp);
169+ static_assert (GMP_NUMB_BITS == sizeof (mp_limb_t ) * 8 , " Wrong GMP_NUMB_BITS value" );
170+ std::random_device rd;
171+ constexpr size_t num_random_words = sizeof (mp_limb_t ) * n / sizeof (std::random_device::result_type);
172+ auto random_words = reinterpret_cast <std::random_device::result_type*>(this ->data );
173+ for (size_t i = 0 ; i < num_random_words; ++i)
174+ {
175+ random_words[i] = rd ();
176+ }
173177
174178 return (*this );
175179}
You can’t perform that action at this time.
0 commit comments