summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormiod <>2015-02-15 08:48:24 +0000
committermiod <>2015-02-15 08:48:24 +0000
commitd33df2419dcfb65ea9d3992c313d58a09972b135 (patch)
tree47e0ee6103e2d9f118fbf2e6c566056178835658
parent29153f47f3b6c9395c5d07a642619cd77186d08a (diff)
downloadopenbsd-d33df2419dcfb65ea9d3992c313d58a09972b135.tar.gz
openbsd-d33df2419dcfb65ea9d3992c313d58a09972b135.tar.bz2
openbsd-d33df2419dcfb65ea9d3992c313d58a09972b135.zip
If we decide to discard the provided seed buffer because its size is not
large enough, do it correctly so that the local seed buffer on the stack gets properly initialized in the first iteration of the loop. While there, remove an outdated and bogus comment. Coverity CID 21785 ok doug@ jsing@
-rw-r--r--src/lib/libcrypto/dsa/dsa_gen.c14
-rw-r--r--src/lib/libssl/src/crypto/dsa/dsa_gen.c14
2 files changed, 12 insertions, 16 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c
index dcfa957884..c1664d5f8a 100644
--- a/src/lib/libcrypto/dsa/dsa_gen.c
+++ b/src/lib/libcrypto/dsa/dsa_gen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_gen.c,v 1.18 2015/02/09 15:49:22 jsing Exp $ */ 1/* $OpenBSD: dsa_gen.c,v 1.19 2015/02/15 08:48:24 miod Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -126,12 +126,10 @@ dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits, const EVP_MD *evpmd,
126 126
127 bits = (bits + 63) / 64 * 64; 127 bits = (bits + 63) / 64 * 64;
128 128
129 /* 129 if (seed_len < (size_t)qsize) {
130 * NB: seed_len == 0 is special case: copy generated seed to
131 * seed_in if it is not NULL.
132 */
133 if (seed_len && seed_len < (size_t)qsize)
134 seed_in = NULL; /* seed buffer too small -- ignore */ 130 seed_in = NULL; /* seed buffer too small -- ignore */
131 seed_len = 0;
132 }
135 /* 133 /*
136 * App. 2.2 of FIPS PUB 186 allows larger SEED, 134 * App. 2.2 of FIPS PUB 186 allows larger SEED,
137 * but our internal buffers are restricted to 160 bits 135 * but our internal buffers are restricted to 160 bits
@@ -176,7 +174,7 @@ dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits, const EVP_MD *evpmd,
176 if (!BN_GENCB_call(cb, 0, m++)) 174 if (!BN_GENCB_call(cb, 0, m++))
177 goto err; 175 goto err;
178 176
179 if (!seed_len) { 177 if (seed_len == 0) {
180 arc4random_buf(seed, qsize); 178 arc4random_buf(seed, qsize);
181 seed_is_random = 1; 179 seed_is_random = 1;
182 } else { 180 } else {
@@ -344,7 +342,7 @@ err:
344 *counter_ret = counter; 342 *counter_ret = counter;
345 if (h_ret != NULL) 343 if (h_ret != NULL)
346 *h_ret = h; 344 *h_ret = h;
347 if (seed_out) 345 if (seed_out != NULL)
348 memcpy(seed_out, seed, qsize); 346 memcpy(seed_out, seed, qsize);
349 } 347 }
350 if (ctx) { 348 if (ctx) {
diff --git a/src/lib/libssl/src/crypto/dsa/dsa_gen.c b/src/lib/libssl/src/crypto/dsa/dsa_gen.c
index dcfa957884..c1664d5f8a 100644
--- a/src/lib/libssl/src/crypto/dsa/dsa_gen.c
+++ b/src/lib/libssl/src/crypto/dsa/dsa_gen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_gen.c,v 1.18 2015/02/09 15:49:22 jsing Exp $ */ 1/* $OpenBSD: dsa_gen.c,v 1.19 2015/02/15 08:48:24 miod Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -126,12 +126,10 @@ dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits, const EVP_MD *evpmd,
126 126
127 bits = (bits + 63) / 64 * 64; 127 bits = (bits + 63) / 64 * 64;
128 128
129 /* 129 if (seed_len < (size_t)qsize) {
130 * NB: seed_len == 0 is special case: copy generated seed to
131 * seed_in if it is not NULL.
132 */
133 if (seed_len && seed_len < (size_t)qsize)
134 seed_in = NULL; /* seed buffer too small -- ignore */ 130 seed_in = NULL; /* seed buffer too small -- ignore */
131 seed_len = 0;
132 }
135 /* 133 /*
136 * App. 2.2 of FIPS PUB 186 allows larger SEED, 134 * App. 2.2 of FIPS PUB 186 allows larger SEED,
137 * but our internal buffers are restricted to 160 bits 135 * but our internal buffers are restricted to 160 bits
@@ -176,7 +174,7 @@ dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits, const EVP_MD *evpmd,
176 if (!BN_GENCB_call(cb, 0, m++)) 174 if (!BN_GENCB_call(cb, 0, m++))
177 goto err; 175 goto err;
178 176
179 if (!seed_len) { 177 if (seed_len == 0) {
180 arc4random_buf(seed, qsize); 178 arc4random_buf(seed, qsize);
181 seed_is_random = 1; 179 seed_is_random = 1;
182 } else { 180 } else {
@@ -344,7 +342,7 @@ err:
344 *counter_ret = counter; 342 *counter_ret = counter;
345 if (h_ret != NULL) 343 if (h_ret != NULL)
346 *h_ret = h; 344 *h_ret = h;
347 if (seed_out) 345 if (seed_out != NULL)
348 memcpy(seed_out, seed, qsize); 346 memcpy(seed_out, seed, qsize);
349 } 347 }
350 if (ctx) { 348 if (ctx) {