提交 201b305a 编写于 作者: B Beat Bolli 提交者: Pauli

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: NBeat Bolli <dev@drbeat.li>
Reviewed-by: NRich Salz <rsalz@openssl.org>
Reviewed-by: NPaul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/6797)
上级 cb809437
...@@ -309,33 +309,31 @@ int dhparam_main(int argc, char **argv) ...@@ -309,33 +309,31 @@ int dhparam_main(int argc, char **argv)
bits = DH_bits(dh); bits = DH_bits(dh);
DH_get0_pqg(dh, &pbn, NULL, &gbn); DH_get0_pqg(dh, &pbn, NULL, &gbn);
data = app_malloc(len, "print a BN"); data = app_malloc(len, "print a BN");
BIO_printf(out, "#ifndef HEADER_DH_H\n"
"# include <openssl/dh.h>\n" BIO_printf(out, "static DH *get_dh%d(void)\n{\n", bits);
"#endif\n"
"\n");
BIO_printf(out, "DH *get_dh%d()\n{\n", bits);
print_bignum_var(out, pbn, "dhp", bits, data); print_bignum_var(out, pbn, "dhp", bits, data);
print_bignum_var(out, gbn, "dhg", bits, data); print_bignum_var(out, gbn, "dhg", bits, data);
BIO_printf(out, " DH *dh = DH_new();\n" BIO_printf(out, " DH *dh = DH_new();\n"
" BIGNUM *dhp_bn, *dhg_bn;\n" " BIGNUM *p, *g;\n"
"\n" "\n"
" if (dh == NULL)\n" " if (dh == NULL)\n"
" return 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); 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); bits, bits);
BIO_printf(out, " if (dhp_bn == NULL || dhg_bn == NULL\n" BIO_printf(out, " if (p == NULL || g == NULL\n"
" || !DH_set0_pqg(dh, dhp_bn, NULL, dhg_bn)) {\n" " || !DH_set0_pqg(dh, p, NULL, g)) {\n"
" DH_free(dh);\n" " DH_free(dh);\n"
" BN_free(dhp_bn);\n" " BN_free(p);\n"
" BN_free(dhg_bn);\n" " BN_free(g);\n"
" return NULL;\n" " return NULL;\n"
" }\n"); " }\n");
if (DH_get_length(dh) > 0) if (DH_get_length(dh) > 0)
BIO_printf(out, BIO_printf(out,
" if (!DH_set_length(dh, %ld)) {\n" " if (!DH_set_length(dh, %ld)) {\n"
" DH_free(dh);\n" " DH_free(dh);\n"
" return NULL;\n"
" }\n", DH_get_length(dh)); " }\n", DH_get_length(dh));
BIO_printf(out, " return dh;\n}\n"); BIO_printf(out, " return dh;\n}\n");
OPENSSL_free(data); OPENSSL_free(data);
...@@ -371,16 +369,9 @@ int dhparam_main(int argc, char **argv) ...@@ -371,16 +369,9 @@ int dhparam_main(int argc, char **argv)
static int dh_cb(int p, int n, BN_GENCB *cb) static int dh_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); BIO_write(BN_GENCB_get_arg(cb), &c, 1);
(void)BIO_flush(BN_GENCB_get_arg(cb)); (void)BIO_flush(BN_GENCB_get_arg(cb));
return 1; return 1;
......
...@@ -248,16 +248,9 @@ int dsaparam_main(int argc, char **argv) ...@@ -248,16 +248,9 @@ int dsaparam_main(int argc, char **argv)
static int dsa_cb(int p, int n, BN_GENCB *cb) 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); BIO_write(BN_GENCB_get_arg(cb), &c, 1);
(void)BIO_flush(BN_GENCB_get_arg(cb)); (void)BIO_flush(BN_GENCB_get_arg(cb));
return 1; return 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册