-int MAIN(int, char **);
-
-int MAIN(int argc, char **argv)
- {
- ENGINE *e = NULL;
- unsigned char *buf=NULL;
- int i,err=0;
- const EVP_MD *md=NULL,*m;
- BIO *in=NULL,*inp;
- BIO *bmd=NULL;
- BIO *out = NULL;
- const char *name;
-#define PROG_NAME_SIZE 16
- char pname[PROG_NAME_SIZE];
- int separator=0;
- int debug=0;
- int keyform=FORMAT_PEM;
- const char *outfile = NULL, *keyfile = NULL;
- const char *sigfile = NULL, *randfile = NULL;
- char out_bin = -1, want_pub = 0, do_verify = 0;
- EVP_PKEY *sigkey = NULL;
- unsigned char *sigbuf = NULL;
- int siglen = 0;
- char *engine=NULL;
-
- apps_startup();
-
- if ((buf=(unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL)
- {
- BIO_printf(bio_err,"out of memory\n");
- goto end;
- }
- if (bio_err == NULL)
- if ((bio_err=BIO_new(BIO_s_file())) != NULL)
- BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
-
- /* first check the program name */
- program_name(argv[0],pname,PROG_NAME_SIZE);
-
- md=EVP_get_digestbyname(pname);
-
- argc--;
- argv++;
- while (argc > 0)
- {
- if ((*argv)[0] != '-') break;
- if (strcmp(*argv,"-c") == 0)
- separator=1;
- else if (strcmp(*argv,"-rand") == 0)
- {
- if (--argc < 1) break;
- randfile=*(++argv);
- }
- else if (strcmp(*argv,"-out") == 0)
- {
- if (--argc < 1) break;
- outfile=*(++argv);
- }
- else if (strcmp(*argv,"-sign") == 0)
- {
- if (--argc < 1) break;
- keyfile=*(++argv);
- }
- else if (strcmp(*argv,"-verify") == 0)
- {
- if (--argc < 1) break;
- keyfile=*(++argv);
- want_pub = 1;
- do_verify = 1;
- }
- else if (strcmp(*argv,"-prverify") == 0)
- {
- if (--argc < 1) break;
- keyfile=*(++argv);
- do_verify = 1;
- }
- else if (strcmp(*argv,"-signature") == 0)
- {
- if (--argc < 1) break;
- sigfile=*(++argv);
- }
- else if (strcmp(*argv,"-keyform") == 0)
- {
- if (--argc < 1) break;
- keyform=str2fmt(*(++argv));
- }
- else if (strcmp(*argv,"-engine") == 0)
- {
- if (--argc < 1) break;
- engine= *(++argv);
- }
- else if (strcmp(*argv,"-hex") == 0)
- out_bin = 0;
- else if (strcmp(*argv,"-binary") == 0)
- out_bin = 1;
- else if (strcmp(*argv,"-d") == 0)
- debug=1;
- else if ((m=EVP_get_digestbyname(&((*argv)[1]))) != NULL)
- md=m;
- else
- break;
- argc--;
- argv++;
- }
+const OPTIONS dgst_options[] = {
+ {OPT_HELP_STR, 1, '-', "Usage: %s [options] [file...]\n"},
+ {OPT_HELP_STR, 1, '-',
+ " file... files to digest (default is stdin)\n"},
+ {"help", OPT_HELP, '-', "Display this summary"},
+ {"c", OPT_C, '-', "Print the digest with separating colons"},
+ {"r", OPT_R, '-', "Print the digest in coreutils format"},
+ {"out", OPT_OUT, '>', "Output to filename rather than stdout"},
+ {"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
+ {"sign", OPT_SIGN, 's', "Sign digest using private key"},
+ {"verify", OPT_VERIFY, 's',
+ "Verify a signature using public key"},
+ {"prverify", OPT_PRVERIFY, 's',
+ "Verify a signature using private key"},
+ {"signature", OPT_SIGNATURE, '<', "File with signature to verify"},
+ {"keyform", OPT_KEYFORM, 'f', "Key file format (PEM or ENGINE)"},
+ {"hex", OPT_HEX, '-', "Print as hex dump"},
+ {"binary", OPT_BINARY, '-', "Print in binary form"},
+ {"d", OPT_DEBUG, '-', "Print debug info"},
+ {"debug", OPT_DEBUG, '-', "Print debug info"},
+ {"fips-fingerprint", OPT_FIPS_FINGERPRINT, '-',
+ "Compute HMAC with the key used in OpenSSL-FIPS fingerprint"},
+ {"hmac", OPT_HMAC, 's', "Create hashed MAC with key"},
+ {"mac", OPT_MAC, 's', "Create MAC (not necessarily HMAC)"},
+ {"sigopt", OPT_SIGOPT, 's', "Signature parameter in n:v form"},
+ {"macopt", OPT_MACOPT, 's', "MAC algorithm parameters in n:v form or key"},
+ {"", OPT_DIGEST, '-', "Any supported digest"},
+ OPT_R_OPTIONS,
+#ifndef OPENSSL_NO_ENGINE
+ {"engine", OPT_ENGINE, 's', "Use engine e, possibly a hardware device"},
+ {"engine_impl", OPT_ENGINE_IMPL, '-',
+ "Also use engine given by -engine for digest operations"},
+#endif
+ {NULL}
+};