加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 使用RNDADDENTROPY将熵添加到/ dev / random

发布时间:2020-12-16 05:04:06 所属栏目:百科 来源:网络整理
导读:我有一个设备会产生一些噪音,我想将它添加到嵌入式 Linux系统中/ dev / random设备的熵池中. 我正在阅读man page on /dev/random并且我不太了解您传递给RNDADDENTROPY ioctl调用的结构. RNDADDENTROPY Add some additional entropy to the input pool,increm
我有一个设备会产生一些噪音,我想将它添加到嵌入式 Linux系统中/ dev / random设备的熵池中.

我正在阅读man page on /dev/random并且我不太了解您传递给RNDADDENTROPY ioctl调用的结构.

RNDADDENTROPY
          Add some additional entropy to the input pool,incrementing
          the entropy count.  This differs from writing to /dev/random
          or /dev/urandom,which only adds some data but does not
          increment the entropy count.  The following structure is used:

              struct rand_pool_info {
                  int    entropy_count;
                  int    buf_size;
                  __u32  buf[0];
              };

          Here entropy_count is the value added to (or subtracted from)
          the entropy count,and buf is the buffer of size buf_size
          which gets added to the entropy pool.

这个结构中的entropy_count是我添加的位数吗?为什么这不总是buf_size * 8(假设buf_size是以字节为单位)?

另外为什么buf是零大小的数组?我该如何为它分配一个值?

感谢您的帮助!

解决方法

我正在使用硬件RNG来存储我的熵池.我的结构是静态大小
看起来像这样(我的内核有一个稍微不同的random.h;只是复制什么
你找到你的,并将数组大小增加到你想要的任何东西):
#define BUFSIZE 256
/* WARNING - this struct must match random.h's struct rand_pool_info */
typedef struct {
    int bit_count;               /* number of bits of entropy in data */
    int byte_count;              /* number of bytes of data in array */
    unsigned char buf[BUFSIZ];
} entropy_t;

无论你在buf中传递什么都将被哈希并将搅动熵池.
如果您使用/ dev / urandom,则为bit_count传递的内容无关紧要
因为/ dev / urandom忽略它等于零并且继续前进.

bit_count的作用是推动/ dev / random将阻塞的点
并等待物理RNG源添加更多熵.
因此,可以猜测bit_count.如果你猜低,最差
会发生的事情是/ dev / random会比其他情况更快地阻止
将有.如果你猜高,/ dev / random将像/ dev / urandom一样运行
比它阻挡之前要长一点点.

您可以根据熵源的“质量”进行猜测.如果它很低,就像人类输入的字符一样,你可以将它设置为1或2每字节.如果它很高,就像从专用硬件RNG读取的值,您可以将其设置为每字节8位.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读