summaryrefslogtreecommitdiffstats
path: root/apps/dhparam.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2016-04-06 17:49:48 +0100
committerMatt Caswell <matt@openssl.org>2016-04-09 10:10:55 +0100
commit0aeddcfa61250a6c474c4f8b3533772a63192f1b (patch)
treed8ac8b14fc1bd8a365d522a0ecf0fc9999c01575 /apps/dhparam.c
parentb9aec69ace2ae84b2b4494cc49725945805d5a29 (diff)
Make DH opaque
Move the dh_st structure into an internal header file and provide relevant accessors for the internal fields. Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'apps/dhparam.c')
-rw-r--r--apps/dhparam.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/apps/dhparam.c b/apps/dhparam.c
index 58baff822a..9ad80edef6 100644
--- a/apps/dhparam.c
+++ b/apps/dhparam.c
@@ -384,40 +384,50 @@ int dhparam_main(int argc, char **argv)
if (C) {
unsigned char *data;
int len, bits;
+ BIGNUM *pbn, *gbn;
- len = BN_num_bytes(dh->p);
- bits = BN_num_bits(dh->p);
+ len = DH_size(dh);
+ 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);
- print_bignum_var(out, dh->p, "dhp", bits, data);
- print_bignum_var(out, dh->g, "dhg", bits, data);
- BIO_printf(out, " DH *dh = DN_new();\n"
+ 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"
"\n"
" if (dh == NULL)\n"
" return NULL;\n");
- BIO_printf(out, " dh->p = BN_bin2bn(dhp_%d, sizeof (dhp_%d), NULL);\n",
- bits, bits);
- BIO_printf(out, " dh->g = BN_bin2bn(dhg_%d, sizeof (dhg_%d), NULL);\n",
- bits, bits);
- BIO_printf(out, " if (!dh->p || !dh->g) {\n"
+ BIO_printf(out, " dhp_bn = 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",
+ bits, bits);
+ BIO_printf(out, " if (dhp_bn == NULL || dhg_bn == NULL\n"
+ " || !DH_set0_pqg(dh, dhp_bn, NULL, dhg_bn)) {\n"
" DH_free(dh);\n"
+ " BN_free(dhp_bn);\n"
+ " BN_free(dhg_bn);\n"
" return NULL;\n"
" }\n");
- if (dh->length)
+ if (DH_get_length(dh) > 0)
BIO_printf(out,
- " dh->length = %ld;\n", dh->length);
+ " if (!DH_set_length(dh, %ld)) {\n"
+ " DH_free(dh);\n"
+ " }\n", DH_get_length(dh));
BIO_printf(out, " return dh;\n}\n");
OPENSSL_free(data);
}
if (!noout) {
+ BIGNUM *q;
+ DH_get0_pqg(dh, NULL, &q, NULL);
if (outformat == FORMAT_ASN1)
i = i2d_DHparams_bio(out, dh);
- else if (dh->q)
+ else if (q != NULL)
i = PEM_write_bio_DHxparams(out, dh);
else
i = PEM_write_bio_DHparams(out, dh);