Always return multiple of block length bytes from default DRBG seed
authorDr. Stephen Henson <steve@openssl.org>
Sat, 23 Apr 2011 20:05:19 +0000 (20:05 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Sat, 23 Apr 2011 20:05:19 +0000 (20:05 +0000)
callback.

Handle case where no multiple of the block size is in the interval
[min_len, max_len].

CHANGES
crypto/rand/rand_lib.c
fips/rand/fips_drbg_lib.c

diff --git a/CHANGES b/CHANGES
index 6e54214b404f0c936b07cf327311c2bfa3e6ed94..aa0fe51e19bbe18e9b25a0066776513fb97a544b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,14 @@
 
  Changes between 1.0.1 and 1.1.0  [xx XXX xxxx]
 
 
  Changes between 1.0.1 and 1.1.0  [xx XXX xxxx]
 
+  *) Minor change to DRBG entropy callback semantics. In some cases
+     there is no mutiple of the block length between min_len and
+     max_len. Allow the callback to return more than max_len bytes
+     of entropy but discard any extra: it is the callback's responsibility
+     to ensure that the extra data discarded does not impact the
+     requested amount of entropy.
+     [Steve Henson]
+
   *) Add PRNG security strength checks to RSA, DSA and ECDSA using 
      information in FIPS186-3, SP800-57 and SP800-131A.
      [Steve Henson]
   *) Add PRNG security strength checks to RSA, DSA and ECDSA using 
      information in FIPS186-3, SP800-57 and SP800-131A.
      [Steve Henson]
index 0e8201316307dc940565e8e0a51d8f0c0d7adca2..f3bd4e632eebc07384bd368db458a8b4dc3ef2fb 100644 (file)
@@ -201,6 +201,8 @@ static size_t drbg_get_entropy(DRBG_CTX *ctx, unsigned char **pout,
        *pout = OPENSSL_malloc(min_len);
        if (!*pout)
                return 0;
        *pout = OPENSSL_malloc(min_len);
        if (!*pout)
                return 0;
+       /* Round up request to multiple of block size */
+       min_len = ((min_len + 19) / 20) * 20;
        if (RAND_SSLeay()->bytes(*pout, min_len) <= 0)
                {
                OPENSSL_free(*pout);
        if (RAND_SSLeay()->bytes(*pout, min_len) <= 0)
                {
                OPENSSL_free(*pout);
index 46e42e2947d521211925f70d0bfd51329ae7c3f6..7892a02b60227bc6390d78903232f62f63a4d19c 100644 (file)
@@ -153,7 +153,10 @@ static size_t fips_get_entropy(DRBG_CTX *dctx, unsigned char **pout,
                        return 0;
                        }
                }
                        return 0;
                        }
                }
-       return rv - bl;
+       rv -= bl;
+       if (rv > max_len)
+               return max_len;
+       return rv;
        }
 
 static void fips_cleanup_entropy(DRBG_CTX *dctx,
        }
 
 static void fips_cleanup_entropy(DRBG_CTX *dctx,