File tree 1 file changed +9
-5
lines changed
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 11
11
#define BIGINT_TCC_
12
12
#include < cassert>
13
13
#include < cstring>
14
+ #include < random>
14
15
15
16
namespace libff {
16
17
@@ -165,11 +166,14 @@ bool bigint<n>::test_bit(const std::size_t bitno) const
165
166
template <mp_size_t n>
166
167
bigint<n>& bigint<n>::randomize()
167
168
{
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
+ }
173
177
174
178
return (*this );
175
179
}
You can’t perform that action at this time.
0 commit comments