aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-02-14 14:51:12 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-02-14 14:51:12 +0800
commitff70f09295e18a1d3ffdf5f324c3969d6ee6efea (patch)
treef3074e080b794951f11c5c559bb4397a7ae37d02 /include
parentf71821a727079f9ca61ba3a53d9d89af6b4b4328 (diff)
downloadtangerine-mcl-ff70f09295e18a1d3ffdf5f324c3969d6ee6efea.tar.gz
tangerine-mcl-ff70f09295e18a1d3ffdf5f324c3969d6ee6efea.tar.zst
tangerine-mcl-ff70f09295e18a1d3ffdf5f324c3969d6ee6efea.zip
use std::random_device for Fp::setRand
Diffstat (limited to 'include')
-rw-r--r--include/mcl/util.hpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/include/mcl/util.hpp b/include/mcl/util.hpp
index 14468aa..62ecd9c 100644
--- a/include/mcl/util.hpp
+++ b/include/mcl/util.hpp
@@ -146,6 +146,26 @@ size_t getNonZeroArraySize(const T *x, size_t n)
}
return 1;
}
+
+namespace impl {
+
+template<class T, class RG>
+static void readN(T* out, size_t n, RG& rg)
+{
+ if (sizeof(T) == 8) {
+ for (size_t i = 0; i < n; i++) {
+ T v = rg();
+ v = (v << 32) | rg();
+ out[i] = v;
+ }
+ } else {
+ for (size_t i = 0; i < n; i++) {
+ out[i] = rg();
+ }
+ }
+}
+
+} // impl
/*
get random value less than in[]
n = (bitSize + sizeof(T) * 8) / (sizeof(T) * 8)
@@ -160,7 +180,7 @@ void getRandVal(T *out, RG& rg, const T *in, size_t bitSize)
const size_t n = (bitSize + TbitSize - 1) / TbitSize;
const size_t rem = bitSize & (TbitSize - 1);
for (;;) {
- rg.read(out, n);
+ impl::readN(out, n, rg);
if (rem > 0) out[n - 1] &= (T(1) << rem) - 1;
if (isLessArray(out, in, n)) return;
}