rngd服务---熵值

https://www.kernel.org/doc/Documentation/hw_random.txt

https://wiki.archlinux.org/index.php/Rng-tools

什么是随机数

很多软件和应用都需要随机数,从纸牌游戏中纸牌的分发到 SSL 安全协议中密钥的产生,到处都有随机数的身影。随机数至少具备两个条件:

  1. 数字序列在统计上是随机的
  2. 不能通过已知序列推算后面的序列

自从计算机诞生起,寻求用计算机产生高质量的随机数序列的研究就一直是研究者长期关注的课题。一般情况下,使用计算机程序产生一个真正的随机数是很难的, 因为程序的行为是可预测的,计算机利用设计好的算法结合用户提供的种子产生的随机数序列通常是“伪随机数”(pseudo-random number),伪随机数就是我们平时经常使用的“随机数”。伪随机数可以满足一般应用的需求,但是在对于安全要求比较高的环境和领域中存在明显的缺点:

  1. 伪随机数是周期性的,当它们足够多时,会重复数字序列
  2. 如果提供相同的算法和相同的种子值,将会得出完全一样的随机数序列
  3. 可以使用逆向工程,猜测算法与种子值,以便推算后面所有的随机数列

只有实际物理过程才是真正的随机,只有借助物理世界中事物的随机性才能产生真正的随机数,比如真空内亚原子粒子量子涨落产生的噪音、超亮发光二极管在噪声的量子不确定性和放射性衰变等。


随机数为什么如此重要

生成随机数是密码学中的一项基本任务,是生成加密密钥、加密算法和加密协议所必不可少的,随机数的质量对安全性至关重要。最近报道有人利用随机数缺点成功 攻击了某网站,获得了管理员的权限。美国和法国的安全研究人员最近也评估了两个 Linux 内核 PRNG——/dev/random 和/dev/urandom 的安全性,认为 Linux 的伪随机数生成器不满足鲁棒性的安全概念,没有正确积累熵。可见随机数在安全系统中占据着非常重要的地位。


rngd
[root@10-4-25-124 ~]# yum -y install rng-tools
[root@10-4-25-124 ~]# echo 'EXTRAOPTIONS="--rng-device /dev/urandom"' >/etc/sysconfig/rngd
[root@10-4-25-124 ~]# service rngd start
Starting rngd:                                             OK  ]
[root@10-4-25-124 ~]# chkconfig rngd on
[root@10-4-25-124 ~]# chkconfig --list rngd
rngd               0:off    1:off    2:on    3:on    4:on    5:on    6:off
或者
直接在/etc/rc.d/rc.local中加入
rngd -r /dev/urandom -o /dev/random &

关于rng-tools详细的说明,可以参看
yum -y install kernel-doc
less  /usr/share/doc/kernel-doc-2.6.32-xxx/Documentation/hw_random.txt
Introduction:

        The hw_random framework is software that makes use of a
        special hardware feature on your CPU or motherboard,
        a Random Number Generator (RNG).  The software has two parts:
        a core providing the /dev/hw_random character device and its
        sysfs support, plus a hardware-specific driver that plugs
        into that core.

        To make the most effective use of these mechanisms, you
        should download the support software as well.  Download the
        latest version of the "rng-tools" package from the
        hw_random driver's official Web site:

                http://sourceforge.net/projects/gkernel/

        Those tools use /dev/hw_random to fill the kernel entropy pool,
        which is used internally and exported by the /dev/urandom and
        /dev/random special files.

确定CPU支持rdrand指令集
https://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide
http://rhelblog.redhat.com/2015/03/09/red-hat-enterprise-linux-virtual-machines-access-to-random-numbers-made-easy/
grep rdrand /proc/cpuinfo
在物理机中,如果rng-tools启动失败则可通过tpm-rng内核模块来生成/dev/hwrng
https://cryptotronix.com/2014/08/28/tpm-rng/
modprobe tpm-rng
echo tpm-rng >> /etc/modules
service rng-tools restart

systemctl restart rngd.service
echo $(cat /proc/sys/kernel/random/entropy_avail)/$(cat /proc/sys/kernel/random/poolsize)

随机数看起来什么样
apt-get -y install netpbm
cat /dev/urandom|rawtoppm -rgb 256 256 | pnmtopng > random$(date +%Y%m%d%H%M%S).png
rngd服务---熵值


随机数听起来怎么样
apt-get install sox libsox-fmt-all
dd if=/dev/hwrng status=noxfer | sox -t u16 -c 1 -r 48000 - -c 1 random$(date +%Y%m%d%H%M%S).wav trim 0 5



另一个解决方案haveged
http://www.issihosts.com/haveged/


原文地址:https://www.cnblogs.com/lixuebin/p/10814408.html