From 437dba66841a8f6a7a8fddc476e7b4a17b2ef413 Mon Sep 17 00:00:00 2001 From: tb Date: Fri, 14 Jan 2022 09:24:20 +0000 Subject: [PATCH] Convert openssl(1) dsaparam to opaque dsa ok inoguchi jsing --- usr.bin/openssl/dsaparam.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/usr.bin/openssl/dsaparam.c b/usr.bin/openssl/dsaparam.c index 3a907fe6207..33bde035aae 100644 --- a/usr.bin/openssl/dsaparam.c +++ b/usr.bin/openssl/dsaparam.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsaparam.c,v 1.12 2021/11/20 18:10:48 tb Exp $ */ +/* $OpenBSD: dsaparam.c,v 1.13 2022/01/14 09:24:20 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -259,14 +259,14 @@ dsaparam_main(int argc, char **argv) unsigned char *data; int l, len, bits_p; - len = BN_num_bytes(dsa->p); - bits_p = BN_num_bits(dsa->p); + len = BN_num_bytes(DSA_get0_p(dsa)); + bits_p = BN_num_bits(DSA_get0_p(dsa)); data = malloc(len + 20); if (data == NULL) { perror("malloc"); goto end; } - l = BN_bn2bin(dsa->p, data); + l = BN_bn2bin(DSA_get0_p(dsa), data); printf("static unsigned char dsa%d_p[] = {", bits_p); for (i = 0; i < l; i++) { if ((i % 12) == 0) @@ -275,7 +275,7 @@ dsaparam_main(int argc, char **argv) } printf("\n\t};\n"); - l = BN_bn2bin(dsa->q, data); + l = BN_bn2bin(DSA_get0_q(dsa), data); printf("static unsigned char dsa%d_q[] = {", bits_p); for (i = 0; i < l; i++) { if ((i % 12) == 0) @@ -284,7 +284,7 @@ dsaparam_main(int argc, char **argv) } printf("\n\t};\n"); - l = BN_bn2bin(dsa->g, data); + l = BN_bn2bin(DSA_get0_g(dsa), data); printf("static unsigned char dsa%d_g[] = {", bits_p); for (i = 0; i < l; i++) { if ((i % 12) == 0) @@ -295,16 +295,18 @@ dsaparam_main(int argc, char **argv) printf("\n\t};\n\n"); printf("DSA *get_dsa%d()\n\t{\n", bits_p); + printf("\tBIGNUM *p = NULL, *q = NULL, *g = NULL;\n"); printf("\tDSA *dsa;\n\n"); printf("\tif ((dsa = DSA_new()) == NULL) return(NULL);\n"); - printf("\tdsa->p = BN_bin2bn(dsa%d_p, sizeof(dsa%d_p), NULL);\n", + printf("\tp = BN_bin2bn(dsa%d_p, sizeof(dsa%d_p), NULL);\n", bits_p, bits_p); - printf("\tdsa->q = BN_bin2bn(dsa%d_q, sizeof(dsa%d_q), NULL);\n", + printf("\tq = BN_bin2bn(dsa%d_q, sizeof(dsa%d_q), NULL);\n", bits_p, bits_p); - printf("\tdsa->g = BN_bin2bn(dsa%d_g, sizeof(dsa%d_g), NULL);\n", + printf("\tg = BN_bin2bn(dsa%d_g, sizeof(dsa%d_g), NULL);\n", bits_p, bits_p); - printf("\tif ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))\n"); - printf("\t\t{ DSA_free(dsa); return(NULL); }\n"); + printf("\tif (p == NULL || q == NULL || g == NULL)\n"); + printf("\t\t{ BN_free(p); BN_free(q); BN_free(g); DSA_free(dsa); return(NULL); }\n"); + printf("\tDSA_set0_pqg(dsa, p, q, g);\n"); printf("\treturn(dsa);\n\t}\n"); } if (!dsaparam_config.noout) { -- 2.20.1