c - rand(), srand() 1to1替换使用urandom

标签 c linux random coverity

我目前正在玩 coverity,它对 rand() 调用大喊大叫

CID 52583 (#1 of 1): Don't call (DC.WEAK_CRYPTO)
dont_call: rand() should not be used for security related applications, as linear congruential algorithms are too easy to break.

使用 urandom 返回与 rand() 相同范围内的数字的替换是否容易下降?

最佳答案

为了在我的代码中抑制有关 rand() 的 Coverity 警告,它的使用安全相关,我提供了一个建模.c 覆盖率 modeling file到 Coverity,告诉 Coverity 忽略该函数,例如:

/* libc functions. */

int rand(void) {
  /* ignore */
}

long random(void) {
  /* ignore */
}

void srand(unsigned int seed) {
  /* ignore */
}

对于沿着这些方向抑制的其他示例,我经常查看 Python 的 Coverity文档。

希望这对您有所帮助!

关于c - rand(), srand() 1to1替换使用urandom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25613072/

相关文章:

linux - 进程死后,Linux 内核在哪里进行进程和 TCP 连接清理?

algorithm - 在什么情况下,[0,1) 上生成的随机数与 [0,1] 上生成的随机数之间的差异会产生影响?

c - C 允许函数调用作为参数吗?

c - 我如何在 c 中创建一个二维数组并使用指针和函数显示它?

linux - scp 到远程主机而不在该主机上执行 bash_profile 文件

java - iptables 阻止我远程登录到端口 80 上的外部服务器

c++ - 在播种伪随机引擎后, std::random_device 是否应该保持事件状态?

c# - 简单的伪随机算法

c - C 中的结构、内部结构和大小

c# - 如何通过属性编码为 ANSI 字符串?