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

Side by Side Diff: openssl/apps/prime.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/pkeyutl.c ('k') | openssl/apps/progs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* ==================================================================== 1 /* ====================================================================
2 * Copyright (c) 2004 The OpenSSL Project. All rights reserved. 2 * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 #undef PROG 56 #undef PROG
57 #define PROG prime_main 57 #define PROG prime_main
58 58
59 int MAIN(int, char **); 59 int MAIN(int, char **);
60 60
61 int MAIN(int argc, char **argv) 61 int MAIN(int argc, char **argv)
62 { 62 {
63 int hex=0; 63 int hex=0;
64 int checks=20; 64 int checks=20;
65 int generate=0;
66 int bits=0;
67 int safe=0;
65 BIGNUM *bn=NULL; 68 BIGNUM *bn=NULL;
66 BIO *bio_out; 69 BIO *bio_out;
67 70
68 apps_startup(); 71 apps_startup();
69 72
70 if (bio_err == NULL) 73 if (bio_err == NULL)
71 if ((bio_err=BIO_new(BIO_s_file())) != NULL) 74 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
72 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); 75 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
73 76
74 --argc; 77 --argc;
75 ++argv; 78 ++argv;
76 while (argc >= 1 && **argv == '-') 79 while (argc >= 1 && **argv == '-')
77 { 80 {
78 if(!strcmp(*argv,"-hex")) 81 if(!strcmp(*argv,"-hex"))
79 hex=1; 82 hex=1;
83 else if(!strcmp(*argv,"-generate"))
84 generate=1;
85 else if(!strcmp(*argv,"-bits"))
86 if(--argc < 1)
87 goto bad;
88 else
89 bits=atoi(*++argv);
90 else if(!strcmp(*argv,"-safe"))
91 safe=1;
80 else if(!strcmp(*argv,"-checks")) 92 else if(!strcmp(*argv,"-checks"))
81 if(--argc < 1) 93 if(--argc < 1)
82 goto bad; 94 goto bad;
83 else 95 else
84 checks=atoi(*++argv); 96 checks=atoi(*++argv);
85 else 97 else
86 { 98 {
87 BIO_printf(bio_err,"Unknown option '%s'\n",*argv); 99 BIO_printf(bio_err,"Unknown option '%s'\n",*argv);
88 goto bad; 100 goto bad;
89 } 101 }
90 --argc; 102 --argc;
91 ++argv; 103 ++argv;
92 } 104 }
93 105
94 if (argv[0] == NULL) 106 if (argv[0] == NULL && !generate)
95 { 107 {
96 BIO_printf(bio_err,"No prime specified\n"); 108 BIO_printf(bio_err,"No prime specified\n");
97 goto bad; 109 goto bad;
98 } 110 }
99 111
100 if ((bio_out=BIO_new(BIO_s_file())) != NULL) 112 if ((bio_out=BIO_new(BIO_s_file())) != NULL)
101 { 113 {
102 BIO_set_fp(bio_out,stdout,BIO_NOCLOSE); 114 BIO_set_fp(bio_out,stdout,BIO_NOCLOSE);
103 #ifdef OPENSSL_SYS_VMS 115 #ifdef OPENSSL_SYS_VMS
104 { 116 {
105 BIO *tmpbio = BIO_new(BIO_f_linebuffer()); 117 BIO *tmpbio = BIO_new(BIO_f_linebuffer());
106 bio_out = BIO_push(tmpbio, bio_out); 118 bio_out = BIO_push(tmpbio, bio_out);
107 } 119 }
108 #endif 120 #endif
109 } 121 }
110 122
111 if(hex) 123 if(generate)
112 » BN_hex2bn(&bn,argv[0]); 124 » {
125 » char *s;
126
127 » if(!bits)
128 » {
129 » BIO_printf(bio_err,"Specifiy the number of bits.\n");
130 » return 1;
131 » }
132 » bn=BN_new();
133 » BN_generate_prime_ex(bn,bits,safe,NULL,NULL,NULL);
134 » s=hex ? BN_bn2hex(bn) : BN_bn2dec(bn);
135 » BIO_printf(bio_out,"%s\n",s);
136 » OPENSSL_free(s);
137 » }
113 else 138 else
114 » BN_dec2bn(&bn,argv[0]); 139 » {
140 » if(hex)
141 » BN_hex2bn(&bn,argv[0]);
142 » else
143 » BN_dec2bn(&bn,argv[0]);
115 144
116 BN_print(bio_out,bn); 145 » BN_print(bio_out,bn);
117 BIO_printf(bio_out," is %sprime\n", 146 » BIO_printf(bio_out," is %sprime\n",
118 » BN_is_prime_ex(bn,checks,NULL,NULL) ? "" : "not "); 147 » » BN_is_prime_ex(bn,checks,NULL,NULL) ? "" : "not ");
148 » }
119 149
120 BN_free(bn); 150 BN_free(bn);
121 BIO_free_all(bio_out); 151 BIO_free_all(bio_out);
122 152
123 return 0; 153 return 0;
124 154
125 bad: 155 bad:
126 BIO_printf(bio_err,"options are\n"); 156 BIO_printf(bio_err,"options are\n");
127 BIO_printf(bio_err,"%-14s hex\n","-hex"); 157 BIO_printf(bio_err,"%-14s hex\n","-hex");
128 BIO_printf(bio_err,"%-14s number of checks\n","-checks <n>"); 158 BIO_printf(bio_err,"%-14s number of checks\n","-checks <n>");
129 return 1; 159 return 1;
130 } 160 }
OLDNEW
« no previous file with comments | « openssl/apps/pkeyutl.c ('k') | openssl/apps/progs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698