From 0aeddcfa61250a6c474c4f8b3533772a63192f1b Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Wed, 6 Apr 2016 17:49:48 +0100 Subject: 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 --- apps/dhparam.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'apps/dhparam.c') 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 \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); -- cgit v1.2.3