Skip to content

std::random_device can not constructing #2439

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
usagi opened this issue Jun 21, 2014 · 4 comments
Closed

std::random_device can not constructing #2439

usagi opened this issue Jun 21, 2014 · 4 comments

Comments

@usagi
Copy link
Contributor

usagi commented Jun 21, 2014

Testing environment:

  • Emscripten-1.20.0 ( with fastcomp )
  • nodejs-0.10.25
  • Ubuntu-14.04

Sample code:

#include <random>
#include <iostream>
#include <exception>

auto main()
  -> int
try
{
  std::random_device rd;
}
catch( const std::exception& e )
{
  std::cerr << e.what();
}

Result of the sample:

random_device failed to open /dev/urandom: No such file or directory

The exception thrown from maybe: https://github.com/kripken/emscripten/blob/master/system/lib/libcxx/random.cpp#L53

26.5.6 of the C++ specification:

A random_device uniform random number generator produces non-deterministic random numbers. If implementation limitations prevent generating non-deterministic random numbers, the implementation may employ a random number engine.

I think, Emscripten's std::random_device constructor is need specific token. Or, it need /dev/urandom emulation.

@kripken
Copy link
Member

kripken commented Jun 23, 2014

Probably /dev/urandom emulation is the best solution here.

kripken added a commit that referenced this issue Jun 24, 2014
@kripken
Copy link
Member

kripken commented Jun 24, 2014

Implemented.

@kripken kripken closed this as completed Jun 24, 2014
@usagi
Copy link
Contributor Author

usagi commented Jun 24, 2014

@kripken

Thanks implement.

But, I think /dev/random and /dev/urandom need to be implemented by more safety random source if supported. I will write a patch and pull-request after in today.

( ref.: https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#dfn-RandomSource )

@kripken
Copy link
Member

kripken commented Jun 24, 2014

Good point, yeah, we should use that where available.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants