2

Does Ruby provide functionality to run a seedable CSPRNG? From the standard library, OpenSSL/SecureRandom is cryptographically secure, but not seedable. Random is seedable, but not cryptographically secure.

Alternatively, what is a secure way to instantiate a cryptographically secure PRNG in Ruby using only OpenSSL APIs?

user2398029
  • 6,699
  • 8
  • 48
  • 80
  • Off topic, try softwarerecs.stackexchange.com. Bizarrely I just yesterday started work on *something* of that nature, but not really suitable for use as a CSPRNG: https://github.com/neilslater/pool_of_entropy - Note that being secure generally means securing the seed process too (plus ensuring high quality seed data). I guess SecureRandom took that away from its API on purpose to avoid chances of end users compromising their own security. – Neil Slater Apr 30 '14 at 07:00
  • I think this is an important enough topic that it is of interest to the general community on StackOverflow. My question is not for software recommendation; I am asking whether there exists a method to instantiate such a PRNG that I am not aware of. – user2398029 Apr 30 '14 at 07:20
  • You *can* call `OpenSSL::Random.seed( 'some data' )`, also `write_random_file` then `read_random_file`, but from Ruby these do not set a precise fixed state of the RNG. – Neil Slater Apr 30 '14 at 09:43
  • I had a look around, and it looks like you can *add* any data you like to the current state, it will get mixed in. There does not appear to be a way via OpenSSL API to set the current state exactly. Also see http://stackoverflow.com/questions/12118406/is-rubys-seed-for-opensslrandom-sufficient - so could you clarify whether you are looking to fully control the initial state of a CSPRNG, or just ensure that it contains enough entropy for your purpose? The latter seems very do-able using OpenSSL – Neil Slater Apr 30 '14 at 13:17
  • I am looking to fully control the initial state. I assume I am going to need to write up an HMAC or AES-based DRBG (http://csrc.nist.gov/groups/ST/toolkit/documents/rng/HashBlockCipherDRBG.pdf) – user2398029 Apr 30 '14 at 16:41

1 Answers1

1

I ended up implementing DRBG_HMAC in Ruby. The code can be found here: https://github.com/cryodex/drbg-rb

user2398029
  • 6,699
  • 8
  • 48
  • 80