3 ms·
> Seeding with the current time is the real sin here. As somebody who only ever uses rng for games, and then indeed seeds with os.microtime(), what's the issue
by bruce343434 5y ago
> Seeding with the current time is the real sin here.
As somebody who only ever uses rng for games, and then indeed seeds with os.microtime(), what's the issue and what is a better approach?
- ericbarrett 5y agoThere are only so many seconds in a year, and if you know the PRNG and assume reasonable constraints for the password generator (length, symbols, numbers) you can iterate this space orders of magnitude faster than brute-force. The proper way to do this for cryptographic purposes is use the RNG facility provided by the kernel, which mixes in local entropy. Or go directly to the CPU like Intel’s RDRAND instruction. But the kernel should be using this if it’s enabled.
- cogman10 5y agoThe main issue is you generally want PRNGs, especially in terms of crypto, to be unpredictable. When you use something like the time, you've suddenly made the output VERY predictable. In terms of a global password manager, it's extremely bad, you now can use things like "member since x" to guess a password. If, for example, a database with credentials are leaked, you've significantly shorted the amount of passwords that need to be brute forced for a given target (assuming you know what password manager software they are using) A good approach would have been something as simple as adding the master password into the seed. (Master password + time). An even better approach would be using a more cryptographically secure random number from the system for either the whole thing or at very least for the seed. (On linux systems /dev/random). You certainly could combine all those approaches to make the password much harder to guess.
- comicjk 5y agoSeeding with the time makes the outputs predictable to an adversary. If your games are not moving real money based on your RNG (like online poker), you probably don't have any adversaries trying to guess your random numbers, so you're fine. See here for an online poker game which actually had this flaw: https://news.ycombinator.com/item?id=7207851 https://news.ycombinator.com/item?id=7207851