69 static void usage(
void);
73 #define PROG pkeyutl_main
76 char *keyfile,
int keyform,
int key_type,
77 char *passargin,
int pkey_op,
ENGINE *
e);
83 unsigned char *out,
size_t *poutlen,
84 unsigned char *in,
size_t inlen);
86 int MAIN(
int argc,
char **);
88 int MAIN(
int argc,
char **argv)
91 char *infile = NULL, *outfile = NULL, *sigfile = NULL;
95 char badarg = 0, rev = 0;
96 char hexdump = 0, asn1parse = 0;
98 char *passargin = NULL;
101 unsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL;
103 int buf_inlen = 0, siglen = -1;
105 int ret = 1, rv = -1;
119 if (!strcmp(*argv,
"-in"))
121 if (--argc < 1) badarg = 1;
122 else infile= *(++argv);
124 else if (!strcmp(*argv,
"-out"))
126 if (--argc < 1) badarg = 1;
127 else outfile= *(++argv);
129 else if (!strcmp(*argv,
"-sigfile"))
131 if (--argc < 1) badarg = 1;
132 else sigfile= *(++argv);
134 else if(!strcmp(*argv,
"-inkey"))
140 ctx = init_ctx(&keysize,
141 *(++argv), keyform, key_type,
142 passargin, pkey_op, e);
146 "Error initializing context\n");
152 else if (!strcmp(*argv,
"-peerkey"))
156 else if (!setup_peer(
bio_err, ctx, peerform, *(++argv)))
159 else if (!strcmp(*argv,
"-passin"))
161 if (--argc < 1) badarg = 1;
162 else passargin= *(++argv);
164 else if (strcmp(*argv,
"-peerform") == 0)
166 if (--argc < 1) badarg = 1;
167 else peerform=
str2fmt(*(++argv));
169 else if (strcmp(*argv,
"-keyform") == 0)
171 if (--argc < 1) badarg = 1;
172 else keyform=
str2fmt(*(++argv));
174 #ifndef OPENSSL_NO_ENGINE
175 else if(!strcmp(*argv,
"-engine"))
183 else if(!strcmp(*argv,
"-pubin"))
185 else if(!strcmp(*argv,
"-certin"))
187 else if(!strcmp(*argv,
"-asn1parse"))
189 else if(!strcmp(*argv,
"-hexdump"))
191 else if(!strcmp(*argv,
"-sign"))
193 else if(!strcmp(*argv,
"-verify"))
195 else if(!strcmp(*argv,
"-verifyrecover"))
197 else if(!strcmp(*argv,
"-rev"))
199 else if(!strcmp(*argv,
"-encrypt"))
201 else if(!strcmp(*argv,
"-decrypt"))
203 else if(!strcmp(*argv,
"-derive"))
205 else if (strcmp(*argv,
"-pkeyopt") == 0)
212 "-pkeyopt command before -inkey\n");
260 "Error Opening Input File\n");
281 #ifdef OPENSSL_SYS_VMS
298 siglen =
bio_to_mem(&sig, keysize * 10, sigbio);
310 buf_inlen =
bio_to_mem(&buf_in, keysize * 10, in);
320 size_t l = (size_t)buf_inlen;
321 for(i = 0; i < l/2; i++)
324 buf_in[i] = buf_in[l - 1 - i];
325 buf_in[l - 1 - i] = ctmp;
333 buf_in, (
size_t)buf_inlen);
335 BIO_puts(out,
"Signature Verification Failure\n");
337 BIO_puts(out,
"Signature Verified Successfully\n");
343 rv = do_keyop(ctx, pkey_op, NULL, (
size_t *)&buf_outlen,
344 buf_in, (
size_t)buf_inlen);
351 rv = do_keyop(ctx, pkey_op,
352 buf_out, (
size_t *)&buf_outlen,
353 buf_in, (
size_t)buf_inlen);
370 BIO_dump(out, (
char *)buf_out, buf_outlen);
401 BIO_printf(
bio_err,
"-verifyrecover verify with public key, recover original data\n");
406 #ifndef OPENSSL_NO_ENGINE
414 char *keyfile,
int keyform,
int key_type,
415 char *passargin,
int pkey_op,
ENGINE *e)
438 passin, e,
"Private Key");
443 NULL, e,
"Public Key");
448 NULL, e,
"Certificate");
520 BIO_puts(err,
"-peerkey command before -inkey\n");
542 unsigned char *out,
size_t *poutlen,
543 unsigned char *in,
size_t inlen)