GH367: Fix dsa keygen for too-short seed

If the seed value for dsa key generation is too short (< qsize),
return an error. Also update the documentation.

Signed-off-by: Rich Salz <rsalz@akamai.com>
Reviewed-by: Emilia Käsper <emilia@openssl.org>
This commit is contained in:
Ismo Puustinen
2015-08-07 22:14:47 -04:00
committed by Rich Salz
parent 3c65047d30
commit f00a10b897
3 changed files with 21 additions and 23 deletions

View File

@@ -132,18 +132,15 @@ int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,
bits = (bits + 63) / 64 * 64;
/*
* NB: seed_len == 0 is special case: copy generated seed to seed_in if
* it is not NULL.
*/
if (seed_len && (seed_len < (size_t)qsize))
seed_in = NULL; /* seed buffer too small -- ignore */
if (seed_len > (size_t)qsize)
seed_len = qsize; /* App. 2.2 of FIPS PUB 186 allows larger
* SEED, but our internal buffers are
* restricted to 160 bits */
if (seed_in != NULL)
if (seed_in != NULL) {
if (seed_len < (size_t)qsize)
return 0;
if (seed_len > (size_t)qsize) {
/* Don't overflow seed local variable. */
seed_len = qsize;
}
memcpy(seed, seed_in, seed_len);
}
if ((ctx = BN_CTX_new()) == NULL)
goto err;
@@ -166,20 +163,18 @@ int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,
for (;;) {
for (;;) { /* find q */
int seed_is_random;
int seed_is_random = seed_in == NULL;
/* step 1 */
if (!BN_GENCB_call(cb, 0, m++))
goto err;
if (!seed_len) {
if (seed_is_random) {
if (RAND_bytes(seed, qsize) <= 0)
goto err;
seed_is_random = 1;
} else {
seed_is_random = 0;
seed_len = 0; /* use random seed if 'seed_in' turns out to
* be bad */
/* If we come back through, use random seed next time. */
seed_in = NULL;
}
memcpy(buf, seed, qsize);
memcpy(buf2, seed, qsize);