version 1.14, 2022/11/11 17:07:38 |
version 1.15, 2023/03/06 14:32:05 |
|
|
char *outfile; |
char *outfile; |
int outformat; |
int outformat; |
int text; |
int text; |
} dh_config; |
} cfg; |
|
|
static const struct option dh_options[] = { |
static const struct option dh_options[] = { |
{ |
{ |
.name = "C", |
.name = "C", |
.desc = "Convert DH parameters into C code", |
.desc = "Convert DH parameters into C code", |
.type = OPTION_FLAG, |
.type = OPTION_FLAG, |
.opt.flag = &dh_config.C, |
.opt.flag = &cfg.C, |
}, |
}, |
{ |
{ |
.name = "check", |
.name = "check", |
.desc = "Check the DH parameters", |
.desc = "Check the DH parameters", |
.type = OPTION_FLAG, |
.type = OPTION_FLAG, |
.opt.flag = &dh_config.check, |
.opt.flag = &cfg.check, |
}, |
}, |
{ |
{ |
.name = "in", |
.name = "in", |
.argname = "file", |
.argname = "file", |
.desc = "Input file (default stdin)", |
.desc = "Input file (default stdin)", |
.type = OPTION_ARG, |
.type = OPTION_ARG, |
.opt.arg = &dh_config.infile, |
.opt.arg = &cfg.infile, |
}, |
}, |
{ |
{ |
.name = "inform", |
.name = "inform", |
.argname = "format", |
.argname = "format", |
.desc = "Input format (DER or PEM (default))", |
.desc = "Input format (DER or PEM (default))", |
.type = OPTION_ARG_FORMAT, |
.type = OPTION_ARG_FORMAT, |
.opt.value = &dh_config.informat, |
.opt.value = &cfg.informat, |
}, |
}, |
{ |
{ |
.name = "noout", |
.name = "noout", |
.desc = "No output", |
.desc = "No output", |
.type = OPTION_FLAG, |
.type = OPTION_FLAG, |
.opt.flag = &dh_config.noout, |
.opt.flag = &cfg.noout, |
}, |
}, |
{ |
{ |
.name = "out", |
.name = "out", |
.argname = "file", |
.argname = "file", |
.desc = "Output file (default stdout)", |
.desc = "Output file (default stdout)", |
.type = OPTION_ARG, |
.type = OPTION_ARG, |
.opt.arg = &dh_config.outfile, |
.opt.arg = &cfg.outfile, |
}, |
}, |
{ |
{ |
.name = "outform", |
.name = "outform", |
.argname = "format", |
.argname = "format", |
.desc = "Output format (DER or PEM (default))", |
.desc = "Output format (DER or PEM (default))", |
.type = OPTION_ARG_FORMAT, |
.type = OPTION_ARG_FORMAT, |
.opt.value = &dh_config.outformat, |
.opt.value = &cfg.outformat, |
}, |
}, |
{ |
{ |
.name = "text", |
.name = "text", |
.desc = "Print a text form of the DH parameters", |
.desc = "Print a text form of the DH parameters", |
.type = OPTION_FLAG, |
.type = OPTION_FLAG, |
.opt.flag = &dh_config.text, |
.opt.flag = &cfg.text, |
}, |
}, |
{ NULL }, |
{ NULL }, |
}; |
}; |
|
|
exit(1); |
exit(1); |
} |
} |
|
|
memset(&dh_config, 0, sizeof(dh_config)); |
memset(&cfg, 0, sizeof(cfg)); |
|
|
dh_config.informat = FORMAT_PEM; |
cfg.informat = FORMAT_PEM; |
dh_config.outformat = FORMAT_PEM; |
cfg.outformat = FORMAT_PEM; |
|
|
if (options_parse(argc, argv, dh_options, NULL, NULL) != 0) { |
if (options_parse(argc, argv, dh_options, NULL, NULL) != 0) { |
dh_usage(); |
dh_usage(); |
|
|
ERR_print_errors(bio_err); |
ERR_print_errors(bio_err); |
goto end; |
goto end; |
} |
} |
if (dh_config.infile == NULL) |
if (cfg.infile == NULL) |
BIO_set_fp(in, stdin, BIO_NOCLOSE); |
BIO_set_fp(in, stdin, BIO_NOCLOSE); |
else { |
else { |
if (BIO_read_filename(in, dh_config.infile) <= 0) { |
if (BIO_read_filename(in, cfg.infile) <= 0) { |
perror(dh_config.infile); |
perror(cfg.infile); |
goto end; |
goto end; |
} |
} |
} |
} |
if (dh_config.outfile == NULL) { |
if (cfg.outfile == NULL) { |
BIO_set_fp(out, stdout, BIO_NOCLOSE); |
BIO_set_fp(out, stdout, BIO_NOCLOSE); |
} else { |
} else { |
if (BIO_write_filename(out, dh_config.outfile) <= 0) { |
if (BIO_write_filename(out, cfg.outfile) <= 0) { |
perror(dh_config.outfile); |
perror(cfg.outfile); |
goto end; |
goto end; |
} |
} |
} |
} |
|
|
if (dh_config.informat == FORMAT_ASN1) |
if (cfg.informat == FORMAT_ASN1) |
dh = d2i_DHparams_bio(in, NULL); |
dh = d2i_DHparams_bio(in, NULL); |
else if (dh_config.informat == FORMAT_PEM) |
else if (cfg.informat == FORMAT_PEM) |
dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL); |
dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL); |
else { |
else { |
BIO_printf(bio_err, "bad input format specified\n"); |
BIO_printf(bio_err, "bad input format specified\n"); |
|
|
ERR_print_errors(bio_err); |
ERR_print_errors(bio_err); |
goto end; |
goto end; |
} |
} |
if (dh_config.text) { |
if (cfg.text) { |
DHparams_print(out, dh); |
DHparams_print(out, dh); |
} |
} |
if (dh_config.check) { |
if (cfg.check) { |
if (!DH_check(dh, &i)) { |
if (!DH_check(dh, &i)) { |
ERR_print_errors(bio_err); |
ERR_print_errors(bio_err); |
goto end; |
goto end; |
|
|
if (i == 0) |
if (i == 0) |
printf("DH parameters appear to be ok.\n"); |
printf("DH parameters appear to be ok.\n"); |
} |
} |
if (dh_config.C) { |
if (cfg.C) { |
unsigned char *data; |
unsigned char *data; |
int len, l, bits; |
int len, l, bits; |
|
|
|
|
printf("\treturn(dh);\n\t}\n"); |
printf("\treturn(dh);\n\t}\n"); |
free(data); |
free(data); |
} |
} |
if (!dh_config.noout) { |
if (!cfg.noout) { |
if (dh_config.outformat == FORMAT_ASN1) |
if (cfg.outformat == FORMAT_ASN1) |
i = i2d_DHparams_bio(out, dh); |
i = i2d_DHparams_bio(out, dh); |
else if (dh_config.outformat == FORMAT_PEM) |
else if (cfg.outformat == FORMAT_PEM) |
i = PEM_write_bio_DHparams(out, dh); |
i = PEM_write_bio_DHparams(out, dh); |
else { |
else { |
BIO_printf(bio_err, "bad output format specified for outfile\n"); |
BIO_printf(bio_err, "bad output format specified for outfile\n"); |