djpohly / libgfshare

Shamir's secret-sharing method in the Galois Field GF(2**8), modified implementation of the original by Daniel Silverstone
Other
8 stars 1 forks source link

random(3) and secure randomness #2

Open cyphar opened 6 years ago

cyphar commented 6 years ago

Really we should be using getrandom(2) or reading directly from /dev/urandom rather than using random(3) (which is deterministic). I don't really like this justification:

static void
_gfshare_fill_rand_using_random( unsigned char* buffer,
                                 unsigned int count )
{
  unsigned int i;
  for( i = 0; i < count; ++i )
    buffer[i] = (random() & 0xff00) >> 8; /* apparently the bottom 8 aren't
                                           * very random but the middles ones
                                           * are
                                           */
}

I can prepare a patch for this if you like, but it's not clear to me whether this library is actually maintained.

djpohly commented 6 years ago

Yeah, I think that's the reason for the comment at libgfshare.h:34-39. It's already set up so you can assign a different function to gfshare_fill_rand if you want.

(I'm not the author of libgfshare, but I suspect the "not very random" remark is based on the "NOTES" section in the Linux rand(3) page. Perhaps this code used to use that function instead.)