Will python SystemRandom / os.urandom always have enough entropy for good crypto

前端 未结 3 1330
走了就别回头了
走了就别回头了 2020-12-25 13:12

I have a password generator:

import random, string

def gen_pass():
    foo = random.SystemRandom()
    length = 64
    chars = string.letters + string.digit         


        
3条回答
  •  情深已故
    2020-12-25 13:50

    There's a subtle difference between the output of /dev/random and /dev/urandom. As has been pointed out, /dev/urandom doesn't block. That's because it gets its output from a pseudo-random number generator, seeded from the 'real' random numbers in /dev/random.

    The output of /dev/urandom will almost always be sufficiently random -- it's a high-quality PRNG with a random seed. If you really need a better source of random data, you could consider getting a system with a hardware random number generator -- my netbook has a VIA C7 in it, which can generate quite a lot of properly random data (I get a consistent 99.9kb/s out of /dev/random, 545kb/s out of /dev/urandom).

    As an aside, if you're generating passwords then you might want to look at pwgen -- it makes nice pronounceable passwords for you :).

提交回复
热议问题