Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
644 views
in Technique[技术] by (71.8m points)

php - MCRYPT_DEV_RANDOM freezes but MCRYPT_DEV_URANDOM works

I am trying to create an IV with the function:

mcrypt_create_iv(32, MCRYPT_DEV_RANDOM)

this causes the script to time out after more than 60 seconds. (maybe more?) but when I use URANDOM, it works fine almost instantly. From what I read it should take about 4 seconds with MCRYPT_DEV_RANDOM, but it is definitely taking too long. There is nothing in the error log.

I have it installed with apache2 and php5 on an ubuntu 12.04 server.

I have run the exact same code on my centos server without issues.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Both RANDOM and Unblocking-RANDOM (URANDOM) will supply you random data, but while RANDOM will block if the "entropy well" dries due to over-use, and restart when it has been replenished, URANDOM won't.

Pro: URANDOM won't block. Con: URANDOM, if left without entropy, will feed you not-really-so-random data.

For crypto purposes, unless you're really paranoid, I think that URANDOM should suffice.

See this Ubuntu page: http://manpages.ubuntu.com/manpages/jaunty/man4/random.4.html

I (wrongly) thought that the RANDOM sources were user-controllable, but it appears they aren't. Apparently, nothing much is happening on that computer, so that the kernel entropy generator finds nothing to grind.

On the plus side, the URANDOM generator is said to be very good and is recommended for practically everything.

(I'm editing out some previous suggestions of mine that wouldn't work for you, since they would require, at the very least, a recompilation of PHP).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...