a562621
From gnutls-devel-bounces+joe=manyfish.co.uk@gnu.org Tue Jan 08 18:41:52 2008
a562621
From: Werner Koch <wk@gnupg.org>
a562621
To: Simon Josefsson <simon@josefsson.org>
a562621
Mail-Followup-To: Simon Josefsson <simon@josefsson.org>,
a562621
	Guus Sliepen <guus@debian.org>, gnutls-devel@gnu.org,
a562621
	343085@bugs.debian.org, gcrypt-devel@gnupg.org
a562621
Date: Tue, 08 Jan 2008 12:39:02 +0100
a562621
Cc: Guus Sliepen <guus@debian.org>, gcrypt-devel@gnupg.org,
a562621
	gnutls-devel@gnu.org, 343085@bugs.debian.org
a562621
Subject: [patch] Re: Bug#448775: Uses too much entropy (Debian Bug #343085)
a562621
MIME-Version: 1.0
a562621
Content-Transfer-Encoding: 8bit
a562621
Content-Type: text/plain; charset=utf-8
a562621
Status: RO
a562621
a562621
On Tue,  8 Jan 2008 11:59, wk@gnupg.org said:
a562621
a562621
> Anyway there 3000 calls to /dev/urandom are far too many for an initial
a562621
> pool filling.  I need to check this.
a562621
a562621
Found it.  The bug was introduced with libgcrypt 1.3.1.  Here is a patch:
a562621
a562621
2008-01-08  Werner Koch  <wk@g10code.com>
a562621
a562621
	* random.c (add_randomness): Do not just increment
a562621
	POOL_FILLED_COUNTER but update it by the actual amount of data.
a562621
a562621
Index: cipher/random.c
a562621
===================================================================
a562621
--- cipher/random.c	(revision 1277)
a562621
+++ cipher/random.c	(working copy)
a562621
@@ -1115,6 +1115,7 @@
a562621
 add_randomness (const void *buffer, size_t length, enum random_origins origin)
a562621
 {
a562621
   const unsigned char *p = buffer;
a562621
+  size_t count = 0;
a562621
 
a562621
   assert (pool_is_locked);
a562621
 
a562621
@@ -1123,6 +1124,7 @@
a562621
   while (length-- )
a562621
     {
a562621
       rndpool[pool_writepos++] ^= *p++;
a562621
+      count++;
a562621
       if (pool_writepos >= POOLSIZE )
a562621
         {
a562621
           /* It is possible that we are invoked before the pool is
a562621
@@ -1132,7 +1134,9 @@
a562621
              separately.  See also the remarks about the seed file. */
a562621
           if (origin >= RANDOM_ORIGIN_SLOWPOLL && !pool_filled)
a562621
             {
a562621
-              if (++pool_filled_counter >= POOLSIZE)
a562621
+              pool_filled_counter += count;
a562621
+              count = 0;
a562621
+              if (pool_filled_counter >= POOLSIZE)
a562621
                 pool_filled = 1;
a562621
             }
a562621
           pool_writepos = 0;
a562621
a562621
a562621
Also commited to SVN.  Old and new stats:
a562621
a562621
$ LD_PRELOAD=/usr/local/lib/libgcrypt.so ./benchmark --verbose random
a562621
random       130ms    30ms
a562621
random usage: poolsize=600 mixed=972 polls=3000/200 added=4200/378400
a562621
              outmix=200 getlvl1=200/13600 getlvl2=0/0
a562621
a562621
$ ./benchmark --verbose random
a562621
random        40ms    30ms
a562621
random usage: poolsize=600 mixed=377 polls=25/200 added=1225/21400
a562621
              outmix=200 getlvl1=200/13600 getlvl2=0/0
a562621
a562621
a562621
a562621
Shalom-Salam,
a562621
a562621
   Werner
a562621
a562621
a562621
a562621
-- 
a562621
Die Gedanken sind frei.  Auschnahme regelt ein Bundeschgesetz.
a562621
a562621
a562621
a562621
_______________________________________________
a562621
Gnutls-devel mailing list
a562621
Gnutls-devel@gnu.org
a562621
http://lists.gnu.org/mailman/listinfo/gnutls-devel
a562621