/proc/sys/kernel/random/uuid 是强密钥材料吗?
我一直在寻找为 HMAC_SHA256 算法生成强 256 位/32 字节对称密钥的方法。我偶然发现了 /proc/sys/kernel/random/uuid 文件。
根据 man random(4) :“只读文件uuid和boot_id包含随机字符串,如6fd5a44b-35f4-4ad4-a9b9-6b9be13e1fe9。前者是生成的每次读取都会重新生成一次。”
来自 cat /proc/sys/kernel/random/uuid
的字符串看起来非常适合此目的。我可以删除“-”字符并最终得到 32 字节的随机性。
这是生成加密强密钥材料源的有效方法吗?
I've been looking at ways to generate a strong 256 bit/32 byte symmetric key for the HMAC_SHA256 algorithm. I stumbled upon the /proc/sys/kernel/random/uuid file.
According to man random(4): "The read-only files uuid and boot_id contain random strings like 6fd5a44b-35f4-4ad4-a9b9-6b9be13e1fe9. The former is generated afresh for each read, the latter was generated once."
The string from cat /proc/sys/kernel/random/uuid
looks ideal for this purpose. I can remove the '-' chars and end up with a 32 bytes of randomness.
Is this a valid approach to generate a cryptographically strong source of keying material?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个老问题,但如果有人偶然发现它,我不建议这样做。
/proc/sys/kernel/random/uuid
是具有特定语义的 4 类(随机)UUID - 它不仅仅是一串随机的十六进制字符。例如,您会看到第三组中的第一个数字始终是 4。对于 256 个随机位,只需从
/dev/random
读取 32 个字节(使用外部熵,可以阻止)或/dev/urandom
(从不阻塞)。An old question but in case anyone stumbles on it, I wouldn't advise this.
/proc/sys/kernel/random/uuid
is a type 4 (random) UUID with certain semantics - it's not just a string of random hex characters. For example you'll see the first digit in the third group is always a 4.For 256 random bits just read 32 bytes from
/dev/random
(uses external entropy, can block) or/dev/urandom
(never blocks).o172.net 是最好的答案,可以直接评论,但不能。
/proc/sys/kernel/random/uuid
基于urandom
但最好直接从 urandom 获取。下面是如何从 shell 获取它,以下获取 32 个 ascii 十六进制字节:
您可以通过
tr
参数更改字符集,通过 字节并获取随机二进制文件。
o172.net is the best answer, would comment on it directly but cannot.
/proc/sys/kernel/random/uuid
is based onurandom
but it is best to grab from urandom directly.This below is how to get it from the shell, the following gets 32 ascii hex bytes:
You can change the char set via the
tr
params, the bytes by theand get random binary.
您会依赖定义良好的确定性伪随机算法来生成密钥吗?基本上就是这个问题。
我想说的是,将 UUID 作为密钥的基础,但使用您的密钥对其进行一次加密。
Would you rely on a well-defined deterministic pseudo-random algorithm for key generation? That's the question basically.
I'd say, take the UUID as a base for your key, but do one pass of encryption on it using a secret key of yours.