samedi 30 juillet 2022

Can't make a good ioctl request (-1) to /dev/urandom with `RNDADDENTROPY`

I'm new the the /dev/random|/dev/urandom interface.

Reading the /dev/random manual for the ioctl() interface, using RNDADDENTROPY shows this

    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.

In post, I saw a more understandable struct to pass to the ioctl call.

However, I'm not sure about the parameters of the ioctl() call I need to make.

I've tried:

int fd_w_noblock = open(_FILE,O_NONBLOCK);
struct my_rand_pool_info rnpl
int ret = ioctl(fd_w_noblock,RNDADDENTROPY, &rnpl) // assuming the output of the ioctl() call is sent to struct rand_pool_info (my struct my_rand_pool_info has has sized `buf`)

I can't seem to make a good ioctl() call, get ret==-1. Please guide me with the parameters of my ioctl() call.




Aucun commentaire:

Enregistrer un commentaire