aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorBeat Bolli <dev@drbeat.li>2018-07-30 07:34:32 +1000
committerPauli <paul.dale@oracle.com>2018-07-30 07:34:32 +1000
commit201b305a2409d9eb13b5e4bfbd4967e04e155a60 (patch)
tree67526bf1fe642f77025d5db3ebbd47bb7e6a039e /apps
parentcb809437d391176a1c2e76f6da77a790c9382c4b (diff)
downloadopenssl-201b305a2409d9eb13b5e4bfbd4967e04e155a60.zip
openssl-201b305a2409d9eb13b5e4bfbd4967e04e155a60.tar.gz
openssl-201b305a2409d9eb13b5e4bfbd4967e04e155a60.tar.bz2
apps/dsaparam.c generates code that is intended to be pasted or included
into an existing source file: the function is static, and the code doesn't include dsa.h. Match the generated C source style of dsaparam. Adjust apps/dhparam.c to match, and rename the BIGNUMs to their more usual single-letter names. Add an error return in the generated C source. both: simplify the callback function Signed-off-by: Beat Bolli <dev@drbeat.li> Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/6797)
Diffstat (limited to 'apps')
-rw-r--r--apps/dhparam.c35
-rw-r--r--apps/dsaparam.c11
2 files changed, 15 insertions, 31 deletions
diff --git a/apps/dhparam.c b/apps/dhparam.c
index 44160fd..13f7675 100644
--- a/apps/dhparam.c
+++ b/apps/dhparam.c
@@ -309,33 +309,31 @@ int dhparam_main(int argc, char **argv)
bits = DH_bits(dh);
DH_get0_pqg(dh, &pbn, NULL, &gbn);
data = app_malloc(len, "print a BN");
- BIO_printf(out, "#ifndef HEADER_DH_H\n"
- "# include <openssl/dh.h>\n"
- "#endif\n"
- "\n");
- BIO_printf(out, "DH *get_dh%d()\n{\n", bits);
+
+ BIO_printf(out, "static DH *get_dh%d(void)\n{\n", bits);
print_bignum_var(out, pbn, "dhp", bits, data);
print_bignum_var(out, gbn, "dhg", bits, data);
BIO_printf(out, " DH *dh = DH_new();\n"
- " BIGNUM *dhp_bn, *dhg_bn;\n"
+ " BIGNUM *p, *g;\n"
"\n"
" if (dh == NULL)\n"
" return NULL;\n");
- BIO_printf(out, " dhp_bn = BN_bin2bn(dhp_%d, sizeof(dhp_%d), NULL);\n",
+ BIO_printf(out, " p = BN_bin2bn(dhp_%d, sizeof(dhp_%d), NULL);\n",
bits, bits);
- BIO_printf(out, " dhg_bn = BN_bin2bn(dhg_%d, sizeof(dhg_%d), NULL);\n",
+ BIO_printf(out, " g = BN_bin2bn(dhg_%d, sizeof(dhg_%d), NULL);\n",
bits, bits);
- BIO_printf(out, " if (dhp_bn == NULL || dhg_bn == NULL\n"
- " || !DH_set0_pqg(dh, dhp_bn, NULL, dhg_bn)) {\n"
+ BIO_printf(out, " if (p == NULL || g == NULL\n"
+ " || !DH_set0_pqg(dh, p, NULL, g)) {\n"
" DH_free(dh);\n"
- " BN_free(dhp_bn);\n"
- " BN_free(dhg_bn);\n"
+ " BN_free(p);\n"
+ " BN_free(g);\n"
" return NULL;\n"
" }\n");
if (DH_get_length(dh) > 0)
BIO_printf(out,
" if (!DH_set_length(dh, %ld)) {\n"
" DH_free(dh);\n"
+ " return NULL;\n"
" }\n", DH_get_length(dh));
BIO_printf(out, " return dh;\n}\n");
OPENSSL_free(data);
@@ -371,16 +369,9 @@ int dhparam_main(int argc, char **argv)
static int dh_cb(int p, int n, BN_GENCB *cb)
{
- char c = '*';
-
- if (p == 0)
- c = '.';
- if (p == 1)
- c = '+';
- if (p == 2)
- c = '*';
- if (p == 3)
- c = '\n';
+ static const char symbols[] = ".+*\n";
+ char c = (p >= 0 && (size_t)p < sizeof(symbols) - 1) ? symbols[p] : '?';
+
BIO_write(BN_GENCB_get_arg(cb), &c, 1);
(void)BIO_flush(BN_GENCB_get_arg(cb));
return 1;
diff --git a/apps/dsaparam.c b/apps/dsaparam.c
index 9d8af9e..b227b76 100644
--- a/apps/dsaparam.c
+++ b/apps/dsaparam.c
@@ -248,16 +248,9 @@ int dsaparam_main(int argc, char **argv)
static int dsa_cb(int p, int n, BN_GENCB *cb)
{
- char c = '*';
+ static const char symbols[] = ".+*\n";
+ char c = (p >= 0 && (size_t)p < sizeof(symbols) - 1) ? symbols[p] : '?';
- if (p == 0)
- c = '.';
- if (p == 1)
- c = '+';
- if (p == 2)
- c = '*';
- if (p == 3)
- c = '\n';
BIO_write(BN_GENCB_get_arg(cb), &c, 1);
(void)BIO_flush(BN_GENCB_get_arg(cb));
return 1;