aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2018-05-29 04:53:45 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2018-05-29 04:55:18 +0800
commitfb0362a999d69d8c1180b66e994aff8a327bd342 (patch)
tree7677d8a1b6fbfc10f021b2031ff612d73494b5cb
parent12e3b7bc9ea6aa606d35cc6395e372051afe7af3 (diff)
downloaddexon-mcl-fb0362a999d69d8c1180b66e994aff8a327bd342.tar.gz
dexon-mcl-fb0362a999d69d8c1180b66e994aff8a327bd342.tar.zst
dexon-mcl-fb0362a999d69d8c1180b66e994aff8a327bd342.zip
MCL_DONT_USE_CSPRNG is to avoid /dev/urandom
-rw-r--r--include/mcl/bn.h2
-rw-r--r--include/mcl/randgen.hpp8
-rw-r--r--src/bn_c_impl.hpp2
3 files changed, 8 insertions, 4 deletions
diff --git a/include/mcl/bn.h b/include/mcl/bn.h
index 8327588..f996d00 100644
--- a/include/mcl/bn.h
+++ b/include/mcl/bn.h
@@ -197,8 +197,10 @@ MCLBN_DLL_API int mclBnFr_isEqual(const mclBnFr *x, const mclBnFr *y);
MCLBN_DLL_API int mclBnFr_isZero(const mclBnFr *x);
MCLBN_DLL_API int mclBnFr_isOne(const mclBnFr *x);
+#ifndef MCL_DONT_USE_CSRPNG
// return 0 if success
MCLBN_DLL_API int mclBnFr_setByCSPRNG(mclBnFr *x);
+#endif
// hash(s) and set x
// return 0 if success
diff --git a/include/mcl/randgen.hpp b/include/mcl/randgen.hpp
index 3c4a442..d5a2e95 100644
--- a/include/mcl/randgen.hpp
+++ b/include/mcl/randgen.hpp
@@ -6,7 +6,7 @@
@license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause
*/
-#ifdef MCL_DONT_USE_RANDOM
+#ifdef MCL_DONT_USE_CSRPNG
// nothing
@@ -91,14 +91,14 @@ public:
{
readFunc_(self_, out, static_cast<uint32_t>(byteSize));
}
-#ifdef MCL_DONT_USE_RANDOM
- bool isZero() const { return false; }
+#ifdef MCL_DONT_USE_CSRPNG
+ bool isZero() const { return false; } /* return false to avoid copying default rg */
#else
bool isZero() const { return self_ == 0 && readFunc_ == 0; }
#endif
static RandGen& get()
{
-#ifdef MCL_DONT_USE_RANDOM
+#ifdef MCL_DONT_USE_CSRPNG
static RandGen wrg;
#elif defined(MCL_USE_WEB_CRYPTO_API)
static mcl::RandomGeneratorJS rg;
diff --git a/src/bn_c_impl.hpp b/src/bn_c_impl.hpp
index 7e5fe01..292fec5 100644
--- a/src/bn_c_impl.hpp
+++ b/src/bn_c_impl.hpp
@@ -128,11 +128,13 @@ int mclBnFr_isOne(const mclBnFr *x)
return cast(x)->isOne();
}
+#ifndef MCL_DONT_USE_CSRPNG
int mclBnFr_setByCSPRNG(mclBnFr *x)
{
cast(x)->setByCSPRNG();
return 0;
}
+#endif
// hash(buf) and set x
int mclBnFr_setHashOf(mclBnFr *x, const void *buf, mclSize bufSize)