当前位置: 移动技术网 > 科技>操作系统>Linux > /dev/random 和 /dev/urandmon的差别

/dev/random 和 /dev/urandmon的差别

2019年09月24日  | 移动技术网科技  | 我要评论

最近使用这两个设备的时候,发现 /dev/random生成随机数很慢;于是就查了查:

这两个设备的差异在于:/dev/random的random pool依赖于系统中断,因此在系统的中断数不足时,/dev/random设备会一直封锁,尝试读取的进程就会进入等待状态,直到系统的中断数充分够用, /dev/random设备可以保证数据的随机性。/dev/urandom不依赖系统的中断,也就不会造成进程忙等待,但是数据的随机性也不高。

使用下列命令可以简单对比其差异:

[root@docker ~]# cat /dev/urandom | od -x
[root@docker ~]# cat /dev/random | od -x

使用 dd 进行生成不全为0的文件时,可以选择 /dev/urandom 作为测试源;

使用 urandom:

you just want a large file with random data for some kind of testing.
you are using the dd command to wipe data off a disk by replacing it with random data.
almost everywhere else where you don’t have a really good reason to use /dev/random instead.

使用 random:

randomness is critical to the security of cryptography in your application – one-time pads, key generation.

保持更新,更多linux 相关的内容,请关注 cnblogs.com/xuyaowen 

参考链接:

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网