通常读取/dev/random产生 100-500 字节和块,等待熵被收集。
为什么/dev/random其他进程写入信息不能加快读取速度?它不应该提供所需的熵吗?
它可用于解锁gpg或类似软件而无需重新启动并重新输入所有内容,生成非超级绝密密钥等。
Ant*_*hon 21
您可以写入,/dev/random因为它是向 提供额外随机字节的方法的一部分/dev/random,但这还不够,您还必须通过ioctl()调用通知系统存在额外的熵。
我需要相同的功能来测试我的智能卡设置程序,因为我不想等待我的鼠标/键盘gpg为每次测试运行进行的多次调用生成足够的信息。我所做的是在测试的同时运行 Python 程序。它当然根本不应该用于真正的gpg密钥生成,因为随机字符串根本不是随机的(系统生成的随机信息仍然会被交错)。如果您有一个外部源来为 设置字符串random,那么您应该能够拥有高熵。您可以使用以下方法检查熵:
cat /proc/sys/kernel/random/entropy_avail
Run Code Online (Sandbox Code Playgroud)
该程序:
#!/usr/bin/env python
# For testing purposes only
# DO NOT USE THIS, THIS DOES NOT PROVIDE ENTROPY TO /dev/random, JUST BYTES
import fcntl
import time
import struct
RNDADDENTROPY=0x40085203
while True:
random = "3420348024823049823-984230942049832423l4j2l42j"
t = struct.pack("ii32s", 8, 32, random)
with open("/dev/random", mode='wb') as fp:
# as fp has a method fileno(), you can pass it to ioctl
res = fcntl.ioctl(fp, RNDADDENTROPY, t)
time.sleep(0.001)
Run Code Online (Sandbox Code Playgroud)
(完成后不要忘记杀死程序。)
cuo*_*glm 14
通常,它由内核开发人员设计并记录在man 4 random:
Writing to /dev/random or /dev/urandom will update the entropy pool
with the data written, but this will not result in a higher entropy
count. This means that it will impact the contents read from both
files, but it will not make reads from /dev/random faster.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6376 次 |
| 最近记录: |