
我正在阅读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位.
总结以上是内存溢出为你收集整理的c – 使用RNDADDENTROPY将熵添加到/ dev / random全部内容,希望文章能够帮你解决c – 使用RNDADDENTROPY将熵添加到/ dev / random所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)