rsautl.c (111147) | rsautl.c (127128) |
---|---|
1/* rsautl.c */ 2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 3 * project 2000. 4 */ 5/* ==================================================================== 6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 83 unchanged lines hidden (view full) --- 92 char rsa_mode = RSA_VERIFY, key_type = KEY_PRIVKEY; 93 int keyform = FORMAT_PEM; 94 char need_priv = 0, badarg = 0, rev = 0; 95 char hexdump = 0, asn1parse = 0; 96 X509 *x; 97 EVP_PKEY *pkey = NULL; 98 RSA *rsa = NULL; 99 unsigned char *rsa_in = NULL, *rsa_out = NULL, pad; | 1/* rsautl.c */ 2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 3 * project 2000. 4 */ 5/* ==================================================================== 6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 83 unchanged lines hidden (view full) --- 92 char rsa_mode = RSA_VERIFY, key_type = KEY_PRIVKEY; 93 int keyform = FORMAT_PEM; 94 char need_priv = 0, badarg = 0, rev = 0; 95 char hexdump = 0, asn1parse = 0; 96 X509 *x; 97 EVP_PKEY *pkey = NULL; 98 RSA *rsa = NULL; 99 unsigned char *rsa_in = NULL, *rsa_out = NULL, pad; |
100 char *passargin = NULL, *passin = NULL; |
|
100 int rsa_inlen, rsa_outlen = 0; 101 int keysize; 102 103 int ret = 1; 104 105 argc--; 106 argv++; 107 --- 11 unchanged lines hidden (view full) --- 119 if (--argc < 1) badarg = 1; 120 infile= *(++argv); 121 } else if (!strcmp(*argv,"-out")) { 122 if (--argc < 1) badarg = 1; 123 outfile= *(++argv); 124 } else if(!strcmp(*argv, "-inkey")) { 125 if (--argc < 1) badarg = 1; 126 keyfile = *(++argv); | 101 int rsa_inlen, rsa_outlen = 0; 102 int keysize; 103 104 int ret = 1; 105 106 argc--; 107 argv++; 108 --- 11 unchanged lines hidden (view full) --- 120 if (--argc < 1) badarg = 1; 121 infile= *(++argv); 122 } else if (!strcmp(*argv,"-out")) { 123 if (--argc < 1) badarg = 1; 124 outfile= *(++argv); 125 } else if(!strcmp(*argv, "-inkey")) { 126 if (--argc < 1) badarg = 1; 127 keyfile = *(++argv); |
128 } else if (!strcmp(*argv,"-passin")) { 129 if (--argc < 1) badarg = 1; 130 passargin= *(++argv); |
|
127 } else if (strcmp(*argv,"-keyform") == 0) { 128 if (--argc < 1) badarg = 1; 129 keyform=str2fmt(*(++argv)); 130#ifndef OPENSSL_NO_ENGINE 131 } else if(!strcmp(*argv, "-engine")) { 132 if (--argc < 1) badarg = 1; 133 engine = *(++argv); 134#endif --- 29 unchanged lines hidden (view full) --- 164 if(need_priv && (key_type != KEY_PRIVKEY)) { 165 BIO_printf(bio_err, "A private key is needed for this operation\n"); 166 goto end; 167 } 168 169#ifndef OPENSSL_NO_ENGINE 170 e = setup_engine(bio_err, engine, 0); 171#endif | 131 } else if (strcmp(*argv,"-keyform") == 0) { 132 if (--argc < 1) badarg = 1; 133 keyform=str2fmt(*(++argv)); 134#ifndef OPENSSL_NO_ENGINE 135 } else if(!strcmp(*argv, "-engine")) { 136 if (--argc < 1) badarg = 1; 137 engine = *(++argv); 138#endif --- 29 unchanged lines hidden (view full) --- 168 if(need_priv && (key_type != KEY_PRIVKEY)) { 169 BIO_printf(bio_err, "A private key is needed for this operation\n"); 170 goto end; 171 } 172 173#ifndef OPENSSL_NO_ENGINE 174 e = setup_engine(bio_err, engine, 0); 175#endif |
176 if(!app_passwd(bio_err, passargin, NULL, &passin, NULL)) { 177 BIO_printf(bio_err, "Error getting password\n"); 178 goto end; 179 } |
|
172 173/* FIXME: seed PRNG only if needed */ 174 app_RAND_load_file(NULL, bio_err, 0); 175 176 switch(key_type) { 177 case KEY_PRIVKEY: 178 pkey = load_key(bio_err, keyfile, keyform, 0, | 180 181/* FIXME: seed PRNG only if needed */ 182 app_RAND_load_file(NULL, bio_err, 0); 183 184 switch(key_type) { 185 case KEY_PRIVKEY: 186 pkey = load_key(bio_err, keyfile, keyform, 0, |
179 NULL, e, "Private Key"); | 187 passin, e, "Private Key"); |
180 break; 181 182 case KEY_PUBKEY: 183 pkey = load_pubkey(bio_err, keyfile, keyform, 0, 184 NULL, e, "Public Key"); 185 break; 186 187 case KEY_CERT: --- 97 unchanged lines hidden (view full) --- 285 } else if(hexdump) BIO_dump(out, (char *)rsa_out, rsa_outlen); 286 else BIO_write(out, rsa_out, rsa_outlen); 287 end: 288 RSA_free(rsa); 289 BIO_free(in); 290 BIO_free_all(out); 291 if(rsa_in) OPENSSL_free(rsa_in); 292 if(rsa_out) OPENSSL_free(rsa_out); | 188 break; 189 190 case KEY_PUBKEY: 191 pkey = load_pubkey(bio_err, keyfile, keyform, 0, 192 NULL, e, "Public Key"); 193 break; 194 195 case KEY_CERT: --- 97 unchanged lines hidden (view full) --- 293 } else if(hexdump) BIO_dump(out, (char *)rsa_out, rsa_outlen); 294 else BIO_write(out, rsa_out, rsa_outlen); 295 end: 296 RSA_free(rsa); 297 BIO_free(in); 298 BIO_free_all(out); 299 if(rsa_in) OPENSSL_free(rsa_in); 300 if(rsa_out) OPENSSL_free(rsa_out); |
301 if(passin) OPENSSL_free(passin); |
|
293 return ret; 294} 295 296static void usage() 297{ 298 BIO_printf(bio_err, "Usage: rsautl [options]\n"); 299 BIO_printf(bio_err, "-in file input file\n"); 300 BIO_printf(bio_err, "-out file output file\n"); --- 7 unchanged lines hidden (view full) --- 308 BIO_printf(bio_err, "-oaep use PKCS#1 OAEP\n"); 309 BIO_printf(bio_err, "-sign sign with private key\n"); 310 BIO_printf(bio_err, "-verify verify with public key\n"); 311 BIO_printf(bio_err, "-encrypt encrypt with public key\n"); 312 BIO_printf(bio_err, "-decrypt decrypt with private key\n"); 313 BIO_printf(bio_err, "-hexdump hex dump output\n"); 314#ifndef OPENSSL_NO_ENGINE 315 BIO_printf(bio_err, "-engine e use engine e, possibly a hardware device.\n"); | 302 return ret; 303} 304 305static void usage() 306{ 307 BIO_printf(bio_err, "Usage: rsautl [options]\n"); 308 BIO_printf(bio_err, "-in file input file\n"); 309 BIO_printf(bio_err, "-out file output file\n"); --- 7 unchanged lines hidden (view full) --- 317 BIO_printf(bio_err, "-oaep use PKCS#1 OAEP\n"); 318 BIO_printf(bio_err, "-sign sign with private key\n"); 319 BIO_printf(bio_err, "-verify verify with public key\n"); 320 BIO_printf(bio_err, "-encrypt encrypt with public key\n"); 321 BIO_printf(bio_err, "-decrypt decrypt with private key\n"); 322 BIO_printf(bio_err, "-hexdump hex dump output\n"); 323#ifndef OPENSSL_NO_ENGINE 324 BIO_printf(bio_err, "-engine e use engine e, possibly a hardware device.\n"); |
325 BIO_printf (bio_err, "-passin arg pass phrase source\n"); |
|
316#endif 317 318} 319 320#endif | 326#endif 327 328} 329 330#endif |