I am using randomsound because I thought it would be a good idea to inject some additional entropy into the entropy pools of my linux machines (clearly those machines have a corresponding sound card).

(Un)fortunately, I am a quite paranoid person, and, therefore, I am reviewing the source of randomsound in the moment and got stuck at the following code pieces:

In randomsound.c, there is the structure

struct injector {
  int ent_count;
  int size;
  union {
    int ints[128];
    BitField bitfield[512];
  } value;
} random_injector;

which is used to transfer the noise from the sound card to /dev/random

if (ioctl(randomfd, RNDADDENTROPY, &random_injector) == -1) {

However, it is said explicitly (https://stackoverflow.com/questions/17118705/using-rndaddentropy-to-add-entropy-to-dev-random) that injector must match random.h's struct rand_pool_info.

This struct is filled with data via

for (i = 0; i < depositsize; ++i) {
  bitbuffer_extract_bits(buffered_bits, random_injector.value.bitfield + i, 8);

which obviously only works on injector's BitField.

So the actual problem is this ints-array in injector, which is always of size 128 int and is never used in the code. The default size of depositesize is 64. And as far as I can tell, with this configuration, the entropy pool is increased by 64*8 bit and 64 bytes are written to the entropy pool. But those bytes belong to ints which is never touched.

So my main question is: Is the default configuration of randomsound always injecting the same bytes to the entropy pool? Or am I simply wrong with my interpretation of the code.


Ah ... I see. I am not a C/C++-expert.

So the union in injector "projects"ints on bitfield and vice versa. That is, the start of ints and bitfield in memory is the same. Writing on bitfield automatically writes on ints.

See http://www.wachtler.de/ck/8_7_struct_union.html (in german).

So everything is fine.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.