linux 64位 rand,在Linux / POSIX中Windows的rand_s的最佳替代品是什么?

The problem is not about randomness itself (we have rand), but in cryptographically secure PRNG. What can be used on Linux, or ideally POSIX? Does NSS have something useful?

問題不在於隨機性本身(我們有蘭特),而在於加密安全的PRNG。可以在Linux上使用什么,或者理想的POSIX? NSS有用嗎?

Clarification: I know about /dev/random, but it may run out of entropy pool. And I'm not sure whether /dev/urandom is guaranteed to be cryptographically secure.

澄清:我知道/ dev / random,但它可能用完了熵池。而且我不確定/ dev / urandom是否保證加密安全。

3 个解决方案

#1

5

Use /dev/random (requires user input, eg mouse movements) or /dev/urandom. The latter has an entropy pool and doesn't require any user input unless the pool is empty.

使用/ dev / random(需要用戶輸入,例如鼠標移動)或/ dev / urandom。后者具有熵池,除非池為空,否則不需要任何用戶輸入。

You can read from the pool like this:

你可以從這里讀取這樣的:

char buf[100];

FILE *fp;

if (fp = fopen("/dev/urandom", "r")) {

fread(&buf, sizeof(char), 100, fp);

fclose(fp);

}

Or something like that.

或類似的東西。

#2

5

From Wikipedia (my italics):

來自維基百科(我的斜體):

A counterpart to /dev/random is /dev/urandom ("unlocked" random source) which reuses the internal pool to produce more pseudo-random bits. This means that the call will not block, but the output may contain less entropy than the corresponding read from /dev/random. The intent is to serve as a cryptographically secure pseudorandom number generator. This may be used for less secure applications.

/ dev / random的對應物是/ dev / urandom(“解鎖”隨機源),它重用內部池以產生更多的偽隨機位。這意味着調用不會阻塞,但輸出可能包含比來自/ dev / random的相應讀取更少的熵。目的是充當加密安全的偽隨機數生成器。這可用於不太安全的應用程序。

#3

3

The /dev/random device is intended to be a source of cryptographically secure bits.

/ dev / random設備旨在成為加密安全位的來源。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值