|
|
5105f4 |
diff -up libgcrypt-1.5.3/random/random-csprng.c.rng-predictable libgcrypt-1.5.3/random/random-csprng.c
|
|
|
5105f4 |
--- libgcrypt-1.5.3/random/random-csprng.c.rng-predictable 2015-08-11 14:31:35.904275580 +0200
|
|
|
5105f4 |
+++ libgcrypt-1.5.3/random/random-csprng.c 2016-08-17 23:35:15.691980751 +0200
|
|
|
5105f4 |
@@ -561,41 +561,46 @@ _gcry_rngcsprng_randomize (void *buffer,
|
|
|
5105f4 |
|
|
|
5105f4 |
|
|
|
5105f4 |
/*
|
|
|
5105f4 |
- Mix the pool:
|
|
|
5105f4 |
-
|
|
|
5105f4 |
- |........blocks*20byte........|20byte|..44byte..|
|
|
|
5105f4 |
- <..44byte..> <20byte>
|
|
|
5105f4 |
- | |
|
|
|
5105f4 |
- | +------+
|
|
|
5105f4 |
- +---------------------------|----------+
|
|
|
5105f4 |
- v v
|
|
|
5105f4 |
- |........blocks*20byte........|20byte|..44byte..|
|
|
|
5105f4 |
- <.....64bytes.....>
|
|
|
5105f4 |
- |
|
|
|
5105f4 |
- +----------------------------------+
|
|
|
5105f4 |
- Hash
|
|
|
5105f4 |
- v
|
|
|
5105f4 |
- |.............................|20byte|..44byte..|
|
|
|
5105f4 |
- <20byte><20byte><..44byte..>
|
|
|
5105f4 |
- | |
|
|
|
5105f4 |
- | +---------------------+
|
|
|
5105f4 |
- +-----------------------------+ |
|
|
|
5105f4 |
- v v
|
|
|
5105f4 |
- |.............................|20byte|..44byte..|
|
|
|
5105f4 |
- <.....64byte......>
|
|
|
5105f4 |
- |
|
|
|
5105f4 |
- +-------------------------+
|
|
|
5105f4 |
- Hash
|
|
|
5105f4 |
- v
|
|
|
5105f4 |
- |.............................|20byte|..44byte..|
|
|
|
5105f4 |
- <20byte><20byte><..44byte..>
|
|
|
5105f4 |
-
|
|
|
5105f4 |
- and so on until we did this for all blocks.
|
|
|
5105f4 |
-
|
|
|
5105f4 |
- To better protect against implementation errors in this code, we
|
|
|
5105f4 |
- xor a digest of the entire pool into the pool before mixing.
|
|
|
5105f4 |
-
|
|
|
5105f4 |
- Note: this function must only be called with a locked pool.
|
|
|
5105f4 |
+ * Mix the 600 byte pool. Note that the 64 byte scratch area directly
|
|
|
5105f4 |
+ * follows the pool. The numbers in the diagram give the number of
|
|
|
5105f4 |
+ * bytes.
|
|
|
5105f4 |
+ * <................600...............> <.64.>
|
|
|
5105f4 |
+ * pool |------------------------------------| |------|
|
|
|
5105f4 |
+ * <20><.24.> <20>
|
|
|
5105f4 |
+ * | | +-----+
|
|
|
5105f4 |
+ * +-----|-------------------------------|-+
|
|
|
5105f4 |
+ * +-------------------------------|-|-+
|
|
|
5105f4 |
+ * v v v
|
|
|
5105f4 |
+ * |------|
|
|
|
5105f4 |
+ * <hash>
|
|
|
5105f4 |
+ * +---------------------------------------+
|
|
|
5105f4 |
+ * v
|
|
|
5105f4 |
+ * <20>
|
|
|
5105f4 |
+ * pool' |------------------------------------|
|
|
|
5105f4 |
+ * <20><20><.24.>
|
|
|
5105f4 |
+ * +---|-----|---------------------------+
|
|
|
5105f4 |
+ * +-----|---------------------------|-+
|
|
|
5105f4 |
+ * +---------------------------|-|-+
|
|
|
5105f4 |
+ * v v v
|
|
|
5105f4 |
+ * |------|
|
|
|
5105f4 |
+ * <hash>
|
|
|
5105f4 |
+ * |
|
|
|
5105f4 |
+ * +-----------------------------------+
|
|
|
5105f4 |
+ * v
|
|
|
5105f4 |
+ * <20>
|
|
|
5105f4 |
+ * pool'' |------------------------------------|
|
|
|
5105f4 |
+ * <20><20><20><.24.>
|
|
|
5105f4 |
+ * +---|-----|-----------------------+
|
|
|
5105f4 |
+ * +-----|-----------------------|-+
|
|
|
5105f4 |
+ * +-----------------------|-|-+
|
|
|
5105f4 |
+ * v v v
|
|
|
5105f4 |
+ *
|
|
|
5105f4 |
+ * and so on until we did this for all 30 blocks.
|
|
|
5105f4 |
+ *
|
|
|
5105f4 |
+ * To better protect against implementation errors in this code, we
|
|
|
5105f4 |
+ * xor a digest of the entire pool into the pool before mixing.
|
|
|
5105f4 |
+ *
|
|
|
5105f4 |
+ * Note: this function must only be called with a locked pool.
|
|
|
5105f4 |
*/
|
|
|
5105f4 |
static void
|
|
|
5105f4 |
mix_pool(unsigned char *pool)
|
|
|
5105f4 |
@@ -615,32 +620,30 @@ mix_pool(unsigned char *pool)
|
|
|
5105f4 |
gcry_assert (pool_is_locked);
|
|
|
5105f4 |
_gcry_rmd160_init( &md );
|
|
|
5105f4 |
|
|
|
5105f4 |
- /* Loop over the pool. */
|
|
|
5105f4 |
+ /* pool_0 -> pool'. */
|
|
|
5105f4 |
pend = pool + POOLSIZE;
|
|
|
5105f4 |
- memcpy(hashbuf, pend - DIGESTLEN, DIGESTLEN );
|
|
|
5105f4 |
- memcpy(hashbuf+DIGESTLEN, pool, BLOCKLEN-DIGESTLEN);
|
|
|
5105f4 |
- _gcry_rmd160_mixblock( &md, hashbuf);
|
|
|
5105f4 |
- memcpy(pool, hashbuf, 20 );
|
|
|
5105f4 |
+ memcpy (hashbuf, pend - DIGESTLEN, DIGESTLEN);
|
|
|
5105f4 |
+ memcpy (hashbuf+DIGESTLEN, pool, BLOCKLEN-DIGESTLEN);
|
|
|
5105f4 |
+ _gcry_rmd160_mixblock (&md, hashbuf);
|
|
|
5105f4 |
+ memcpy (pool, hashbuf, DIGESTLEN);
|
|
|
5105f4 |
|
|
|
5105f4 |
if (failsafe_digest_valid && pool == rndpool)
|
|
|
5105f4 |
{
|
|
|
5105f4 |
- for (i=0; i < 20; i++)
|
|
|
5105f4 |
+ for (i=0; i < DIGESTLEN; i++)
|
|
|
5105f4 |
pool[i] ^= failsafe_digest[i];
|
|
|
5105f4 |
}
|
|
|
5105f4 |
|
|
|
5105f4 |
+ /* Loop for the remaining iterations. */
|
|
|
5105f4 |
p = pool;
|
|
|
5105f4 |
for (n=1; n < POOLBLOCKS; n++)
|
|
|
5105f4 |
{
|
|
|
5105f4 |
- memcpy (hashbuf, p, DIGESTLEN);
|
|
|
5105f4 |
-
|
|
|
5105f4 |
- p += DIGESTLEN;
|
|
|
5105f4 |
- if (p+DIGESTLEN+BLOCKLEN < pend)
|
|
|
5105f4 |
- memcpy (hashbuf+DIGESTLEN, p+DIGESTLEN, BLOCKLEN-DIGESTLEN);
|
|
|
5105f4 |
+ if (p + BLOCKLEN < pend)
|
|
|
5105f4 |
+ memcpy (hashbuf, p, BLOCKLEN);
|
|
|
5105f4 |
else
|
|
|
5105f4 |
{
|
|
|
5105f4 |
- unsigned char *pp = p + DIGESTLEN;
|
|
|
5105f4 |
+ unsigned char *pp = p;
|
|
|
5105f4 |
|
|
|
5105f4 |
- for (i=DIGESTLEN; i < BLOCKLEN; i++ )
|
|
|
5105f4 |
+ for (i=0; i < BLOCKLEN; i++ )
|
|
|
5105f4 |
{
|
|
|
5105f4 |
if ( pp >= pend )
|
|
|
5105f4 |
pp = pool;
|
|
|
5105f4 |
@@ -648,8 +651,9 @@ mix_pool(unsigned char *pool)
|
|
|
5105f4 |
}
|
|
|
5105f4 |
}
|
|
|
5105f4 |
|
|
|
5105f4 |
- _gcry_rmd160_mixblock ( &md, hashbuf);
|
|
|
5105f4 |
- memcpy(p, hashbuf, 20 );
|
|
|
5105f4 |
+ _gcry_rmd160_mixblock (&md, hashbuf);
|
|
|
5105f4 |
+ p += DIGESTLEN;
|
|
|
5105f4 |
+ memcpy (p, hashbuf, DIGESTLEN);
|
|
|
5105f4 |
}
|
|
|
5105f4 |
|
|
|
5105f4 |
/* Our hash implementation does only leave small parts (64 bytes)
|