使用RNDADDENTROPY熵添加到/ dev /随机 [英] Using RNDADDENTROPY to add entropy to /dev/random

查看:475
本文介绍了使用RNDADDENTROPY熵添加到/ dev /随机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有产生一些噪音,我要添加到熵池在嵌入式Linux系统中的/ dev / random设备的设备。

I have a device which generates some noise that I want to add to the entropy pool for the /dev/random device in an embedded Linux system.

我在读在/ dev /随机手册页一>,我真的不明白,你传递到RNDADDENTROPY ioctl调用的结构。

I'm reading the man page on /dev/random and I don't really understand the structure that you pass into the RNDADDENTROPY ioctl call.

   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 是以字节为单位计算)?

Is entropy_count in this structure the number of bits that I am adding? Why wouldn't this just always be buf_size * 8 (assuming that buf_size is in terms of bytes)?

此外,为什么 BUF 零大小的数组?我怎么一个值分配给它?

Additionally why is buf a zero size array? How am I supposed to assign a value to it?

感谢这里的任何帮助!

推荐答案

我使用的是硬件RNG去购买我的熵池。我的结构是一个静态的大小
看起来像这样(我的内核有一个稍微不同的random.h;只是复制的内容
你在你找到,并增加任何你想要的数组的大小):

I am using a hardware RNG to stock my entropy pool. My struct is a static size and looks like this (my kernel has a slightly different random.h; just copy what you find in yours and increase the array size to whatever you want):

#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的忽略它等于零,只是不断去。

Whatever you pass in buf will be hashed and will stir the entropy pool. If you are using /dev/urandom, it does not matter what you pass for bit_count because /dev/urandom ignores it equaling zero and just keeps on going.

什么BIT_COUNT确实是推点破在此的/ dev /随机将阻止
等待的东西从物理RNG源添加更多的熵。
因此,它的好推测将会在BIT_COUNT。如果你猜低,最差
这会发生是的/ dev /随机将阻止早于它,否则
将有。如果你猜高,为/ dev /随机将如/ dev / urandom的操作
一点点的时间比它否则将它阻止面前。

What bit_count does is push the point out at which /dev/random will block and wait for something to add more entropy from a physical RNG source. Thus, it's okay to guesstimate on bit_count. If you guess low, the worst that will happen is that /dev/random will block sooner than it otherwise would have. If you guess high, /dev/random will operate like /dev/urandom for a little bit longer than it otherwise would have before it blocks.

您可以根据您的信息源的质量推测将会。
如果是低,像人类键入的字符,你可以将其设置为1或2
每字节。如果它的高,像专用的硬件RNG读取数值,
你可以将其设置为每8位。

You can guesstimate based on the "quality" of your entropy source. If it's low, like characters typed by humans, you can set it to 1 or 2 per byte. If it's high, like values read from a dedicated hardware RNG, you can set it to 8 bits per byte.

这篇关于使用RNDADDENTROPY熵添加到/ dev /随机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆