"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "apps/dhparam.c" between
openssl-1.1.1f.tar.gz and openssl-1.1.1g.tar.gz

About: OpenSSL is a toolkit implementing the Transport Layer Security (TLS) protocols (including SSLv3) as well as a full-strength general purpose cryptographic library. Long Term Support (LTS) version (includes support for TLSv1.3).

dhparam.c  (openssl-1.1.1f):dhparam.c  (openssl-1.1.1g)
/* /*
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at * in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html * https://www.openssl.org/source/license.html
*/ */
#include <openssl/opensslconf.h> #include <openssl/opensslconf.h>
#ifdef OPENSSL_NO_DH #include <stdio.h>
NON_EMPTY_TRANSLATION_UNIT #include <stdlib.h>
#else #include <time.h>
#include <string.h>
# include <stdio.h> #include "apps.h"
# include <stdlib.h> #include "progs.h"
# include <time.h> #include <openssl/bio.h>
# include <string.h> #include <openssl/err.h>
# include "apps.h" #include <openssl/bn.h>
# include "progs.h" #include <openssl/dh.h>
# include <openssl/bio.h> #include <openssl/x509.h>
# include <openssl/err.h> #include <openssl/pem.h>
# include <openssl/bn.h>
# include <openssl/dh.h>
# include <openssl/x509.h>
# include <openssl/pem.h>
# ifndef OPENSSL_NO_DSA
# include <openssl/dsa.h>
# endif
# define DEFBITS 2048 #ifndef OPENSSL_NO_DSA
# include <openssl/dsa.h>
#endif
#define DEFBITS 2048
static int dh_cb(int p, int n, BN_GENCB *cb); static int dh_cb(int p, int n, BN_GENCB *cb);
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
OPT_INFORM, OPT_OUTFORM, OPT_IN, OPT_OUT, OPT_INFORM, OPT_OUTFORM, OPT_IN, OPT_OUT,
OPT_ENGINE, OPT_CHECK, OPT_TEXT, OPT_NOOUT, OPT_ENGINE, OPT_CHECK, OPT_TEXT, OPT_NOOUT,
OPT_DSAPARAM, OPT_C, OPT_2, OPT_5, OPT_DSAPARAM, OPT_C, OPT_2, OPT_5,
OPT_R_ENUM OPT_R_ENUM
} OPTION_CHOICE; } OPTION_CHOICE;
skipping to change at line 59 skipping to change at line 55
{"inform", OPT_INFORM, 'F', "Input format, DER or PEM"}, {"inform", OPT_INFORM, 'F', "Input format, DER or PEM"},
{"outform", OPT_OUTFORM, 'F', "Output format, DER or PEM"}, {"outform", OPT_OUTFORM, 'F', "Output format, DER or PEM"},
{"out", OPT_OUT, '>', "Output file"}, {"out", OPT_OUT, '>', "Output file"},
{"check", OPT_CHECK, '-', "Check the DH parameters"}, {"check", OPT_CHECK, '-', "Check the DH parameters"},
{"text", OPT_TEXT, '-', "Print a text form of the DH parameters"}, {"text", OPT_TEXT, '-', "Print a text form of the DH parameters"},
{"noout", OPT_NOOUT, '-', "Don't output any DH parameters"}, {"noout", OPT_NOOUT, '-', "Don't output any DH parameters"},
OPT_R_OPTIONS, OPT_R_OPTIONS,
{"C", OPT_C, '-', "Print C code"}, {"C", OPT_C, '-', "Print C code"},
{"2", OPT_2, '-', "Generate parameters using 2 as the generator value"}, {"2", OPT_2, '-', "Generate parameters using 2 as the generator value"},
{"5", OPT_5, '-', "Generate parameters using 5 as the generator value"}, {"5", OPT_5, '-', "Generate parameters using 5 as the generator value"},
# ifndef OPENSSL_NO_DSA #ifndef OPENSSL_NO_DSA
{"dsaparam", OPT_DSAPARAM, '-', {"dsaparam", OPT_DSAPARAM, '-',
"Read or generate DSA parameters, convert to DH"}, "Read or generate DSA parameters, convert to DH"},
# endif #endif
# ifndef OPENSSL_NO_ENGINE #ifndef OPENSSL_NO_ENGINE
{"engine", OPT_ENGINE, 's', "Use engine e, possibly a hardware device"}, {"engine", OPT_ENGINE, 's', "Use engine e, possibly a hardware device"},
# endif #endif
{NULL} {NULL}
}; };
int dhparam_main(int argc, char **argv) int dhparam_main(int argc, char **argv)
{ {
BIO *in = NULL, *out = NULL; BIO *in = NULL, *out = NULL;
DH *dh = NULL; DH *dh = NULL;
char *infile = NULL, *outfile = NULL, *prog; char *infile = NULL, *outfile = NULL, *prog;
ENGINE *e = NULL; ENGINE *e = NULL;
#ifndef OPENSSL_NO_DSA #ifndef OPENSSL_NO_DSA
skipping to change at line 149 skipping to change at line 145
} }
argc = opt_num_rest(); argc = opt_num_rest();
argv = opt_rest(); argv = opt_rest();
if (argv[0] != NULL && (!opt_int(argv[0], &num) || num <= 0)) if (argv[0] != NULL && (!opt_int(argv[0], &num) || num <= 0))
goto end; goto end;
if (g && !num) if (g && !num)
num = DEFBITS; num = DEFBITS;
# ifndef OPENSSL_NO_DSA #ifndef OPENSSL_NO_DSA
if (dsaparam && g) { if (dsaparam && g) {
BIO_printf(bio_err, BIO_printf(bio_err,
"generator may not be chosen for DSA parameters\n"); "generator may not be chosen for DSA parameters\n");
goto end; goto end;
} }
# endif #endif
out = bio_open_default(outfile, 'w', outformat); out = bio_open_default(outfile, 'w', outformat);
if (out == NULL) if (out == NULL)
goto end; goto end;
/* DH parameters */ /* DH parameters */
if (num && !g) if (num && !g)
g = 2; g = 2;
if (num) { if (num) {
BN_GENCB *cb; BN_GENCB *cb;
cb = BN_GENCB_new(); cb = BN_GENCB_new();
if (cb == NULL) { if (cb == NULL) {
ERR_print_errors(bio_err); ERR_print_errors(bio_err);
goto end; goto end;
} }
BN_GENCB_set(cb, dh_cb, bio_err); BN_GENCB_set(cb, dh_cb, bio_err);
# ifndef OPENSSL_NO_DSA #ifndef OPENSSL_NO_DSA
if (dsaparam) { if (dsaparam) {
DSA *dsa = DSA_new(); DSA *dsa = DSA_new();
BIO_printf(bio_err, BIO_printf(bio_err,
"Generating DSA parameters, %d bit long prime\n", num); "Generating DSA parameters, %d bit long prime\n", num);
if (dsa == NULL if (dsa == NULL
|| !DSA_generate_parameters_ex(dsa, num, NULL, 0, NULL, NULL, || !DSA_generate_parameters_ex(dsa, num, NULL, 0, NULL, NULL,
cb)) { cb)) {
DSA_free(dsa); DSA_free(dsa);
BN_GENCB_free(cb); BN_GENCB_free(cb);
skipping to change at line 199 skipping to change at line 195
} }
dh = DSA_dup_DH(dsa); dh = DSA_dup_DH(dsa);
DSA_free(dsa); DSA_free(dsa);
if (dh == NULL) { if (dh == NULL) {
BN_GENCB_free(cb); BN_GENCB_free(cb);
ERR_print_errors(bio_err); ERR_print_errors(bio_err);
goto end; goto end;
} }
} else } else
# endif #endif
{ {
dh = DH_new(); dh = DH_new();
BIO_printf(bio_err, BIO_printf(bio_err,
"Generating DH parameters, %d bit long safe prime, genera tor %d\n", "Generating DH parameters, %d bit long safe prime, genera tor %d\n",
num, g); num, g);
BIO_printf(bio_err, "This is going to take a long time\n"); BIO_printf(bio_err, "This is going to take a long time\n");
if (dh == NULL || !DH_generate_parameters_ex(dh, num, g, cb)) { if (dh == NULL || !DH_generate_parameters_ex(dh, num, g, cb)) {
BN_GENCB_free(cb); BN_GENCB_free(cb);
ERR_print_errors(bio_err); ERR_print_errors(bio_err);
goto end; goto end;
} }
} }
BN_GENCB_free(cb); BN_GENCB_free(cb);
} else { } else {
in = bio_open_default(infile, 'r', informat); in = bio_open_default(infile, 'r', informat);
if (in == NULL) if (in == NULL)
goto end; goto end;
# ifndef OPENSSL_NO_DSA #ifndef OPENSSL_NO_DSA
if (dsaparam) { if (dsaparam) {
DSA *dsa; DSA *dsa;
if (informat == FORMAT_ASN1) if (informat == FORMAT_ASN1)
dsa = d2i_DSAparams_bio(in, NULL); dsa = d2i_DSAparams_bio(in, NULL);
else /* informat == FORMAT_PEM */ else /* informat == FORMAT_PEM */
dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL); dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL);
if (dsa == NULL) { if (dsa == NULL) {
BIO_printf(bio_err, "unable to load DSA parameters\n"); BIO_printf(bio_err, "unable to load DSA parameters\n");
skipping to change at line 242 skipping to change at line 238
goto end; goto end;
} }
dh = DSA_dup_DH(dsa); dh = DSA_dup_DH(dsa);
DSA_free(dsa); DSA_free(dsa);
if (dh == NULL) { if (dh == NULL) {
ERR_print_errors(bio_err); ERR_print_errors(bio_err);
goto end; goto end;
} }
} else } else
# endif #endif
{ {
if (informat == FORMAT_ASN1) { if (informat == FORMAT_ASN1) {
/* /*
* We have no PEM header to determine what type of DH params it * We have no PEM header to determine what type of DH params it
* is. We'll just try both. * is. We'll just try both.
*/ */
dh = d2i_DHparams_bio(in, NULL); dh = d2i_DHparams_bio(in, NULL);
/* BIO_reset() returns 0 for success for file BIOs only!!! */ /* BIO_reset() returns 0 for success for file BIOs only!!! */
if (dh == NULL && BIO_reset(in) == 0) if (dh == NULL && BIO_reset(in) == 0)
dh = d2i_DHxparams_bio(in, NULL); dh = d2i_DHxparams_bio(in, NULL);
skipping to change at line 379 skipping to change at line 375
static int dh_cb(int p, int n, BN_GENCB *cb) static int dh_cb(int p, int n, BN_GENCB *cb)
{ {
static const char symbols[] = ".+*\n"; static const char symbols[] = ".+*\n";
char c = (p >= 0 && (size_t)p < sizeof(symbols) - 1) ? symbols[p] : '?'; char c = (p >= 0 && (size_t)p < sizeof(symbols) - 1) ? symbols[p] : '?';
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;
} }
#endif
 End of changes. 13 change blocks. 
32 lines changed or deleted 28 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)