就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the help center为指导。
9年前关闭。
我为加密目的创建了一个随机生成器,我想知道它是否足够安全。如果是,你当然可以自由使用它。提前感谢您阅读我的文字墙:D
功能说明 $this->pref_hash_algo($bits_of_entropy=null, $inclusive=false)
函数获取默认散列方法(在我的情况下 sha256
)或者如果 $bits_of_entropy
给定它获得包含或不包含的最佳散列算法。例如,包含 230 位熵将返回 sha256
而独家会给sha224
.
从 self::$HASH_PREFERENCES['128'][0]
返回的算法是 ripemd128
对于 $this->hash($input, $algorithm=null, $output_type=self::OUTPUT_HEX)
它只做一个 PHP hash($input, $algorithm[, $binary])
额外检查算法是否被认为是安全的,并支持比二进制和十六进制更多的输出类型。
代号
为方便访问,将第一个版本移至 http://pastebin.com/YtJFvpah
更新
根据您的输入,我已将代码更改为以下内容:http://pastebin.com/bQ5tFDdh
编辑摘要:
测试
情况1
我跑了
php /my/path/to/file.php | ent
测试 /dev/urandom
方法和 2.000.000 字节样本的替代方法。/dev/urandom
给出每字节 7.999903 位的熵。 ( http://pastebin.com/NLqZ5Kza ) 案例二
我使用替代方法创建了一个 4,7MB 的二进制文件(当
/dev/urandom
被禁用/不可用时)并运行 dieharder -a -f /home/beanow/random.input -t 10
:/dev/urandom
给出: 2 个弱点 ( http://pastebin.com/HiwQeJtP ) 案例3
与案例 2 相同,但使用 20MB 二进制文件并删除 -t 参数以使用默认设置。
/dev/urandom
给出: 4 个弱点 ( http://pastebin.com/hwqQBTqu ) 最佳答案
您可以针对您的输出运行许多测试,以确定它的真正随机性。
ent - A Pseudorandom Number Sequence Test Program
... [ent] applies various tests to sequences of bytes stored in files and reports the results of those tests. [ent] is useful for evaluating pseudorandom number generators for encryption and statistical sampling applications, compression algorithms, and other applications where the information density of a file is of interest.
The diehard test suite
... a battery of statistical tests for measuring the quality of a random number generator. Wikipedia
The dieharder test suite
The primary point of dieharder (like diehard before it) is to make it easy to time and test (pseudo)random number generators, both software and hardware, for a variety of purposes in research and cryptography.
使用自制的伪随机数生成器,通过顽固和顽固的测试套件是相当困难的。
关于php - 我创建了一个伪随机生成器,它对密码学安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9037327/