[Michael Frankowski] libgcrypt - rndegd question/problem

Werner Koch wk@g10code.com
Thu, 18 Sep 2003 18:07:34 +0200


[Michael asked me to forward this message]

Good Morning,

  I am trying to get libgcrypt version 1.1.43 working on my Solaris 8 box
using egd as the random number source. I have a question about the code.

  My problem is with two routines --

  do_read   and   rndegd_gather_random.

  I want to make sure I am understanding what is going on, if yes, I have
found a bug.

  Inside do_read, at about line 104 'n' is set to the number of bytes
read.  At about line 112 'n' is added to 'nread', and subtracted from
'nbytes' (Which I think is the number of bytes requested.). Now comes
the part I am confused about...at about line 116 you return 'nbytes',
which is either '0', or the number of bytes that you still need to
read.

  So inside rndegd_gather_random we call do_read asking for one byte. It
returns '0', we don't care. Then we call do_read again for "buffer[0]"
bytes. We add the 'n' bytes using (*add), 'n' should be '0'.

  Now we hit the while loop and I have big problems. We are asking for
'length' bytes of random data. At around line 252 we get "length -= n;"
to cut down on the length. But most of the time on a successful read
'n' is 0. Only when we DON'T get enough entropy is 'n' set to anything
so only then do we cut down on the length.

  Eventually we are asking for only 1 byte of entropy, and that is ALWAYS
successful, so we always get '0' back.

  Unless I am wrong, and missed something, do_read should be returnning
'nread' not 'nbytes'.

  My question -- am I missing something??

  Thank you for your help,

    - Michael Caerwyn
 (mfrankow@winternet.com)