node.js - randomBytes vs pseudoRandomBytes -


in situations acceptable (from security standpoint) use node's crypto.pseudorandombytes instead of cryptographically-strong crypto.randombytes?

i assume pseudorandombytes performs better @ expense of being more predictable (incorrect), docs don't have how less-strong is.

specifically, i'm wondering if i'm ok using pseudorandombytes generate csrf token.

as turns out, with default openssl (which bundled node, if you've built own, possible configure different engines), the algorithm generate random data same both randombytes (rand_bytes) , pseudorandombytes (rand_pseudo_bytes).

the 1 , difference between 2 calls depends on version of node you're using:

  • in node v0.12 , prior, randombytes returns error if entropy pool has not yet been seeded enough data. pseudorandombytes return bytes, if entropy pool has not been seeded.
  • in node v4 , later, randombytes not return until entropy pool has enough data. should take few milliseconds (unless system has booted).

once the entropy pool has been seeded enough data, never "run out," there absolutely no effective difference between randombytes , pseudorandombytes once entropy pool full.

because exact same algorithm used generate randrom data, there no difference in performance between 2 calls (one-time entropy pool seeding notwithstanding).


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -