【发布时间】:2020-04-05 12:22:51
【问题描述】:
我想知道 Docker 容器中的随机(或伪随机)序列生成, 但遇到了另一个有趣的行为。
当直接从/dev/urandom 读取 8000000 字节时,ENT 的测试结果如下:
Entropy = 7.999976 bits per byte.
Optimum compression would reduce the size
of this 8000000 byte file by 0 percent.
Chi square distribution for 8000000 samples is 262.08, and randomly
would exceed this value 36.69 percent of the times.
Arithmetic mean value of data bytes is 127.5337 (127.5 = random).
Monte Carlo value for Pi is 3.139911785 (error 0.05 percent).
Serial correlation coefficient is -0.000101 (totally uncorrelated = 0.0).
但在生成 1000000 个 DES 密钥的情况下,ENT 的输出会给出以下信息:
Entropy = 6.999990 bits per byte.
Optimum compression would reduce the size
of this 8000000 byte file by 12 percent.
Chi square distribution for 8000000 samples is 8000217.63, and randomly
would exceed this value less than 0.01 percent of the times.
Arithmetic mean value of data bytes is 127.4870 (127.5 = random).
Monte Carlo value for Pi is 3.145497786 (error 0.12 percent).
Serial correlation coefficient is 0.000033 (totally uncorrelated = 0.0).
用于生成 1000000 个密钥的代码:
KeyGenerator des = KeyGenerator.getInstance("DES");
IntStream.range(0, 1_000_000).forEach(j -> {
SecretKey secretKey = des.generateKey();
System.out.write(secretKey.getEncoded());
});
熵较低,卡方分布表明分布不再是随机的。
所以我想知道SecureRandom Java 的实现是否只是减少熵并直接从
urandom 可能是更好的选择。
【问题讨论】:
标签: java security random alpine des