| 
									
										
										
										
											2016-05-18 02:18:30 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-02-18 22:57:13 +08:00
										 |  |  |  * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2000-03-04 06:18:19 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-12-06 20:00:26 +08:00
										 |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							| 
									
										
										
										
											2016-05-18 02:18:30 +08:00
										 |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							| 
									
										
										
										
											2000-03-04 06:18:19 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-01-22 21:58:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-01 02:08:23 +08:00
										 |  |  | #include <openssl/opensslconf.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-05 05:52:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <time.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include "apps.h"
 | 
					
						
							|  |  |  | #include "progs.h"
 | 
					
						
							|  |  |  | #include <openssl/bio.h>
 | 
					
						
							|  |  |  | #include <openssl/err.h>
 | 
					
						
							|  |  |  | #include <openssl/bn.h>
 | 
					
						
							| 
									
										
										
										
											2020-10-01 16:19:28 +08:00
										 |  |  | #include <openssl/dsa.h>
 | 
					
						
							|  |  |  | #include <openssl/dh.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-05 05:52:22 +08:00
										 |  |  | #include <openssl/x509.h>
 | 
					
						
							|  |  |  | #include <openssl/pem.h>
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  | #include <openssl/core_names.h>
 | 
					
						
							| 
									
										
										
										
											2020-10-01 16:19:28 +08:00
										 |  |  | #include <openssl/core_dispatch.h>
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  | #include <openssl/param_build.h>
 | 
					
						
							| 
									
										
										
										
											2020-10-01 16:19:28 +08:00
										 |  |  | #include <openssl/encoder.h>
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  | #include <openssl/decoder.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-05 05:52:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define DEFBITS 2048
 | 
					
						
							| 
									
										
										
										
											2000-01-22 21:58:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  | static EVP_PKEY *dsa_to_dh(EVP_PKEY *dh); | 
					
						
							| 
									
										
										
										
											2020-03-03 15:38:39 +08:00
										 |  |  | static int gendh_cb(EVP_PKEY_CTX *ctx); | 
					
						
							| 
									
										
										
										
											2000-01-22 21:58:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  | typedef enum OPTION_choice { | 
					
						
							|  |  |  |     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, | 
					
						
							|  |  |  |     OPT_INFORM, OPT_OUTFORM, OPT_IN, OPT_OUT, | 
					
						
							|  |  |  |     OPT_ENGINE, OPT_CHECK, OPT_TEXT, OPT_NOOUT, | 
					
						
							| 
									
										
										
										
											2020-11-12 07:03:38 +08:00
										 |  |  |     OPT_DSAPARAM, OPT_2, OPT_3, OPT_5, | 
					
						
							| 
									
										
										
										
											2020-02-25 12:29:30 +08:00
										 |  |  |     OPT_R_ENUM, OPT_PROV_ENUM | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  | } OPTION_CHOICE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-13 21:07:50 +08:00
										 |  |  | const OPTIONS dhparam_options[] = { | 
					
						
							| 
									
										
										
										
											2019-09-20 09:33:17 +08:00
										 |  |  |     {OPT_HELP_STR, 1, '-', "Usage: %s [options] [numbits]\n"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     OPT_SECTION("General"), | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {"help", OPT_HELP, '-', "Display this summary"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     {"check", OPT_CHECK, '-', "Check the DH parameters"}, | 
					
						
							| 
									
										
										
										
											2020-10-20 11:32:26 +08:00
										 |  |  | #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_DEPRECATED_3_0)
 | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     {"dsaparam", OPT_DSAPARAM, '-', | 
					
						
							|  |  |  |      "Read or generate DSA parameters, convert to DH"}, | 
					
						
							| 
									
										
										
										
											2020-10-20 11:32:26 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-03-05 05:52:22 +08:00
										 |  |  | #ifndef OPENSSL_NO_ENGINE
 | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     {"engine", OPT_ENGINE, 's', "Use engine e, possibly a hardware device"}, | 
					
						
							| 
									
										
										
										
											2020-03-05 05:52:22 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     OPT_SECTION("Input"), | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {"in", OPT_IN, '<', "Input file"}, | 
					
						
							|  |  |  |     {"inform", OPT_INFORM, 'F', "Input format, DER or PEM"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     OPT_SECTION("Output"), | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {"out", OPT_OUT, '>', "Output file"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     {"outform", OPT_OUTFORM, 'F', "Output format, DER or PEM"}, | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {"text", OPT_TEXT, '-', "Print a text form of the DH parameters"}, | 
					
						
							| 
									
										
										
										
											2016-03-21 04:14:10 +08:00
										 |  |  |     {"noout", OPT_NOOUT, '-', "Don't output any DH parameters"}, | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {"2", OPT_2, '-', "Generate parameters using 2 as the generator value"}, | 
					
						
							| 
									
										
										
										
											2019-07-10 21:52:36 +08:00
										 |  |  |     {"3", OPT_3, '-', "Generate parameters using 3 as the generator value"}, | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {"5", OPT_5, '-', "Generate parameters using 5 as the generator value"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     OPT_R_OPTIONS, | 
					
						
							| 
									
										
										
										
											2020-02-25 12:29:30 +08:00
										 |  |  |     OPT_PROV_OPTIONS, | 
					
						
							| 
									
										
										
										
											2019-09-20 09:33:17 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     OPT_PARAMETERS(), | 
					
						
							|  |  |  |     {"numbits", 0, 0, "Number of bits if generating parameters (optional)"}, | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {NULL} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int dhparam_main(int argc, char **argv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     BIO *in = NULL, *out = NULL; | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |     EVP_PKEY *pkey = NULL, *tmppkey = NULL; | 
					
						
							| 
									
										
										
										
											2020-03-03 15:38:39 +08:00
										 |  |  |     EVP_PKEY_CTX *ctx = NULL; | 
					
						
							| 
									
										
										
										
											2017-07-05 22:58:48 +08:00
										 |  |  |     char *infile = NULL, *outfile = NULL, *prog; | 
					
						
							| 
									
										
										
										
											2016-09-29 05:39:18 +08:00
										 |  |  |     ENGINE *e = NULL; | 
					
						
							| 
									
										
										
										
											2016-03-19 01:43:58 +08:00
										 |  |  |     int dsaparam = 0; | 
					
						
							| 
									
										
										
										
											2020-10-01 16:19:28 +08:00
										 |  |  |     int text = 0, ret = 1, num = 0, g = 0; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     int informat = FORMAT_PEM, outformat = FORMAT_PEM, check = 0, noout = 0; | 
					
						
							|  |  |  |     OPTION_CHOICE o; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     prog = opt_init(argc, argv, dhparam_options); | 
					
						
							|  |  |  |     while ((o = opt_next()) != OPT_EOF) { | 
					
						
							|  |  |  |         switch (o) { | 
					
						
							|  |  |  |         case OPT_EOF: | 
					
						
							|  |  |  |         case OPT_ERR: | 
					
						
							|  |  |  |  opthelp: | 
					
						
							|  |  |  |             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         case OPT_HELP: | 
					
						
							|  |  |  |             opt_help(dhparam_options); | 
					
						
							|  |  |  |             ret = 0; | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         case OPT_INFORM: | 
					
						
							|  |  |  |             if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat)) | 
					
						
							|  |  |  |                 goto opthelp; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_OUTFORM: | 
					
						
							|  |  |  |             if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat)) | 
					
						
							|  |  |  |                 goto opthelp; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_IN: | 
					
						
							|  |  |  |             infile = opt_arg(); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_OUT: | 
					
						
							|  |  |  |             outfile = opt_arg(); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_ENGINE: | 
					
						
							| 
									
										
										
										
											2016-09-29 05:39:18 +08:00
										 |  |  |             e = setup_engine(opt_arg(), 0); | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_CHECK: | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             check = 1; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_TEXT: | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             text = 1; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_DSAPARAM: | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             dsaparam = 1; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_2: | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             g = 2; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							| 
									
										
										
										
											2019-07-10 21:52:36 +08:00
										 |  |  |         case OPT_3: | 
					
						
							|  |  |  |             g = 3; | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |         case OPT_5: | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             g = 5; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_NOOUT: | 
					
						
							|  |  |  |             noout = 1; | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2017-07-05 22:58:48 +08:00
										 |  |  |         case OPT_R_CASES: | 
					
						
							|  |  |  |             if (!opt_rand(o)) | 
					
						
							|  |  |  |                 goto end; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							| 
									
										
										
										
											2020-02-25 12:29:30 +08:00
										 |  |  |         case OPT_PROV_CASES: | 
					
						
							|  |  |  |             if (!opt_provider(o)) | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-29 05:12:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* One optional argument, bitsize to generate. */ | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     argc = opt_num_rest(); | 
					
						
							|  |  |  |     argv = opt_rest(); | 
					
						
							| 
									
										
										
										
											2020-11-29 05:12:58 +08:00
										 |  |  |     if (argc == 1) { | 
					
						
							|  |  |  |         if (!opt_int(argv[0], &num) || num <= 0) | 
					
						
							|  |  |  |             goto opthelp; | 
					
						
							|  |  |  |     } else if (argc != 0) { | 
					
						
							|  |  |  |         goto opthelp; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-04-03 18:53:51 +08:00
										 |  |  |     if (!app_RAND_load()) | 
					
						
							|  |  |  |         goto end; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (g && !num) | 
					
						
							|  |  |  |         num = DEFBITS; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     if (dsaparam && g) { | 
					
						
							|  |  |  |         BIO_printf(bio_err, | 
					
						
							| 
									
										
										
										
											2020-06-06 03:40:28 +08:00
										 |  |  |                    "Error, generator may not be chosen for DSA parameters\n"); | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |         goto end; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-04-23 16:26:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     out = bio_open_default(outfile, 'w', outformat); | 
					
						
							|  |  |  |     if (out == NULL) | 
					
						
							|  |  |  |         goto end; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     /* DH parameters */ | 
					
						
							|  |  |  |     if (num && !g) | 
					
						
							|  |  |  |         g = 2; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (num) { | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |         const char *alg = dsaparam ? "DSA" : "DH"; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |         ctx = EVP_PKEY_CTX_new_from_name(NULL, alg, NULL); | 
					
						
							|  |  |  |         if (ctx == NULL) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             BIO_printf(bio_err, | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |                         "Error, %s param generation context allocation failed\n", | 
					
						
							|  |  |  |                         alg); | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         EVP_PKEY_CTX_set_cb(ctx, gendh_cb); | 
					
						
							|  |  |  |         EVP_PKEY_CTX_set_app_data(ctx, bio_err); | 
					
						
							|  |  |  |         BIO_printf(bio_err, | 
					
						
							|  |  |  |                     "Generating %s parameters, %d bit long %sprime\n", | 
					
						
							|  |  |  |                     alg, num, dsaparam ? "" : "safe "); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |         if (!EVP_PKEY_paramgen_init(ctx)) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             BIO_printf(bio_err, | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |                         "Error, unable to initialise %s parameters\n", | 
					
						
							|  |  |  |                         alg); | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (dsaparam) { | 
					
						
							|  |  |  |             if (!EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, num)) { | 
					
						
							|  |  |  |                 BIO_printf(bio_err, "Error, unable to set DSA prime length\n"); | 
					
						
							| 
									
										
										
										
											2020-03-03 15:38:39 +08:00
										 |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2020-03-03 15:38:39 +08:00
										 |  |  |             if (!EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, num)) { | 
					
						
							|  |  |  |                 BIO_printf(bio_err, "Error, unable to set DH prime length\n"); | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |             if (!EVP_PKEY_CTX_set_dh_paramgen_generator(ctx, g)) { | 
					
						
							|  |  |  |                 BIO_printf(bio_err, "Error, unable to set generator\n"); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (!EVP_PKEY_paramgen(ctx, &tmppkey)) { | 
					
						
							|  |  |  |             BIO_printf(bio_err, "Error, %s generation failed\n", alg); | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         EVP_PKEY_CTX_free(ctx); | 
					
						
							|  |  |  |         ctx = NULL; | 
					
						
							|  |  |  |         if (dsaparam) { | 
					
						
							|  |  |  |             pkey = dsa_to_dh(tmppkey); | 
					
						
							|  |  |  |             if (pkey == NULL) | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             EVP_PKEY_free(tmppkey); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             pkey = tmppkey; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         tmppkey = NULL; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |         OSSL_DECODER_CTX *decoderctx = NULL; | 
					
						
							|  |  |  |         const char *keytype = "DH"; | 
					
						
							|  |  |  |         int done; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 18:49:06 +08:00
										 |  |  |         in = bio_open_default(infile, 'r', informat); | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |         if (in == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             goto end; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |         do { | 
					
						
							|  |  |  |             /*
 | 
					
						
							|  |  |  |              * We assume we're done unless we explicitly want to retry and set | 
					
						
							|  |  |  |              * this to 0 below. | 
					
						
							|  |  |  |              */ | 
					
						
							|  |  |  |             done = 1; | 
					
						
							|  |  |  |             /*
 | 
					
						
							|  |  |  |             * We set NULL for the keytype to allow any key type. We don't know | 
					
						
							|  |  |  |             * if we're going to get DH or DHX (or DSA in the event of dsaparam). | 
					
						
							|  |  |  |             * We check that we got one of those key types afterwards. | 
					
						
							|  |  |  |             */ | 
					
						
							|  |  |  |             decoderctx | 
					
						
							| 
									
										
										
										
											2021-02-11 23:57:37 +08:00
										 |  |  |                 = OSSL_DECODER_CTX_new_for_pkey(&tmppkey, | 
					
						
							|  |  |  |                                                 (informat == FORMAT_ASN1) | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |                                                     ? "DER" : "PEM", | 
					
						
							| 
									
										
										
										
											2021-02-11 23:57:37 +08:00
										 |  |  |                                                 NULL, | 
					
						
							|  |  |  |                                                 (informat == FORMAT_ASN1) | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |                                                     ? keytype : NULL, | 
					
						
							| 
									
										
										
										
											2021-02-11 23:57:37 +08:00
										 |  |  |                                                 OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS, | 
					
						
							|  |  |  |                                                 NULL, NULL); | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (decoderctx != NULL | 
					
						
							|  |  |  |                     && !OSSL_DECODER_from_bio(decoderctx, in) | 
					
						
							|  |  |  |                     && informat == FORMAT_ASN1 | 
					
						
							|  |  |  |                     && strcmp(keytype, "DH") == 0) { | 
					
						
							|  |  |  |                 /*
 | 
					
						
							|  |  |  |                 * When reading DER we explicitly state the expected keytype | 
					
						
							|  |  |  |                 * because, unlike PEM, there is no header to declare what | 
					
						
							|  |  |  |                 * the contents of the DER file are. The decoders just try | 
					
						
							|  |  |  |                 * and guess. Unfortunately with DHX key types they may guess | 
					
						
							|  |  |  |                 * wrong and think we have a DSA keytype. Therefore we try | 
					
						
							|  |  |  |                 * both DH and DHX sequentially. | 
					
						
							|  |  |  |                 */ | 
					
						
							|  |  |  |                 keytype = "DHX"; | 
					
						
							|  |  |  |                 /*
 | 
					
						
							|  |  |  |                     * BIO_reset() returns 0 for success for file BIOs only!!! | 
					
						
							|  |  |  |                     * This won't work for stdin (and never has done) | 
					
						
							|  |  |  |                     * TODO: We should fix this at some point | 
					
						
							|  |  |  |                     */ | 
					
						
							|  |  |  |                 if (BIO_reset(in) == 0) | 
					
						
							|  |  |  |                     done = 0; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             OSSL_DECODER_CTX_free(decoderctx); | 
					
						
							|  |  |  |         } while (!done); | 
					
						
							|  |  |  |         if (tmppkey == NULL) { | 
					
						
							|  |  |  |             BIO_printf(bio_err, "Error, unable to load parameters\n"); | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |         if (dsaparam) { | 
					
						
							|  |  |  |             if (!EVP_PKEY_is_a(tmppkey, "DSA")) { | 
					
						
							| 
									
										
										
										
											2020-06-06 03:40:28 +08:00
										 |  |  |                 BIO_printf(bio_err, "Error, unable to load DSA parameters\n"); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |             pkey = dsa_to_dh(tmppkey); | 
					
						
							|  |  |  |             if (pkey == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                 goto end; | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             if (!EVP_PKEY_is_a(tmppkey, "DH") | 
					
						
							|  |  |  |                     && !EVP_PKEY_is_a(tmppkey, "DHX")) { | 
					
						
							| 
									
										
										
										
											2020-06-06 03:40:28 +08:00
										 |  |  |                 BIO_printf(bio_err, "Error, unable to load DH parameters\n"); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |             pkey = tmppkey; | 
					
						
							|  |  |  |             tmppkey = NULL; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-03 15:38:39 +08:00
										 |  |  |     if (text) | 
					
						
							|  |  |  |         EVP_PKEY_print_params(out, pkey, 4, NULL); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (check) { | 
					
						
							| 
									
										
										
										
											2020-10-01 16:19:28 +08:00
										 |  |  |         ctx = EVP_PKEY_CTX_new_from_pkey(NULL, pkey, NULL); | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |         if (ctx == NULL) { | 
					
						
							|  |  |  |             BIO_printf(bio_err, "Error, failed to check DH parameters\n"); | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-10-01 16:19:28 +08:00
										 |  |  |         if (!EVP_PKEY_param_check(ctx)) { | 
					
						
							| 
									
										
										
										
											2020-06-06 03:40:28 +08:00
										 |  |  |             BIO_printf(bio_err, "Error, invalid parameters generated\n"); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             goto end; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-03-03 15:38:39 +08:00
										 |  |  |         BIO_printf(bio_err, "DH parameters appear to be ok.\n"); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!noout) { | 
					
						
							| 
									
										
										
										
											2020-10-01 16:19:28 +08:00
										 |  |  |         OSSL_ENCODER_CTX *ectx = | 
					
						
							| 
									
										
										
										
											2021-02-11 23:57:37 +08:00
										 |  |  |             OSSL_ENCODER_CTX_new_for_pkey(pkey, | 
					
						
							|  |  |  |                                           OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS, | 
					
						
							|  |  |  |                                           outformat == FORMAT_ASN1 | 
					
						
							|  |  |  |                                               ? "DER" : "PEM", | 
					
						
							|  |  |  |                                           NULL, NULL); | 
					
						
							| 
									
										
										
										
											2020-10-01 16:19:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (ectx == NULL || !OSSL_ENCODER_to_bio(ectx, out)) { | 
					
						
							|  |  |  |             OSSL_ENCODER_CTX_free(ectx); | 
					
						
							| 
									
										
										
										
											2020-06-06 03:40:28 +08:00
										 |  |  |             BIO_printf(bio_err, "Error, unable to write DH parameters\n"); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             goto end; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-10-01 16:19:28 +08:00
										 |  |  |         OSSL_ENCODER_CTX_free(ectx); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     ret = 0; | 
					
						
							|  |  |  |  end: | 
					
						
							| 
									
										
										
										
											2020-06-06 03:40:28 +08:00
										 |  |  |     if (ret != 0) | 
					
						
							|  |  |  |         ERR_print_errors(bio_err); | 
					
						
							| 
									
										
										
										
											2015-03-25 23:31:18 +08:00
										 |  |  |     BIO_free(in); | 
					
						
							|  |  |  |     BIO_free_all(out); | 
					
						
							| 
									
										
										
										
											2020-03-03 15:38:39 +08:00
										 |  |  |     EVP_PKEY_free(pkey); | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |     EVP_PKEY_free(tmppkey); | 
					
						
							| 
									
										
										
										
											2020-03-03 15:38:39 +08:00
										 |  |  |     EVP_PKEY_CTX_free(ctx); | 
					
						
							| 
									
										
										
										
											2016-09-29 05:39:18 +08:00
										 |  |  |     release_engine(e); | 
					
						
							| 
									
										
										
										
											2017-10-17 22:04:09 +08:00
										 |  |  |     return ret; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2000-01-22 21:58:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Historically we had the low level call DSA_dup_DH() to do this. | 
					
						
							|  |  |  |  * That is now deprecated with no replacement. Since we still need to do this | 
					
						
							|  |  |  |  * for backwards compatibility reasons, we do it "manually". | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static EVP_PKEY *dsa_to_dh(EVP_PKEY *dh) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |     OSSL_PARAM_BLD *tmpl = NULL; | 
					
						
							|  |  |  |     OSSL_PARAM *params = NULL; | 
					
						
							|  |  |  |     BIGNUM *bn_p = NULL, *bn_q = NULL, *bn_g = NULL; | 
					
						
							|  |  |  |     EVP_PKEY_CTX *ctx = NULL; | 
					
						
							|  |  |  |     EVP_PKEY *pkey = NULL; | 
					
						
							| 
									
										
										
										
											2018-07-30 05:34:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |     if (!EVP_PKEY_get_bn_param(dh, OSSL_PKEY_PARAM_FFC_P, &bn_p) | 
					
						
							|  |  |  |             || !EVP_PKEY_get_bn_param(dh, OSSL_PKEY_PARAM_FFC_Q, &bn_q) | 
					
						
							|  |  |  |             || !EVP_PKEY_get_bn_param(dh, OSSL_PKEY_PARAM_FFC_G, &bn_g)) { | 
					
						
							|  |  |  |         BIO_printf(bio_err, "Error, failed to set DH parameters\n"); | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-03 15:38:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |     if ((tmpl = OSSL_PARAM_BLD_new()) == NULL | 
					
						
							|  |  |  |             || !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_P, | 
					
						
							|  |  |  |                                         bn_p) | 
					
						
							|  |  |  |             || !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_Q, | 
					
						
							|  |  |  |                                         bn_q) | 
					
						
							|  |  |  |             || !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_G, | 
					
						
							|  |  |  |                                         bn_g) | 
					
						
							|  |  |  |             || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) { | 
					
						
							|  |  |  |         BIO_printf(bio_err, "Error, failed to set DH parameters\n"); | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ctx = EVP_PKEY_CTX_new_from_name(NULL, "DHX", NULL); | 
					
						
							|  |  |  |     if (ctx == NULL | 
					
						
							| 
									
										
										
										
											2021-02-05 11:55:50 +08:00
										 |  |  |             || !EVP_PKEY_fromdata_init(ctx) | 
					
						
							|  |  |  |             || !EVP_PKEY_fromdata(ctx, &pkey, EVP_PKEY_KEY_PARAMETERS, params)) { | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |         BIO_printf(bio_err, "Error, failed to set DH parameters\n"); | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  err: | 
					
						
							|  |  |  |     EVP_PKEY_CTX_free(ctx); | 
					
						
							| 
									
										
										
										
											2021-04-07 11:45:19 +08:00
										 |  |  |     OSSL_PARAM_free(params); | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |     OSSL_PARAM_BLD_free(tmpl); | 
					
						
							|  |  |  |     BN_free(bn_p); | 
					
						
							|  |  |  |     BN_free(bn_q); | 
					
						
							|  |  |  |     BN_free(bn_g); | 
					
						
							|  |  |  |     return pkey; | 
					
						
							| 
									
										
										
										
											2020-03-03 15:38:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int gendh_cb(EVP_PKEY_CTX *ctx) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-29 23:32:11 +08:00
										 |  |  |     int p = EVP_PKEY_CTX_get_keygen_info(ctx, 0); | 
					
						
							|  |  |  |     BIO *b = EVP_PKEY_CTX_get_app_data(ctx); | 
					
						
							|  |  |  |     static const char symbols[] = ".+*\n"; | 
					
						
							|  |  |  |     char c = (p >= 0 && (size_t)p < sizeof(symbols) - 1) ? symbols[p] : '?'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BIO_write(b, &c, 1); | 
					
						
							|  |  |  |     (void)BIO_flush(b); | 
					
						
							|  |  |  |     return 1; | 
					
						
							| 
									
										
										
										
											2020-03-03 15:38:39 +08:00
										 |  |  | } |