diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2018-05-14 13:38:50 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2018-05-14 13:38:50 +0800 |
commit | 925c48010529a54630a997a92ede51bcc75f775c (patch) | |
tree | 246c851a6d357b4311e1710919bad6457516cc85 | |
parent | 57fc4756ba86e594cddc785dabe777b23206a270 (diff) | |
download | tangerine-mcl-925c48010529a54630a997a92ede51bcc75f775c.tar.gz tangerine-mcl-925c48010529a54630a997a92ede51bcc75f775c.tar.zst tangerine-mcl-925c48010529a54630a997a92ede51bcc75f775c.zip |
callback crypto.getRandomValues
-rw-r--r-- | include/mcl/randgen.hpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/include/mcl/randgen.hpp b/include/mcl/randgen.hpp index aee8cb5..2e28378 100644 --- a/include/mcl/randgen.hpp +++ b/include/mcl/randgen.hpp @@ -6,10 +6,23 @@ @license modified new BSD license http://opensource.org/licenses/BSD-3-Clause */ +#ifdef MCL_USE_WEB_CRYPTO_API +#include <emscripten.h> + +struct RandomGenerator { + void read(void *buf, size_t bufSize) + { + // use crypto.getRandomValues + EM_ASM({mod.cryptoGetRandomValues($0, $1)}, buf, bufSize); + } +}; + +#else #include <cybozu/random_generator.hpp> -#if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11 +#if 0 // #if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11 #include <random> #endif +#endif #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4521) @@ -24,7 +37,7 @@ void readWrapper(void *self, void *buf, uint32_t bufSize) reinterpret_cast<RG*>(self)->read((uint8_t*)buf, bufSize); } -#if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11 +#if 0 // #if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11 template<> inline void readWrapper<std::random_device>(void *self, void *buf, uint32_t bufSize) { |