Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: openssl/apps/rsa.c

Issue 9254031: Upgrade chrome's OpenSSL to same version Android ships with. (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/openssl/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « openssl/apps/req.c ('k') | openssl/apps/rsautl.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* apps/rsa.c */ 1 /* apps/rsa.c */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 int informat,outformat,text=0,check=0,noout=0; 108 int informat,outformat,text=0,check=0,noout=0;
109 int pubin = 0, pubout = 0; 109 int pubin = 0, pubout = 0;
110 char *infile,*outfile,*prog; 110 char *infile,*outfile,*prog;
111 char *passargin = NULL, *passargout = NULL; 111 char *passargin = NULL, *passargout = NULL;
112 char *passin = NULL, *passout = NULL; 112 char *passin = NULL, *passout = NULL;
113 #ifndef OPENSSL_NO_ENGINE 113 #ifndef OPENSSL_NO_ENGINE
114 char *engine=NULL; 114 char *engine=NULL;
115 #endif 115 #endif
116 int modulus=0; 116 int modulus=0;
117 117
118 int pvk_encr = 2;
119
118 apps_startup(); 120 apps_startup();
119 121
120 if (bio_err == NULL) 122 if (bio_err == NULL)
121 if ((bio_err=BIO_new(BIO_s_file())) != NULL) 123 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
122 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); 124 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
123 125
124 if (!load_config(bio_err, NULL)) 126 if (!load_config(bio_err, NULL))
125 goto end; 127 goto end;
126 128
127 infile=NULL; 129 infile=NULL;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 if (--argc < 1) goto bad; 172 if (--argc < 1) goto bad;
171 engine= *(++argv); 173 engine= *(++argv);
172 } 174 }
173 #endif 175 #endif
174 else if (strcmp(*argv,"-sgckey") == 0) 176 else if (strcmp(*argv,"-sgckey") == 0)
175 sgckey=1; 177 sgckey=1;
176 else if (strcmp(*argv,"-pubin") == 0) 178 else if (strcmp(*argv,"-pubin") == 0)
177 pubin=1; 179 pubin=1;
178 else if (strcmp(*argv,"-pubout") == 0) 180 else if (strcmp(*argv,"-pubout") == 0)
179 pubout=1; 181 pubout=1;
182 else if (strcmp(*argv,"-RSAPublicKey_in") == 0)
183 pubin = 2;
184 else if (strcmp(*argv,"-RSAPublicKey_out") == 0)
185 pubout = 2;
186 else if (strcmp(*argv,"-pvk-strong") == 0)
187 pvk_encr=2;
188 else if (strcmp(*argv,"-pvk-weak") == 0)
189 pvk_encr=1;
190 else if (strcmp(*argv,"-pvk-none") == 0)
191 pvk_encr=0;
180 else if (strcmp(*argv,"-noout") == 0) 192 else if (strcmp(*argv,"-noout") == 0)
181 noout=1; 193 noout=1;
182 else if (strcmp(*argv,"-text") == 0) 194 else if (strcmp(*argv,"-text") == 0)
183 text=1; 195 text=1;
184 else if (strcmp(*argv,"-modulus") == 0) 196 else if (strcmp(*argv,"-modulus") == 0)
185 modulus=1; 197 modulus=1;
186 else if (strcmp(*argv,"-check") == 0) 198 else if (strcmp(*argv,"-check") == 0)
187 check=1; 199 check=1;
188 else if ((enc=EVP_get_cipherbyname(&(argv[0][1]))) == NULL) 200 else if ((enc=EVP_get_cipherbyname(&(argv[0][1]))) == NULL)
189 { 201 {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 BIO_printf(bio_err, "Only private keys can be checked\n"); 262 BIO_printf(bio_err, "Only private keys can be checked\n");
251 goto end; 263 goto end;
252 } 264 }
253 265
254 out=BIO_new(BIO_s_file()); 266 out=BIO_new(BIO_s_file());
255 267
256 { 268 {
257 EVP_PKEY *pkey; 269 EVP_PKEY *pkey;
258 270
259 if (pubin) 271 if (pubin)
260 » » » pkey = load_pubkey(bio_err, infile, 272 » » » {
261 » » » » (informat == FORMAT_NETSCAPE && sgckey ? 273 » » » int tmpformat=-1;
262 » » » » » FORMAT_IISSGC : informat), 1, 274 » » » if (pubin == 2)
275 » » » » {
276 » » » » if (informat == FORMAT_PEM)
277 » » » » » tmpformat = FORMAT_PEMRSA;
278 » » » » else if (informat == FORMAT_ASN1)
279 » » » » » tmpformat = FORMAT_ASN1RSA;
280 » » » » }
281 » » » else if (informat == FORMAT_NETSCAPE && sgckey)
282 » » » » tmpformat = FORMAT_IISSGC;
283 » » » else
284 » » » » tmpformat = informat;
285 » » » » »
286 » » » pkey = load_pubkey(bio_err, infile, tmpformat, 1,
263 passin, e, "Public Key"); 287 passin, e, "Public Key");
288 }
264 else 289 else
265 pkey = load_key(bio_err, infile, 290 pkey = load_key(bio_err, infile,
266 (informat == FORMAT_NETSCAPE && sgckey ? 291 (informat == FORMAT_NETSCAPE && sgckey ?
267 FORMAT_IISSGC : informat), 1, 292 FORMAT_IISSGC : informat), 1,
268 passin, e, "Private Key"); 293 passin, e, "Private Key");
269 294
270 if (pkey != NULL) 295 if (pkey != NULL)
271 » » rsa = pkey == NULL ? NULL : EVP_PKEY_get1_RSA(pkey); 296 » » » rsa = EVP_PKEY_get1_RSA(pkey);
272 EVP_PKEY_free(pkey); 297 EVP_PKEY_free(pkey);
273 } 298 }
274 299
275 if (rsa == NULL) 300 if (rsa == NULL)
276 { 301 {
277 ERR_print_errors(bio_err); 302 ERR_print_errors(bio_err);
278 goto end; 303 goto end;
279 } 304 }
280 305
281 if (outfile == NULL) 306 if (outfile == NULL)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 } 364 }
340 } 365 }
341 366
342 if (noout) 367 if (noout)
343 { 368 {
344 ret = 0; 369 ret = 0;
345 goto end; 370 goto end;
346 } 371 }
347 BIO_printf(bio_err,"writing RSA key\n"); 372 BIO_printf(bio_err,"writing RSA key\n");
348 if (outformat == FORMAT_ASN1) { 373 if (outformat == FORMAT_ASN1) {
349 » » if(pubout || pubin) i=i2d_RSA_PUBKEY_bio(out,rsa); 374 » » if(pubout || pubin)
375 » » » {
376 » » » if (pubout == 2)
377 » » » » i=i2d_RSAPublicKey_bio(out,rsa);
378 » » » else
379 » » » » i=i2d_RSA_PUBKEY_bio(out,rsa);
380 » » » }
350 else i=i2d_RSAPrivateKey_bio(out,rsa); 381 else i=i2d_RSAPrivateKey_bio(out,rsa);
351 } 382 }
352 #ifndef OPENSSL_NO_RC4 383 #ifndef OPENSSL_NO_RC4
353 else if (outformat == FORMAT_NETSCAPE) 384 else if (outformat == FORMAT_NETSCAPE)
354 { 385 {
355 unsigned char *p,*pp; 386 unsigned char *p,*pp;
356 int size; 387 int size;
357 388
358 i=1; 389 i=1;
359 size=i2d_RSA_NET(rsa,NULL,NULL, sgckey); 390 size=i2d_RSA_NET(rsa,NULL,NULL, sgckey);
360 if ((p=(unsigned char *)OPENSSL_malloc(size)) == NULL) 391 if ((p=(unsigned char *)OPENSSL_malloc(size)) == NULL)
361 { 392 {
362 BIO_printf(bio_err,"Memory allocation failure\n"); 393 BIO_printf(bio_err,"Memory allocation failure\n");
363 goto end; 394 goto end;
364 } 395 }
365 pp=p; 396 pp=p;
366 i2d_RSA_NET(rsa,&p,NULL, sgckey); 397 i2d_RSA_NET(rsa,&p,NULL, sgckey);
367 BIO_write(out,(char *)pp,size); 398 BIO_write(out,(char *)pp,size);
368 OPENSSL_free(pp); 399 OPENSSL_free(pp);
369 } 400 }
370 #endif 401 #endif
371 else if (outformat == FORMAT_PEM) { 402 else if (outformat == FORMAT_PEM) {
372 if(pubout || pubin) 403 if(pubout || pubin)
373 » » i=PEM_write_bio_RSA_PUBKEY(out,rsa); 404 » » » {
405 » » » if (pubout == 2)
406 » » » » i=PEM_write_bio_RSAPublicKey(out,rsa);
407 » » » else
408 » » » » i=PEM_write_bio_RSA_PUBKEY(out,rsa);
409 » » » }
374 else i=PEM_write_bio_RSAPrivateKey(out,rsa, 410 else i=PEM_write_bio_RSAPrivateKey(out,rsa,
375 enc,NULL,0,NULL,passout); 411 enc,NULL,0,NULL,passout);
412 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_RC4)
413 } else if (outformat == FORMAT_MSBLOB || outformat == FORMAT_PVK) {
414 EVP_PKEY *pk;
415 pk = EVP_PKEY_new();
416 EVP_PKEY_set1_RSA(pk, rsa);
417 if (outformat == FORMAT_PVK)
418 i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout);
419 else if (pubin || pubout)
420 i = i2b_PublicKey_bio(out, pk);
421 else
422 i = i2b_PrivateKey_bio(out, pk);
423 EVP_PKEY_free(pk);
424 #endif
376 } else { 425 } else {
377 BIO_printf(bio_err,"bad output format specified for outfile\n"); 426 BIO_printf(bio_err,"bad output format specified for outfile\n");
378 goto end; 427 goto end;
379 } 428 }
380 » if (!i) 429 » if (i <= 0)
381 { 430 {
382 BIO_printf(bio_err,"unable to write key\n"); 431 BIO_printf(bio_err,"unable to write key\n");
383 ERR_print_errors(bio_err); 432 ERR_print_errors(bio_err);
384 } 433 }
385 else 434 else
386 ret=0; 435 ret=0;
387 end: 436 end:
388 if(out != NULL) BIO_free_all(out); 437 if(out != NULL) BIO_free_all(out);
389 if(rsa != NULL) RSA_free(rsa); 438 if(rsa != NULL) RSA_free(rsa);
390 if(passin) OPENSSL_free(passin); 439 if(passin) OPENSSL_free(passin);
391 if(passout) OPENSSL_free(passout); 440 if(passout) OPENSSL_free(passout);
392 apps_shutdown(); 441 apps_shutdown();
393 OPENSSL_EXIT(ret); 442 OPENSSL_EXIT(ret);
394 } 443 }
395 #else /* !OPENSSL_NO_RSA */ 444 #else /* !OPENSSL_NO_RSA */
396 445
397 # if PEDANTIC 446 # if PEDANTIC
398 static void *dummy=&dummy; 447 static void *dummy=&dummy;
399 # endif 448 # endif
400 449
401 #endif 450 #endif
OLDNEW
« no previous file with comments | « openssl/apps/req.c ('k') | openssl/apps/rsautl.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698