Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Math.random() cryptographically secure?

How good are algorithms used in Javascript Math.random() in different browsers? Is it okay to use it for generating salts and one-time passwords?

How many bits from one random I can use?

like image 723
grep Avatar asked Apr 13 '11 15:04

grep


People also ask

Is Python random cryptographically secure?

Random numbers and data generated by the random class are not cryptographically protected. An output of all random module functions is not cryptographically secure, whether it is used to create a random number or pick random elements from a sequence.

Is math random predictable?

An unfortunately predictable PRNG called Math. random() . If you're using Node. js (or any other JavaScript environment) in your stack today, the same Math.

Is math random () good?

The JavaScript Math. random() method is an excellent built-in method for producing random numbers. When Math. random() is executed, it returns a random number that can be anywhere between 0 and 1.

What is cryptographically secure?

A cryptographically secure pseudo random number generator (CSPRNG), is one where the number that is generated is extremely hard for any third party to predict what it might be.

How do I generate cryptographically secure random numbers in JavaScript?

How do I generate cryptographically secure random numbers in javascript? What exactly do you mean by "cryptographically"? Use Math.random () to return a random number between 0 and 1. Its technically pseudo random, since there isn't really any (simple) way to generate true random numbers.

Do cryptographic algorithms require random numbers?

Everyone seems to have missed a bit of a nuance here: Cryptographic algorithms require a number to be mathematically and statistically random over all executions of the algorithm.

What does cryptographically secure mean?

Cryptographically secure is a standard term that means that the value is unpredictable, even to an adversary who is willing to invest a significant amount of time and energy trying to predict it or distinguish it from random. There's been discussion at WHATWG on adding this to the window.crypto object.

Why is there a better alternative to math random?

Because there actually is a cryptographically secure alternative to Math.random (): This allows the developer to use the right tool for the job. If you want to generate pretty pictures or loot drops for your game, use the fast Math.random (). When you need cryptographically secure random numbers, use the more expensive window.crypto.


1 Answers

Nope; JavaScript's Math.random() function is not a cryptographically-secure random number generator. You are better off using the JavaScript Crypto Library's Fortuna implementation which is a strong pseudo-random number generator (have a look at src/js/Clipperz/Crypto/PRNG.js), or the Web Crypto API for getRandomValues

  • Here is a detailed explanation: How trustworthy is javascript's random implementation in various browsers?
  • Here is how to generate a good crypto grade random number: Secure random numbers in javascript?
like image 162
Teoman Soygul Avatar answered Sep 24 '22 02:09

Teoman Soygul