| 
									
										
										
										
											2008-11-06 02:39:08 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-09-05 15:35:49 +08:00
										 |  |  |  * Copyright 2006-2024 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +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
 | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "apps.h"
 | 
					
						
							| 
									
										
										
										
											2018-01-31 18:13:10 +08:00
										 |  |  | #include "progs.h"
 | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <openssl/err.h>
 | 
					
						
							|  |  |  | #include <openssl/pem.h>
 | 
					
						
							|  |  |  | #include <openssl/evp.h>
 | 
					
						
							| 
									
										
										
										
											2019-03-16 19:07:35 +08:00
										 |  |  | #include <sys/stat.h>
 | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  | #define KEY_NONE        0
 | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  | #define KEY_PRIVKEY     1
 | 
					
						
							|  |  |  | #define KEY_PUBKEY      2
 | 
					
						
							|  |  |  | #define KEY_CERT        3
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  | static EVP_PKEY *get_pkey(const char *kdfalg, | 
					
						
							|  |  |  |                           const char *keyfile, int keyform, int key_type, | 
					
						
							|  |  |  |                           char *passinarg, int pkey_op, ENGINE *e); | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  | static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize, | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  |                               int pkey_op, ENGINE *e, | 
					
						
							|  |  |  |                               const int engine_impl, int rawin, | 
					
						
							|  |  |  |                               EVP_PKEY *pkey /* ownership is passed to ctx */, | 
					
						
							|  |  |  |                               EVP_MD_CTX *mctx, const char *digestname, | 
					
						
							|  |  |  |                               const char *kemop, OSSL_LIB_CTX *libctx, const char *propq); | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  | static int setup_peer(EVP_PKEY_CTX *ctx, int peerform, const char *file, | 
					
						
							|  |  |  |                       ENGINE *e); | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  | static int do_keyop(EVP_PKEY_CTX *ctx, int pkey_op, | 
					
						
							| 
									
										
										
										
											2006-05-26 20:24:49 +08:00
										 |  |  |                     unsigned char *out, size_t *poutlen, | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |                     const unsigned char *in, size_t inlen, | 
					
						
							|  |  |  |                     unsigned char *secret, size_t *psecretlen); | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 04:26:32 +08:00
										 |  |  | static int do_raw_keyop(int pkey_op, EVP_MD_CTX *mctx, | 
					
						
							|  |  |  |                         EVP_PKEY *pkey, BIO *in, | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |                         int filesize, unsigned char *sig, int siglen, | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |                         unsigned char **out, size_t *poutlen); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-08 05:01:41 +08:00
										 |  |  | static int is_EdDSA(const EVP_PKEY *pkey) | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     if (pkey == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     return EVP_PKEY_is_a(pkey, "ED25519") | 
					
						
							|  |  |  |         || EVP_PKEY_is_a(pkey, "ED448"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-08 05:01:41 +08:00
										 |  |  | static int only_rawin(const EVP_PKEY *pkey) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return is_EdDSA(pkey); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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 { | 
					
						
							| 
									
										
										
										
											2021-05-01 21:29:00 +08:00
										 |  |  |     OPT_COMMON, | 
					
						
							| 
									
										
										
										
											2016-01-14 12:03:31 +08:00
										 |  |  |     OPT_ENGINE, OPT_ENGINE_IMPL, OPT_IN, OPT_OUT, | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |     OPT_PUBIN, OPT_CERTIN, OPT_ASN1PARSE, OPT_HEXDUMP, OPT_SIGN, | 
					
						
							|  |  |  |     OPT_VERIFY, OPT_VERIFYRECOVER, OPT_REV, OPT_ENCRYPT, OPT_DECRYPT, | 
					
						
							|  |  |  |     OPT_DERIVE, OPT_SIGFILE, OPT_INKEY, OPT_PEERKEY, OPT_PASSIN, | 
					
						
							| 
									
										
										
										
											2017-08-02 01:38:32 +08:00
										 |  |  |     OPT_PEERFORM, OPT_KEYFORM, OPT_PKEYOPT, OPT_PKEYOPT_PASSIN, OPT_KDF, | 
					
						
							| 
									
										
										
										
											2020-02-25 12:29:30 +08:00
										 |  |  |     OPT_KDFLEN, OPT_R_ENUM, OPT_PROV_ENUM, | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     OPT_DECAP, OPT_ENCAP, OPT_SECOUT, OPT_KEMOP, | 
					
						
							| 
									
										
										
										
											2020-07-23 15:40:40 +08:00
										 |  |  |     OPT_CONFIG, | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |     OPT_RAWIN, OPT_DIGEST | 
					
						
							| 
									
										
											  
											
												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 pkeyutl_options[] = { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | #ifndef OPENSSL_NO_ENGINE
 | 
					
						
							|  |  |  |     {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, | 
					
						
							|  |  |  |     {"engine_impl", OPT_ENGINE_IMPL, '-', | 
					
						
							|  |  |  |      "Also use engine given by -engine for crypto operations"}, | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-02-08 12:14:12 +08:00
										 |  |  |     {"sign", OPT_SIGN, '-', "Sign input data with private key"}, | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |     {"verify", OPT_VERIFY, '-', "Verify with public key"}, | 
					
						
							| 
									
										
										
										
											2016-02-08 12:14:12 +08:00
										 |  |  |     {"encrypt", OPT_ENCRYPT, '-', "Encrypt input data with public key"}, | 
					
						
							|  |  |  |     {"decrypt", OPT_DECRYPT, '-', "Decrypt input data with private key"}, | 
					
						
							| 
									
										
										
										
											2024-11-14 16:28:16 +08:00
										 |  |  |     {"derive", OPT_DERIVE, '-', "Derive shared secret from own and peer (EC)DH keys"}, | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     {"decap", OPT_DECAP, '-', "Decapsulate shared secret"}, | 
					
						
							|  |  |  |     {"encap", OPT_ENCAP, '-', "Encapsulate shared secret"}, | 
					
						
							| 
									
										
										
										
											2020-07-23 15:40:40 +08:00
										 |  |  |     OPT_CONFIG_OPTION, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     OPT_SECTION("Input"), | 
					
						
							|  |  |  |     {"in", OPT_IN, '<', "Input file - default stdin"}, | 
					
						
							| 
									
										
										
										
											2022-08-27 02:40:48 +08:00
										 |  |  |     {"inkey", OPT_INKEY, 's', "Input key, by default private key"}, | 
					
						
							|  |  |  |     {"pubin", OPT_PUBIN, '-', "Input key is a public key"}, | 
					
						
							| 
									
										
										
										
											2016-03-21 04:14:10 +08:00
										 |  |  |     {"passin", OPT_PASSIN, 's', "Input file pass phrase source"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     {"peerkey", OPT_PEERKEY, 's', "Peer key file used in key derivation"}, | 
					
						
							| 
									
										
										
										
											2020-05-06 19:51:50 +08:00
										 |  |  |     {"peerform", OPT_PEERFORM, 'E', "Peer key format (DER/PEM/P12/ENGINE)"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     {"certin", OPT_CERTIN, '-', "Input is a cert with a public key"}, | 
					
						
							|  |  |  |     {"rev", OPT_REV, '-', "Reverse the order of the input buffer"}, | 
					
						
							|  |  |  |     {"sigfile", OPT_SIGFILE, '<', "Signature file (verify operation only)"}, | 
					
						
							| 
									
										
										
										
											2020-05-06 19:51:50 +08:00
										 |  |  |     {"keyform", OPT_KEYFORM, 'E', "Private key format (ENGINE, other values ignored)"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     OPT_SECTION("Output"), | 
					
						
							|  |  |  |     {"out", OPT_OUT, '>', "Output file - default stdout"}, | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     {"secret", OPT_SECOUT, '>', "File to store secret on encapsulation"}, | 
					
						
							| 
									
										
										
										
											2024-10-31 03:37:38 +08:00
										 |  |  |     {"asn1parse", OPT_ASN1PARSE, '-', | 
					
						
							|  |  |  |      "parse the output as ASN.1 data to check its DER encoding and print errors"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     {"hexdump", OPT_HEXDUMP, '-', "Hex dump output"}, | 
					
						
							|  |  |  |     {"verifyrecover", OPT_VERIFYRECOVER, '-', | 
					
						
							| 
									
										
										
										
											2024-10-31 03:37:38 +08:00
										 |  |  |      "Verify RSA signature, recovering original signature input data"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     OPT_SECTION("Signing/Derivation/Encapsulation"), | 
					
						
							| 
									
										
										
										
											2024-10-30 02:21:14 +08:00
										 |  |  |     {"rawin", OPT_RAWIN, '-', | 
					
						
							|  |  |  |      "Indicate that the signature/verification input data is not yet hashed"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     {"digest", OPT_DIGEST, 's', | 
					
						
							| 
									
										
										
										
											2024-10-30 02:21:14 +08:00
										 |  |  |      "The digest algorithm to use for signing/verifying raw input data. Implies -rawin"}, | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |     {"pkeyopt", OPT_PKEYOPT, 's', "Public key options as opt:value"}, | 
					
						
							| 
									
										
										
										
											2017-08-02 01:38:32 +08:00
										 |  |  |     {"pkeyopt_passin", OPT_PKEYOPT_PASSIN, 's', | 
					
						
							|  |  |  |      "Public key option that is read as a passphrase argument opt:passphrase"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     {"kdf", OPT_KDF, 's', "Use KDF algorithm"}, | 
					
						
							|  |  |  |     {"kdflen", OPT_KDFLEN, 'p', "KDF algorithm output length"}, | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     {"kemop", OPT_KEMOP, 's', "KEM operation specific to the key algorithm"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-05 22:58:48 +08:00
										 |  |  |     OPT_R_OPTIONS, | 
					
						
							| 
									
										
										
										
											2020-02-25 12:29:30 +08:00
										 |  |  |     OPT_PROV_OPTIONS, | 
					
						
							| 
									
										
											  
											
												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} | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +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
										 |  |  | int pkeyutl_main(int argc, char **argv) | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-23 15:40:40 +08:00
										 |  |  |     CONF *conf = NULL; | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     BIO *in = NULL, *out = NULL, *secout = NULL; | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  |     ENGINE *e = NULL; | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |     EVP_PKEY_CTX *ctx = NULL; | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |     EVP_PKEY *pkey = NULL; | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     char *infile = NULL, *outfile = NULL, *secoutfile = NULL, *sigfile = NULL, *passinarg = NULL; | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |     char hexdump = 0, asn1parse = 0, rev = 0, *prog; | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     unsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL, *secret = NULL; | 
					
						
							| 
									
										
											  
											
												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 o; | 
					
						
							| 
									
										
										
										
											2021-04-30 22:57:53 +08:00
										 |  |  |     int buf_inlen = 0, siglen = -1; | 
					
						
							|  |  |  |     int keyform = FORMAT_UNDEF, peerform = FORMAT_UNDEF; | 
					
						
							| 
									
										
											  
											
												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 keysize = -1, pkey_op = EVP_PKEY_OP_SIGN, key_type = KEY_PRIVKEY; | 
					
						
							| 
									
										
										
										
											2016-01-14 12:03:31 +08:00
										 |  |  |     int engine_impl = 0; | 
					
						
							| 
									
										
										
										
											2006-04-09 06:25:47 +08:00
										 |  |  |     int ret = 1, rv = -1; | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     size_t buf_outlen = 0, secretlen = 0; | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  |     const char *inkey = NULL; | 
					
						
							|  |  |  |     const char *peerkey = NULL; | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     const char *kdfalg = NULL, *digestname = NULL, *kemop = NULL; | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  |     int kdflen = 0; | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  |     STACK_OF(OPENSSL_STRING) *pkeyopts = NULL; | 
					
						
							| 
									
										
										
										
											2017-08-02 01:38:32 +08:00
										 |  |  |     STACK_OF(OPENSSL_STRING) *pkeyopts_passin = NULL; | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |     int rawin = 0; | 
					
						
							| 
									
										
										
										
											2021-01-11 04:26:32 +08:00
										 |  |  |     EVP_MD_CTX *mctx = NULL; | 
					
						
							| 
									
										
										
										
											2021-02-18 05:15:27 +08:00
										 |  |  |     EVP_MD *md = NULL; | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |     int filesize = -1; | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     OSSL_LIB_CTX *libctx = app_get0_libctx(); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +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
										 |  |  |     prog = opt_init(argc, argv, pkeyutl_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(pkeyutl_options); | 
					
						
							|  |  |  |             ret = 0; | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         case OPT_IN: | 
					
						
							|  |  |  |             infile = opt_arg(); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_OUT: | 
					
						
							|  |  |  |             outfile = opt_arg(); | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |         case OPT_SECOUT: | 
					
						
							|  |  |  |             secoutfile = opt_arg(); | 
					
						
							|  |  |  |             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_SIGFILE: | 
					
						
							|  |  |  |             sigfile = opt_arg(); | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2016-01-14 12:03:31 +08:00
										 |  |  |         case OPT_ENGINE_IMPL: | 
					
						
							|  |  |  |             engine_impl = 1; | 
					
						
							|  |  |  |             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_INKEY: | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  |             inkey = opt_arg(); | 
					
						
							| 
									
										
											  
											
												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_PEERKEY: | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  |             peerkey = opt_arg(); | 
					
						
							| 
									
										
											  
											
												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_PASSIN: | 
					
						
							|  |  |  |             passinarg = opt_arg(); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_PEERFORM: | 
					
						
							| 
									
										
										
										
											2020-05-06 19:51:50 +08:00
										 |  |  |             if (!opt_format(opt_arg(), OPT_FMT_ANY, &peerform)) | 
					
						
							| 
									
										
											  
											
												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 opthelp; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_KEYFORM: | 
					
						
							| 
									
										
										
										
											2020-05-06 19:51:50 +08:00
										 |  |  |             if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyform)) | 
					
						
							| 
									
										
											  
											
												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 opthelp; | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2017-07-05 22:58:48 +08:00
										 |  |  |         case OPT_R_CASES: | 
					
						
							|  |  |  |             if (!opt_rand(o)) | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2020-07-23 15:40:40 +08:00
										 |  |  |         case OPT_CONFIG: | 
					
						
							|  |  |  |             conf = app_load_config_modules(opt_arg()); | 
					
						
							|  |  |  |             if (conf == NULL) | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             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
										 |  |  |         case OPT_ENGINE: | 
					
						
							|  |  |  |             e = setup_engine(opt_arg(), 0); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_PUBIN: | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |             key_type = KEY_PUBKEY; | 
					
						
							| 
									
										
											  
											
												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_CERTIN: | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |             key_type = KEY_CERT; | 
					
						
							| 
									
										
											  
											
												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_ASN1PARSE: | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |             asn1parse = 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_HEXDUMP: | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |             hexdump = 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_SIGN: | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |             pkey_op = EVP_PKEY_OP_SIGN; | 
					
						
							| 
									
										
											  
											
												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_VERIFY: | 
					
						
							| 
									
										
										
										
											2006-04-09 06:25:47 +08:00
										 |  |  |             pkey_op = EVP_PKEY_OP_VERIFY; | 
					
						
							| 
									
										
											  
											
												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_VERIFYRECOVER: | 
					
						
							| 
									
										
										
										
											2006-04-08 21:02:04 +08:00
										 |  |  |             pkey_op = EVP_PKEY_OP_VERIFYRECOVER; | 
					
						
							| 
									
										
											  
											
												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_ENCRYPT: | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |             pkey_op = EVP_PKEY_OP_ENCRYPT; | 
					
						
							| 
									
										
											  
											
												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_DECRYPT: | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |             pkey_op = EVP_PKEY_OP_DECRYPT; | 
					
						
							| 
									
										
											  
											
												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_DERIVE: | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  |             pkey_op = EVP_PKEY_OP_DERIVE; | 
					
						
							| 
									
										
											  
											
												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; | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |         case OPT_DECAP: | 
					
						
							|  |  |  |             pkey_op = EVP_PKEY_OP_DECAPSULATE; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_ENCAP: | 
					
						
							|  |  |  |             pkey_op = EVP_PKEY_OP_ENCAPSULATE; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_KEMOP: | 
					
						
							|  |  |  |             kemop = opt_arg(); | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  |         case OPT_KDF: | 
					
						
							|  |  |  |             pkey_op = EVP_PKEY_OP_DERIVE; | 
					
						
							|  |  |  |             key_type = KEY_NONE; | 
					
						
							|  |  |  |             kdfalg = opt_arg(); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_KDFLEN: | 
					
						
							|  |  |  |             kdflen = atoi(opt_arg()); | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  |         case OPT_REV: | 
					
						
							|  |  |  |             rev = 1; | 
					
						
							|  |  |  |             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_PKEYOPT: | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  |             if ((pkeyopts == NULL && | 
					
						
							|  |  |  |                  (pkeyopts = sk_OPENSSL_STRING_new_null()) == NULL) || | 
					
						
							| 
									
										
										
										
											2016-03-02 01:22:51 +08:00
										 |  |  |                 sk_OPENSSL_STRING_push(pkeyopts, opt_arg()) == 0) { | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  |                 BIO_puts(bio_err, "out of memory\n"); | 
					
						
							| 
									
										
										
										
											2006-04-09 20:42:09 +08:00
										 |  |  |                 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; | 
					
						
							| 
									
										
										
										
											2017-08-02 01:38:32 +08:00
										 |  |  |         case OPT_PKEYOPT_PASSIN: | 
					
						
							|  |  |  |             if ((pkeyopts_passin == NULL && | 
					
						
							|  |  |  |                  (pkeyopts_passin = sk_OPENSSL_STRING_new_null()) == NULL) || | 
					
						
							|  |  |  |                 sk_OPENSSL_STRING_push(pkeyopts_passin, opt_arg()) == 0) { | 
					
						
							|  |  |  |                 BIO_puts(bio_err, "out of memory\n"); | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |         case OPT_RAWIN: | 
					
						
							|  |  |  |             rawin = 1; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_DIGEST: | 
					
						
							| 
									
										
										
										
											2021-02-09 03:03:35 +08:00
										 |  |  |             digestname = opt_arg(); | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |             break; | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-29 05:12:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* No extra arguments. */ | 
					
						
							| 
									
										
										
										
											2021-08-27 21:33:18 +08:00
										 |  |  |     if (!opt_check_rest_arg(NULL)) | 
					
						
							| 
									
										
										
										
											2016-02-15 03:45:02 +08:00
										 |  |  |         goto opthelp; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-03 18:53:51 +08:00
										 |  |  |     if (!app_RAND_load()) | 
					
						
							|  |  |  |         goto end; | 
					
						
							| 
									
										
										
										
											2021-02-09 02:45:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-30 02:21:14 +08:00
										 |  |  |     if (digestname != NULL) | 
					
						
							|  |  |  |         rawin = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  |     if (kdfalg != NULL) { | 
					
						
							| 
									
										
										
										
											2017-07-22 04:19:35 +08:00
										 |  |  |         if (kdflen == 0) { | 
					
						
							|  |  |  |             BIO_printf(bio_err, | 
					
						
							|  |  |  |                        "%s: no KDF length given (-kdflen parameter).\n", prog); | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  |             goto opthelp; | 
					
						
							| 
									
										
										
										
											2017-07-22 04:19:35 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } else if (inkey == NULL) { | 
					
						
							|  |  |  |         BIO_printf(bio_err, | 
					
						
							|  |  |  |                    "%s: no private key given (-inkey parameter).\n", prog); | 
					
						
							|  |  |  |         goto opthelp; | 
					
						
							|  |  |  |     } else if (peerkey != NULL && pkey_op != EVP_PKEY_OP_DERIVE) { | 
					
						
							|  |  |  |         BIO_printf(bio_err, | 
					
						
							| 
									
										
										
										
											2024-11-14 16:28:16 +08:00
										 |  |  |                    "%s: -peerkey option not allowed without -derive.\n", prog); | 
					
						
							|  |  |  |         goto opthelp; | 
					
						
							|  |  |  |     } else if (peerkey == NULL && pkey_op == EVP_PKEY_OP_DERIVE) { | 
					
						
							|  |  |  |         BIO_printf(bio_err, | 
					
						
							|  |  |  |                    "%s: missing -peerkey option for -derive operation.\n", prog); | 
					
						
							| 
									
										
											  
											
												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 opthelp; | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-01-11 04:26:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  |     pkey = get_pkey(kdfalg, inkey, keyform, key_type, passinarg, pkey_op, e); | 
					
						
							| 
									
										
										
										
											2024-11-08 05:01:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (pkey_op == EVP_PKEY_OP_VERIFYRECOVER && !EVP_PKEY_is_a(pkey, "RSA")) { | 
					
						
							|  |  |  |         BIO_printf(bio_err, "%s: -verifyrecover can be used only with RSA\n", prog); | 
					
						
							|  |  |  |         goto end; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  |     if (pkey_op == EVP_PKEY_OP_SIGN || pkey_op == EVP_PKEY_OP_VERIFY) { | 
					
						
							|  |  |  |         if (only_rawin(pkey)) { | 
					
						
							| 
									
										
										
										
											2024-11-08 05:01:41 +08:00
										 |  |  |             if (is_EdDSA(pkey) && digestname != NULL) { | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  |                 BIO_printf(bio_err, | 
					
						
							|  |  |  |                            "%s: -digest (prehash) is not supported with EdDSA\n", prog); | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             rawin = 1; /* implied for Ed25519(ph) and Ed448(ph) and maybe others in the future */ | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-10-30 02:21:14 +08:00
										 |  |  |     } else if (digestname != NULL || rawin) { | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  |         BIO_printf(bio_err, | 
					
						
							| 
									
										
										
										
											2024-10-30 02:21:14 +08:00
										 |  |  |                    "%s: -digest and -rawin can only be used with -sign or -verify\n", prog); | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  |         goto opthelp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (rawin && rev) { | 
					
						
							|  |  |  |         BIO_printf(bio_err, "%s: -rev cannot be used with raw input\n", prog); | 
					
						
							|  |  |  |         goto opthelp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 04:26:32 +08:00
										 |  |  |     if (rawin) { | 
					
						
							|  |  |  |         if ((mctx = EVP_MD_CTX_new()) == NULL) { | 
					
						
							|  |  |  |             BIO_printf(bio_err, "Error: out of memory\n"); | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  |     ctx = init_ctx(kdfalg, &keysize, pkey_op, e, engine_impl, rawin, pkey, | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |                    mctx, digestname, kemop, libctx, app_get0_propq()); | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  |     if (ctx == NULL) { | 
					
						
							|  |  |  |         BIO_printf(bio_err, "%s: Error initializing context\n", prog); | 
					
						
							|  |  |  |         goto end; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (peerkey != NULL && !setup_peer(ctx, peerform, peerkey, e)) { | 
					
						
							|  |  |  |         BIO_printf(bio_err, "%s: Error setting up peer key\n", prog); | 
					
						
							|  |  |  |         goto end; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (pkeyopts != NULL) { | 
					
						
							|  |  |  |         int num = sk_OPENSSL_STRING_num(pkeyopts); | 
					
						
							|  |  |  |         int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (i = 0; i < num; ++i) { | 
					
						
							|  |  |  |             const char *opt = sk_OPENSSL_STRING_value(pkeyopts, i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (pkey_ctrl_string(ctx, opt) <= 0) { | 
					
						
							| 
									
										
										
										
											2017-07-22 04:19:35 +08:00
										 |  |  |                 BIO_printf(bio_err, "%s: Can't set parameter \"%s\":\n", | 
					
						
							|  |  |  |                            prog, opt); | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-08-02 01:38:32 +08:00
										 |  |  |     if (pkeyopts_passin != NULL) { | 
					
						
							|  |  |  |         int num = sk_OPENSSL_STRING_num(pkeyopts_passin); | 
					
						
							|  |  |  |         int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (i = 0; i < num; i++) { | 
					
						
							|  |  |  |             char *opt = sk_OPENSSL_STRING_value(pkeyopts_passin, i); | 
					
						
							|  |  |  |             char *passin = strchr(opt, ':'); | 
					
						
							|  |  |  |             char *passwd; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (passin == NULL) { | 
					
						
							|  |  |  |                 /* Get password interactively */ | 
					
						
							|  |  |  |                 char passwd_buf[4096]; | 
					
						
							| 
									
										
										
										
											2020-08-19 11:40:22 +08:00
										 |  |  |                 int r; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-02 01:38:32 +08:00
										 |  |  |                 BIO_snprintf(passwd_buf, sizeof(passwd_buf), "Enter %s: ", opt); | 
					
						
							| 
									
										
										
										
											2020-08-19 11:40:22 +08:00
										 |  |  |                 r = EVP_read_pw_string(passwd_buf, sizeof(passwd_buf) - 1, | 
					
						
							|  |  |  |                                        passwd_buf, 0); | 
					
						
							|  |  |  |                 if (r < 0) { | 
					
						
							|  |  |  |                     if (r == -2) | 
					
						
							|  |  |  |                         BIO_puts(bio_err, "user abort\n"); | 
					
						
							|  |  |  |                     else | 
					
						
							|  |  |  |                         BIO_puts(bio_err, "entry failed\n"); | 
					
						
							|  |  |  |                     goto end; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-08-02 01:38:32 +08:00
										 |  |  |                 passwd = OPENSSL_strdup(passwd_buf); | 
					
						
							|  |  |  |                 if (passwd == NULL) { | 
					
						
							|  |  |  |                     BIO_puts(bio_err, "out of memory\n"); | 
					
						
							|  |  |  |                     goto end; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  |                 /*
 | 
					
						
							|  |  |  |                  * Get password as a passin argument: First split option name | 
					
						
							|  |  |  |                  * and passphrase argument into two strings | 
					
						
							|  |  |  |                  */ | 
					
						
							| 
									
										
										
										
											2017-08-02 01:38:32 +08:00
										 |  |  |                 *passin = 0; | 
					
						
							|  |  |  |                 passin++; | 
					
						
							|  |  |  |                 if (app_passwd(passin, NULL, &passwd, NULL) == 0) { | 
					
						
							|  |  |  |                     BIO_printf(bio_err, "failed to get '%s'\n", opt); | 
					
						
							|  |  |  |                     goto end; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (EVP_PKEY_CTX_ctrl_str(ctx, opt, passwd) <= 0) { | 
					
						
							|  |  |  |                 BIO_printf(bio_err, "%s: Can't set parameter \"%s\":\n", | 
					
						
							|  |  |  |                            prog, opt); | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             OPENSSL_free(passwd); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  |     if (sigfile != NULL && (pkey_op != EVP_PKEY_OP_VERIFY)) { | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |         BIO_printf(bio_err, | 
					
						
							|  |  |  |                    "%s: Signature file specified for non verify\n", prog); | 
					
						
							| 
									
										
										
										
											2006-04-09 06:25:47 +08:00
										 |  |  |         goto end; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  |     if (sigfile == NULL && (pkey_op == EVP_PKEY_OP_VERIFY)) { | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |         BIO_printf(bio_err, | 
					
						
							|  |  |  |                    "%s: No signature file specified for verify\n", prog); | 
					
						
							| 
									
										
										
										
											2006-04-09 06:25:47 +08:00
										 |  |  |         goto end; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     if (pkey_op != EVP_PKEY_OP_DERIVE && pkey_op != EVP_PKEY_OP_ENCAPSULATE) { | 
					
						
							| 
									
										
										
										
											2015-09-04 18:49:06 +08:00
										 |  |  |         in = bio_open_default(infile, 'r', FORMAT_BINARY); | 
					
						
							| 
									
										
										
										
											2019-03-16 19:07:35 +08:00
										 |  |  |         if (infile != NULL) { | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |             struct stat st; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (stat(infile, &st) == 0 && st.st_size <= INT_MAX) | 
					
						
							|  |  |  |                 filesize = (int)st.st_size; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
											  
											
												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) | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |             goto end; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-09-04 18:49:06 +08:00
										 |  |  |     out = bio_open_default(outfile, 'w', FORMAT_BINARY); | 
					
						
							| 
									
										
											  
											
												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 (out == NULL) | 
					
						
							|  |  |  |         goto end; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     if (pkey_op == EVP_PKEY_OP_ENCAPSULATE) { | 
					
						
							|  |  |  |         if (secoutfile == NULL) { | 
					
						
							|  |  |  |             BIO_printf(bio_err, "Encapsulation requires '-secret' argument\n"); | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         secout = bio_open_default(secoutfile, 'w', FORMAT_BINARY); | 
					
						
							|  |  |  |         if (secout == NULL) | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  |     if (sigfile != NULL) { | 
					
						
							| 
									
										
										
										
											2006-04-09 06:25:47 +08:00
										 |  |  |         BIO *sigbio = BIO_new_file(sigfile, "rb"); | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (sigbio == NULL) { | 
					
						
							| 
									
										
										
										
											2006-04-09 06:25:47 +08:00
										 |  |  |             BIO_printf(bio_err, "Can't open signature file %s\n", sigfile); | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         siglen = bio_to_mem(&sig, keysize * 10, sigbio); | 
					
						
							|  |  |  |         BIO_free(sigbio); | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  |         if (siglen < 0) { | 
					
						
							| 
									
										
										
										
											2006-04-09 06:25:47 +08:00
										 |  |  |             BIO_printf(bio_err, "Error reading signature data\n"); | 
					
						
							|  |  |  |             goto end; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2006-04-09 06:25:47 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |     /* Raw input data is handled elsewhere */ | 
					
						
							|  |  |  |     if (in != NULL && !rawin) { | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  |         /* Read the input data */ | 
					
						
							| 
									
										
										
										
											2023-06-23 18:50:17 +08:00
										 |  |  |         buf_inlen = bio_to_mem(&buf_in, -1, in); | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  |         if (buf_inlen < 0) { | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  |             BIO_printf(bio_err, "Error reading input Data\n"); | 
					
						
							| 
									
										
										
										
											2018-05-17 19:53:07 +08:00
										 |  |  |             goto end; | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rev) { | 
					
						
							| 
									
										
										
										
											2006-07-22 06:28:48 +08:00
										 |  |  |             size_t i; | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  |             unsigned char ctmp; | 
					
						
							| 
									
										
										
										
											2006-08-20 13:18:12 +08:00
										 |  |  |             size_t l = (size_t)buf_inlen; | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-20 13:18:12 +08:00
										 |  |  |             for (i = 0; i < l / 2; i++) { | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  |                 ctmp = buf_in[i]; | 
					
						
							| 
									
										
										
										
											2006-08-20 13:18:12 +08:00
										 |  |  |                 buf_in[i] = buf_in[l - 1 - i]; | 
					
						
							|  |  |  |                 buf_in[l - 1 - i] = ctmp; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |     /* Sanity check the input if the input is not raw */ | 
					
						
							|  |  |  |     if (!rawin | 
					
						
							| 
									
										
										
										
											2024-11-08 04:55:53 +08:00
										 |  |  |         && (pkey_op == EVP_PKEY_OP_SIGN || pkey_op == EVP_PKEY_OP_VERIFY)) { | 
					
						
							| 
									
										
										
										
											2024-10-30 02:41:02 +08:00
										 |  |  |         if (buf_inlen > EVP_MAX_MD_SIZE) { | 
					
						
							|  |  |  |             BIO_printf(bio_err, | 
					
						
							|  |  |  |                        "Error: The non-raw input data length %d is too long - max supported hashed size is %d\n", | 
					
						
							|  |  |  |                        buf_inlen, EVP_MAX_MD_SIZE); | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-05-17 19:53:07 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  |     if (pkey_op == EVP_PKEY_OP_VERIFY) { | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |         if (rawin) { | 
					
						
							| 
									
										
										
										
											2021-01-11 04:26:32 +08:00
										 |  |  |             rv = do_raw_keyop(pkey_op, mctx, pkey, in, filesize, sig, siglen, | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |                               NULL, 0); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen, | 
					
						
							|  |  |  |                                  buf_in, (size_t)buf_inlen); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
											  
											
												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 (rv == 1) { | 
					
						
							| 
									
										
										
										
											2006-04-09 06:25:47 +08:00
										 |  |  |             BIO_puts(out, "Signature Verified Successfully\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
										 |  |  |             ret = 0; | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  |         } else { | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |             BIO_puts(out, "Signature Verification Failure\n"); | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +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
										 |  |  |         goto end; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-01-11 00:26:33 +08:00
										 |  |  |     if (rawin) { | 
					
						
							|  |  |  |         /* rawin allocates the buffer in do_raw_keyop() */ | 
					
						
							|  |  |  |         rv = do_raw_keyop(pkey_op, mctx, pkey, in, filesize, NULL, 0, | 
					
						
							|  |  |  |                           &buf_out, (size_t *)&buf_outlen); | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2022-01-11 00:26:33 +08:00
										 |  |  |         if (kdflen != 0) { | 
					
						
							|  |  |  |             buf_outlen = kdflen; | 
					
						
							|  |  |  |             rv = 1; | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen, | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |                           buf_in, (size_t)buf_inlen, NULL, (size_t *)&secretlen); | 
					
						
							| 
									
										
										
										
											2022-01-11 00:26:33 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rv > 0 && buf_outlen != 0) { | 
					
						
							|  |  |  |             buf_out = app_malloc(buf_outlen, "buffer output"); | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |             if (secretlen > 0) | 
					
						
							|  |  |  |                 secret = app_malloc(secretlen, "secret output"); | 
					
						
							| 
									
										
										
										
											2022-01-11 00:26:33 +08:00
										 |  |  |             rv = do_keyop(ctx, pkey_op, | 
					
						
							|  |  |  |                           buf_out, (size_t *)&buf_outlen, | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |                           buf_in, (size_t)buf_inlen, secret, (size_t *)&secretlen); | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-03-02 01:22:51 +08:00
										 |  |  |     if (rv <= 0) { | 
					
						
							| 
									
										
										
										
											2017-07-22 04:19:35 +08:00
										 |  |  |         if (pkey_op != EVP_PKEY_OP_DERIVE) { | 
					
						
							|  |  |  |             BIO_puts(bio_err, "Public Key operation error\n"); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             BIO_puts(bio_err, "Key derivation failed\n"); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |         goto end; | 
					
						
							| 
									
										
										
										
											2006-04-09 06:25:47 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |     ret = 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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-09 06:25:47 +08:00
										 |  |  |     if (asn1parse) { | 
					
						
							|  |  |  |         if (!ASN1_parse_dump(out, buf_out, buf_outlen, 1, -1)) | 
					
						
							| 
									
										
										
										
											2021-08-03 20:40:08 +08:00
										 |  |  |             ERR_print_errors(bio_err); /* but still return success */ | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  |     } else if (hexdump) { | 
					
						
							| 
									
										
										
										
											2006-04-09 06:25:47 +08:00
										 |  |  |         BIO_dump(out, (char *)buf_out, buf_outlen); | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2006-04-09 06:25:47 +08:00
										 |  |  |         BIO_write(out, buf_out, buf_outlen); | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     if (secretlen > 0) | 
					
						
							|  |  |  |         BIO_write(secout, secret, secretlen); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |  end: | 
					
						
							| 
									
										
										
										
											2021-08-03 20:40:08 +08:00
										 |  |  |     if (ret != 0) | 
					
						
							|  |  |  |         ERR_print_errors(bio_err); | 
					
						
							| 
									
										
										
										
											2021-01-11 04:26:32 +08:00
										 |  |  |     EVP_MD_CTX_free(mctx); | 
					
						
							| 
									
										
										
										
											2015-03-28 22:54:15 +08:00
										 |  |  |     EVP_PKEY_CTX_free(ctx); | 
					
						
							| 
									
										
										
										
											2024-11-19 03:56:34 +08:00
										 |  |  |     EVP_PKEY_free(pkey); | 
					
						
							| 
									
										
										
										
											2021-02-18 05:15:27 +08:00
										 |  |  |     EVP_MD_free(md); | 
					
						
							| 
									
										
										
										
											2016-09-29 05:39:18 +08:00
										 |  |  |     release_engine(e); | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |     BIO_free(in); | 
					
						
							|  |  |  |     BIO_free_all(out); | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     BIO_free_all(secout); | 
					
						
							| 
									
										
										
										
											2015-05-01 22:02:07 +08:00
										 |  |  |     OPENSSL_free(buf_in); | 
					
						
							|  |  |  |     OPENSSL_free(buf_out); | 
					
						
							|  |  |  |     OPENSSL_free(sig); | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     OPENSSL_free(secret); | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  |     sk_OPENSSL_STRING_free(pkeyopts); | 
					
						
							| 
									
										
										
										
											2017-08-02 01:38:32 +08:00
										 |  |  |     sk_OPENSSL_STRING_free(pkeyopts_passin); | 
					
						
							| 
									
										
										
										
											2020-07-23 15:40:40 +08:00
										 |  |  |     NCONF_free(conf); | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |     return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  | static EVP_PKEY *get_pkey(const char *kdfalg, | 
					
						
							|  |  |  |                           const char *keyfile, int keyform, int key_type, | 
					
						
							|  |  |  |                           char *passinarg, int pkey_op, ENGINE *e) | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     EVP_PKEY *pkey = NULL; | 
					
						
							|  |  |  |     char *passin = NULL; | 
					
						
							|  |  |  |     X509 *x; | 
					
						
							| 
									
										
										
										
											2020-12-27 04:32:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  |     if (((pkey_op == EVP_PKEY_OP_SIGN) || (pkey_op == EVP_PKEY_OP_DECRYPT) | 
					
						
							|  |  |  |          || (pkey_op == EVP_PKEY_OP_DERIVE)) | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  |         && (key_type != KEY_PRIVKEY && kdfalg == NULL)) { | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |         BIO_printf(bio_err, "A private key is needed for this operation\n"); | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +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
										 |  |  |     if (!app_passwd(passinarg, NULL, &passin, NULL)) { | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |         BIO_printf(bio_err, "Error getting password\n"); | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     switch (key_type) { | 
					
						
							|  |  |  |     case KEY_PRIVKEY: | 
					
						
							| 
									
										
										
										
											2020-09-17 07:39:00 +08:00
										 |  |  |         pkey = load_key(keyfile, keyform, 0, passin, e, "private key"); | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |     case KEY_PUBKEY: | 
					
						
							| 
									
										
										
										
											2020-09-17 07:39:00 +08:00
										 |  |  |         pkey = load_pubkey(keyfile, keyform, 0, NULL, e, "public key"); | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |     case KEY_CERT: | 
					
						
							| 
									
										
										
										
											2021-04-30 22:57:53 +08:00
										 |  |  |         x = load_cert(keyfile, keyform, "Certificate"); | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |         if (x) { | 
					
						
							|  |  |  |             pkey = X509_get_pubkey(x); | 
					
						
							|  |  |  |             X509_free(x); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  |     case KEY_NONE: | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  |     OPENSSL_free(passin); | 
					
						
							|  |  |  |     return pkey; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize, | 
					
						
							|  |  |  |                               int pkey_op, ENGINE *e, | 
					
						
							|  |  |  |                               const int engine_impl, int rawin, | 
					
						
							|  |  |  |                               EVP_PKEY *pkey /* ownership is passed to ctx */, | 
					
						
							|  |  |  |                               EVP_MD_CTX *mctx, const char *digestname, | 
					
						
							|  |  |  |                               const char *kemop, OSSL_LIB_CTX *libctx, const char *propq) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EVP_PKEY_CTX *ctx = NULL; | 
					
						
							|  |  |  |     ENGINE *impl = NULL; | 
					
						
							|  |  |  |     int rv = -1; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-14 12:03:31 +08:00
										 |  |  | #ifndef OPENSSL_NO_ENGINE
 | 
					
						
							|  |  |  |     if (engine_impl) | 
					
						
							|  |  |  |         impl = e; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  |     if (kdfalg != NULL) { | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  |         int kdfnid = OBJ_sn2nid(kdfalg); | 
					
						
							| 
									
										
										
										
											2017-08-03 07:45:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (kdfnid == NID_undef) { | 
					
						
							|  |  |  |             kdfnid = OBJ_ln2nid(kdfalg); | 
					
						
							| 
									
										
										
										
											2017-07-22 04:19:35 +08:00
										 |  |  |             if (kdfnid == NID_undef) { | 
					
						
							|  |  |  |                 BIO_printf(bio_err, "The given KDF \"%s\" is unknown.\n", | 
					
						
							|  |  |  |                            kdfalg); | 
					
						
							| 
									
										
										
										
											2024-11-19 03:56:34 +08:00
										 |  |  |                 return NULL; | 
					
						
							| 
									
										
										
										
											2017-07-22 04:19:35 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-08-03 07:45:49 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-23 15:40:40 +08:00
										 |  |  |         if (impl != NULL) | 
					
						
							|  |  |  |             ctx = EVP_PKEY_CTX_new_id(kdfnid, impl); | 
					
						
							|  |  |  |         else | 
					
						
							| 
									
										
										
										
											2021-01-11 04:26:32 +08:00
										 |  |  |             ctx = EVP_PKEY_CTX_new_from_name(libctx, kdfalg, propq); | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         if (pkey == NULL) | 
					
						
							| 
									
										
										
										
											2024-11-19 03:56:34 +08:00
										 |  |  |             return NULL; | 
					
						
							| 
									
										
										
										
											2019-02-28 21:47:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
											
												Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
											
										 
											2021-05-21 22:58:08 +08:00
										 |  |  |         *pkeysize = EVP_PKEY_get_size(pkey); | 
					
						
							| 
									
										
										
										
											2020-07-23 15:40:40 +08:00
										 |  |  |         if (impl != NULL) | 
					
						
							|  |  |  |             ctx = EVP_PKEY_CTX_new(pkey, impl); | 
					
						
							|  |  |  |         else | 
					
						
							| 
									
										
										
										
											2021-01-11 04:26:32 +08:00
										 |  |  |             ctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey, propq); | 
					
						
							| 
									
										
										
										
											2016-03-02 00:29:47 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 19:18:04 +08:00
										 |  |  |     if (ctx == NULL) | 
					
						
							| 
									
										
										
										
											2024-11-19 03:56:34 +08:00
										 |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |     if (rawin) { | 
					
						
							| 
									
										
										
										
											2021-01-11 04:26:32 +08:00
										 |  |  |         EVP_MD_CTX_set_pkey_ctx(mctx, ctx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         switch (pkey_op) { | 
					
						
							|  |  |  |         case EVP_PKEY_OP_SIGN: | 
					
						
							| 
									
										
										
										
											2021-03-02 20:40:25 +08:00
										 |  |  |             rv = EVP_DigestSignInit_ex(mctx, NULL, digestname, libctx, propq, | 
					
						
							|  |  |  |                                        pkey, NULL); | 
					
						
							| 
									
										
										
										
											2021-01-11 04:26:32 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         case EVP_PKEY_OP_VERIFY: | 
					
						
							| 
									
										
										
										
											2021-03-02 20:40:25 +08:00
										 |  |  |             rv = EVP_DigestVerifyInit_ex(mctx, NULL, digestname, libctx, propq, | 
					
						
							|  |  |  |                                          pkey, NULL); | 
					
						
							| 
									
										
										
										
											2021-01-11 04:26:32 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         switch (pkey_op) { | 
					
						
							|  |  |  |         case EVP_PKEY_OP_SIGN: | 
					
						
							|  |  |  |             rv = EVP_PKEY_sign_init(ctx); | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |         case EVP_PKEY_OP_VERIFY: | 
					
						
							|  |  |  |             rv = EVP_PKEY_verify_init(ctx); | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |         case EVP_PKEY_OP_VERIFYRECOVER: | 
					
						
							|  |  |  |             rv = EVP_PKEY_verify_recover_init(ctx); | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |         case EVP_PKEY_OP_ENCRYPT: | 
					
						
							|  |  |  |             rv = EVP_PKEY_encrypt_init(ctx); | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |         case EVP_PKEY_OP_DECRYPT: | 
					
						
							|  |  |  |             rv = EVP_PKEY_decrypt_init(ctx); | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |         case EVP_PKEY_OP_DERIVE: | 
					
						
							|  |  |  |             rv = EVP_PKEY_derive_init(ctx); | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         case EVP_PKEY_OP_ENCAPSULATE: | 
					
						
							|  |  |  |             rv = EVP_PKEY_encapsulate_init(ctx, NULL); | 
					
						
							|  |  |  |             if (rv > 0 && kemop != NULL) | 
					
						
							|  |  |  |                 rv = EVP_PKEY_CTX_set_kem_op(ctx, kemop); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         case EVP_PKEY_OP_DECAPSULATE: | 
					
						
							|  |  |  |             rv = EVP_PKEY_decapsulate_init(ctx, NULL); | 
					
						
							|  |  |  |             if (rv > 0 && kemop != NULL) | 
					
						
							|  |  |  |                 rv = EVP_PKEY_CTX_set_kem_op(ctx, kemop); | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |     if (rv <= 0) { | 
					
						
							|  |  |  |         EVP_PKEY_CTX_free(ctx); | 
					
						
							|  |  |  |         ctx = NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-08 03:33:28 +08:00
										 |  |  |     return ctx; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  | static int setup_peer(EVP_PKEY_CTX *ctx, int peerform, const char *file, | 
					
						
							| 
									
										
										
										
											2017-07-22 04:19:35 +08:00
										 |  |  |                       ENGINE *e) | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-11-14 16:28:16 +08:00
										 |  |  |     EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  |     EVP_PKEY *peer = NULL; | 
					
						
							| 
									
										
										
										
											2017-07-22 04:19:35 +08:00
										 |  |  |     ENGINE *engine = NULL; | 
					
						
							| 
									
										
										
										
											2024-11-14 16:28:16 +08:00
										 |  |  |     int ret = 1; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 13:37:41 +08:00
										 |  |  |     if (peerform == FORMAT_ENGINE) | 
					
						
							|  |  |  |         engine = e; | 
					
						
							| 
									
										
										
										
											2020-09-17 07:39:00 +08:00
										 |  |  |     peer = load_pubkey(file, peerform, 0, NULL, engine, "peer key"); | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  |     if (peer == NULL) { | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  |         BIO_printf(bio_err, "Error reading peer key %s\n", file); | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-11-14 16:28:16 +08:00
										 |  |  |     if (strcmp(EVP_PKEY_get0_type_name(peer), EVP_PKEY_get0_type_name(pkey)) != 0) { | 
					
						
							|  |  |  |         BIO_printf(bio_err, | 
					
						
							|  |  |  |                    "Type of peer public key: %s does not match type of private key: %s\n", | 
					
						
							|  |  |  |                    EVP_PKEY_get0_type_name(peer), EVP_PKEY_get0_type_name(pkey)); | 
					
						
							|  |  |  |         ret = 0; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         ret = EVP_PKEY_derive_set_peer(ctx, peer) > 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-14 04:16:56 +08:00
										 |  |  |     EVP_PKEY_free(peer); | 
					
						
							|  |  |  |     return ret; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int do_keyop(EVP_PKEY_CTX *ctx, int pkey_op, | 
					
						
							| 
									
										
										
										
											2006-05-26 20:24:49 +08:00
										 |  |  |                     unsigned char *out, size_t *poutlen, | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |                     const unsigned char *in, size_t inlen, | 
					
						
							|  |  |  |                     unsigned char *secret, size_t *pseclen) | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-05-26 21:27:58 +08:00
										 |  |  |     int rv = 0; | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  |     switch (pkey_op) { | 
					
						
							|  |  |  |     case EVP_PKEY_OP_VERIFYRECOVER: | 
					
						
							| 
									
										
										
										
											2006-05-26 20:24:49 +08:00
										 |  |  |         rv = EVP_PKEY_verify_recover(ctx, out, poutlen, in, inlen); | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  |     case EVP_PKEY_OP_SIGN: | 
					
						
							| 
									
										
										
										
											2006-05-26 20:24:49 +08:00
										 |  |  |         rv = EVP_PKEY_sign(ctx, out, poutlen, in, inlen); | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  |     case EVP_PKEY_OP_ENCRYPT: | 
					
						
							| 
									
										
										
										
											2006-05-26 20:24:49 +08:00
										 |  |  |         rv = EVP_PKEY_encrypt(ctx, out, poutlen, in, inlen); | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  |     case EVP_PKEY_OP_DECRYPT: | 
					
						
							| 
									
										
										
										
											2006-05-26 20:24:49 +08:00
										 |  |  |         rv = EVP_PKEY_decrypt(ctx, out, poutlen, in, inlen); | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  |     case EVP_PKEY_OP_DERIVE: | 
					
						
							| 
									
										
										
										
											2006-05-26 20:24:49 +08:00
										 |  |  |         rv = EVP_PKEY_derive(ctx, out, poutlen); | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-07 23:17:18 +08:00
										 |  |  |     case EVP_PKEY_OP_ENCAPSULATE: | 
					
						
							|  |  |  |         rv = EVP_PKEY_encapsulate(ctx, out, poutlen, secret, pseclen); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case EVP_PKEY_OP_DECAPSULATE: | 
					
						
							|  |  |  |         rv = EVP_PKEY_decapsulate(ctx, out, poutlen, in, inlen); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-16 02:50:56 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return rv; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define TBUF_MAXSIZE 2048
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 04:26:32 +08:00
										 |  |  | static int do_raw_keyop(int pkey_op, EVP_MD_CTX *mctx, | 
					
						
							|  |  |  |                         EVP_PKEY *pkey, BIO *in, | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |                         int filesize, unsigned char *sig, int siglen, | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |                         unsigned char **out, size_t *poutlen) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int rv = 0; | 
					
						
							|  |  |  |     unsigned char tbuf[TBUF_MAXSIZE]; | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |     unsigned char *mbuf = NULL; | 
					
						
							|  |  |  |     int buf_len = 0; | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |     /* Some algorithms only support oneshot digests */ | 
					
						
							| 
									
										
										
										
											2023-12-02 21:50:36 +08:00
										 |  |  |     if (only_rawin(pkey)) { | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |         if (filesize < 0) { | 
					
						
							|  |  |  |             BIO_printf(bio_err, | 
					
						
							|  |  |  |                        "Error: unable to determine file size for oneshot operation\n"); | 
					
						
							| 
									
										
										
										
											2019-04-07 09:45:36 +08:00
										 |  |  |             goto end; | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |         mbuf = app_malloc(filesize, "oneshot sign/verify buffer"); | 
					
						
							| 
									
										
										
										
											2021-10-26 15:16:18 +08:00
										 |  |  |         switch (pkey_op) { | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |         case EVP_PKEY_OP_VERIFY: | 
					
						
							|  |  |  |             buf_len = BIO_read(in, mbuf, filesize); | 
					
						
							|  |  |  |             if (buf_len != filesize) { | 
					
						
							|  |  |  |                 BIO_printf(bio_err, "Error reading raw input data\n"); | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             rv = EVP_DigestVerify(mctx, sig, (size_t)siglen, mbuf, buf_len); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case EVP_PKEY_OP_SIGN: | 
					
						
							|  |  |  |             buf_len = BIO_read(in, mbuf, filesize); | 
					
						
							|  |  |  |             if (buf_len != filesize) { | 
					
						
							|  |  |  |                 BIO_printf(bio_err, "Error reading raw input data\n"); | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             rv = EVP_DigestSign(mctx, NULL, poutlen, mbuf, buf_len); | 
					
						
							|  |  |  |             if (rv == 1 && out != NULL) { | 
					
						
							|  |  |  |                 *out = app_malloc(*poutlen, "buffer output"); | 
					
						
							|  |  |  |                 rv = EVP_DigestSign(mctx, *out, poutlen, mbuf, buf_len); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         goto end; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-26 15:16:18 +08:00
										 |  |  |     switch (pkey_op) { | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |     case EVP_PKEY_OP_VERIFY: | 
					
						
							|  |  |  |         for (;;) { | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |             buf_len = BIO_read(in, tbuf, TBUF_MAXSIZE); | 
					
						
							|  |  |  |             if (buf_len == 0) | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |             if (buf_len < 0) { | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |                 BIO_printf(bio_err, "Error reading raw input data\n"); | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |             rv = EVP_DigestVerifyUpdate(mctx, tbuf, (size_t)buf_len); | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |             if (rv != 1) { | 
					
						
							|  |  |  |                 BIO_printf(bio_err, "Error verifying raw input data\n"); | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         rv = EVP_DigestVerifyFinal(mctx, sig, (size_t)siglen); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case EVP_PKEY_OP_SIGN: | 
					
						
							|  |  |  |         for (;;) { | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |             buf_len = BIO_read(in, tbuf, TBUF_MAXSIZE); | 
					
						
							|  |  |  |             if (buf_len == 0) | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |             if (buf_len < 0) { | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |                 BIO_printf(bio_err, "Error reading raw input data\n"); | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-03-07 18:37:34 +08:00
										 |  |  |             rv = EVP_DigestSignUpdate(mctx, tbuf, (size_t)buf_len); | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |             if (rv != 1) { | 
					
						
							|  |  |  |                 BIO_printf(bio_err, "Error signing raw input data\n"); | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         rv = EVP_DigestSignFinal(mctx, NULL, poutlen); | 
					
						
							|  |  |  |         if (rv == 1 && out != NULL) { | 
					
						
							|  |  |  |             *out = app_malloc(*poutlen, "buffer output"); | 
					
						
							|  |  |  |             rv = EVP_DigestSignFinal(mctx, *out, poutlen); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  end: | 
					
						
							| 
									
										
										
										
											2019-04-07 09:45:36 +08:00
										 |  |  |     OPENSSL_free(mbuf); | 
					
						
							| 
									
										
										
										
											2019-01-16 16:16:28 +08:00
										 |  |  |     return rv; | 
					
						
							|  |  |  | } |