diff options
Diffstat (limited to 'src/lib/libcrypto/bf/bf_opts.c')
-rw-r--r-- | src/lib/libcrypto/bf/bf_opts.c | 330 |
1 files changed, 0 insertions, 330 deletions
diff --git a/src/lib/libcrypto/bf/bf_opts.c b/src/lib/libcrypto/bf/bf_opts.c deleted file mode 100644 index da7a48740e..0000000000 --- a/src/lib/libcrypto/bf/bf_opts.c +++ /dev/null | |||
@@ -1,330 +0,0 @@ | |||
1 | /* crypto/bf/bf_opts.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* define PART1, PART2, PART3 or PART4 to build only with a few of the options. | ||
60 | * This is for machines with 64k code segment size restrictions. */ | ||
61 | |||
62 | #if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX) | ||
63 | #define TIMES | ||
64 | #endif | ||
65 | |||
66 | #include <stdio.h> | ||
67 | |||
68 | #include <openssl/e_os2.h> | ||
69 | #include <unistd.h> | ||
70 | |||
71 | #ifndef OPENSSL_SYS_NETWARE | ||
72 | #include <signal.h> | ||
73 | #endif | ||
74 | |||
75 | #ifndef _IRIX | ||
76 | #include <time.h> | ||
77 | #endif | ||
78 | #ifdef TIMES | ||
79 | #include <sys/types.h> | ||
80 | #include <sys/times.h> | ||
81 | #endif | ||
82 | |||
83 | /* Depending on the VMS version, the tms structure is perhaps defined. | ||
84 | The __TMS macro will show if it was. If it wasn't defined, we should | ||
85 | undefine TIMES, since that tells the rest of the program how things | ||
86 | should be handled. -- Richard Levitte */ | ||
87 | #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS) | ||
88 | #undef TIMES | ||
89 | #endif | ||
90 | |||
91 | #ifndef TIMES | ||
92 | #include <sys/timeb.h> | ||
93 | #endif | ||
94 | |||
95 | #if defined(sun) || defined(__ultrix) | ||
96 | #define _POSIX_SOURCE | ||
97 | #include <limits.h> | ||
98 | #include <sys/param.h> | ||
99 | #endif | ||
100 | |||
101 | #include <openssl/blowfish.h> | ||
102 | |||
103 | #define BF_DEFAULT_OPTIONS | ||
104 | |||
105 | #undef BF_ENC | ||
106 | #define BF_encrypt BF_encrypt_normal | ||
107 | #undef HEADER_BF_LOCL_H | ||
108 | #include "bf_enc.c" | ||
109 | |||
110 | #define BF_PTR | ||
111 | #undef BF_PTR2 | ||
112 | #undef BF_ENC | ||
113 | #undef BF_encrypt | ||
114 | #define BF_encrypt BF_encrypt_ptr | ||
115 | #undef HEADER_BF_LOCL_H | ||
116 | #include "bf_enc.c" | ||
117 | |||
118 | #undef BF_PTR | ||
119 | #define BF_PTR2 | ||
120 | #undef BF_ENC | ||
121 | #undef BF_encrypt | ||
122 | #define BF_encrypt BF_encrypt_ptr2 | ||
123 | #undef HEADER_BF_LOCL_H | ||
124 | #include "bf_enc.c" | ||
125 | |||
126 | /* The following if from times(3) man page. It may need to be changed */ | ||
127 | #ifndef HZ | ||
128 | # ifndef CLK_TCK | ||
129 | # ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ | ||
130 | # define HZ 100.0 | ||
131 | # else /* _BSD_CLK_TCK_ */ | ||
132 | # define HZ ((double)_BSD_CLK_TCK_) | ||
133 | # endif | ||
134 | # else /* CLK_TCK */ | ||
135 | # define HZ ((double)CLK_TCK) | ||
136 | # endif | ||
137 | #endif | ||
138 | |||
139 | #define BUFSIZE ((long)1024) | ||
140 | long run=0; | ||
141 | |||
142 | double Time_F(int s); | ||
143 | #ifdef SIGALRM | ||
144 | #if defined(__STDC__) || defined(sgi) | ||
145 | #define SIGRETTYPE void | ||
146 | #else | ||
147 | #define SIGRETTYPE int | ||
148 | #endif | ||
149 | |||
150 | SIGRETTYPE sig_done(int sig); | ||
151 | SIGRETTYPE sig_done(int sig) | ||
152 | { | ||
153 | signal(SIGALRM,sig_done); | ||
154 | run=0; | ||
155 | #ifdef LINT | ||
156 | sig=sig; | ||
157 | #endif | ||
158 | } | ||
159 | #endif | ||
160 | |||
161 | #define START 0 | ||
162 | #define STOP 1 | ||
163 | |||
164 | double Time_F(int s) | ||
165 | { | ||
166 | double ret; | ||
167 | #ifdef TIMES | ||
168 | static struct tms tstart,tend; | ||
169 | |||
170 | if (s == START) | ||
171 | { | ||
172 | times(&tstart); | ||
173 | return(0); | ||
174 | } | ||
175 | else | ||
176 | { | ||
177 | times(&tend); | ||
178 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
179 | return((ret == 0.0)?1e-6:ret); | ||
180 | } | ||
181 | #else /* !times() */ | ||
182 | static struct timeb tstart,tend; | ||
183 | long i; | ||
184 | |||
185 | if (s == START) | ||
186 | { | ||
187 | ftime(&tstart); | ||
188 | return(0); | ||
189 | } | ||
190 | else | ||
191 | { | ||
192 | ftime(&tend); | ||
193 | i=(long)tend.millitm-(long)tstart.millitm; | ||
194 | ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; | ||
195 | return((ret == 0.0)?1e-6:ret); | ||
196 | } | ||
197 | #endif | ||
198 | } | ||
199 | |||
200 | #ifdef SIGALRM | ||
201 | #define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10); | ||
202 | #else | ||
203 | #define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb); | ||
204 | #endif | ||
205 | |||
206 | #define time_it(func,name,index) \ | ||
207 | print_name(name); \ | ||
208 | Time_F(START); \ | ||
209 | for (count=0,run=1; COND(cb); count+=4) \ | ||
210 | { \ | ||
211 | unsigned long d[2]; \ | ||
212 | func(d,&sch); \ | ||
213 | func(d,&sch); \ | ||
214 | func(d,&sch); \ | ||
215 | func(d,&sch); \ | ||
216 | } \ | ||
217 | tm[index]=Time_F(STOP); \ | ||
218 | fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \ | ||
219 | tm[index]=((double)COUNT(cb))/tm[index]; | ||
220 | |||
221 | #define print_it(name,index) \ | ||
222 | fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \ | ||
223 | tm[index]*8,1.0e6/tm[index]); | ||
224 | |||
225 | int main(int argc, char **argv) | ||
226 | { | ||
227 | long count; | ||
228 | static unsigned char buf[BUFSIZE]; | ||
229 | static char key[16]={ 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | ||
230 | 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}; | ||
231 | BF_KEY sch; | ||
232 | double d,tm[16],max=0; | ||
233 | int rank[16]; | ||
234 | char *str[16]; | ||
235 | int max_idx=0,i,num=0,j; | ||
236 | #ifndef SIGALARM | ||
237 | long ca,cb,cc,cd,ce; | ||
238 | #endif | ||
239 | |||
240 | for (i=0; i<12; i++) | ||
241 | { | ||
242 | tm[i]=0.0; | ||
243 | rank[i]=0; | ||
244 | } | ||
245 | |||
246 | #ifndef TIMES | ||
247 | fprintf(stderr,"To get the most accurate results, try to run this\n"); | ||
248 | fprintf(stderr,"program when this computer is idle.\n"); | ||
249 | #endif | ||
250 | |||
251 | BF_set_key(&sch,16,key); | ||
252 | |||
253 | #ifndef SIGALRM | ||
254 | fprintf(stderr,"First we calculate the approximate speed ...\n"); | ||
255 | count=10; | ||
256 | do { | ||
257 | long i; | ||
258 | unsigned long data[2]; | ||
259 | |||
260 | count*=2; | ||
261 | Time_F(START); | ||
262 | for (i=count; i; i--) | ||
263 | BF_encrypt(data,&sch); | ||
264 | d=Time_F(STOP); | ||
265 | } while (d < 3.0); | ||
266 | ca=count; | ||
267 | cb=count*3; | ||
268 | cc=count*3*8/BUFSIZE+1; | ||
269 | cd=count*8/BUFSIZE+1; | ||
270 | |||
271 | ce=count/20+1; | ||
272 | #define COND(d) (count != (d)) | ||
273 | #define COUNT(d) (d) | ||
274 | #else | ||
275 | #define COND(c) (run) | ||
276 | #define COUNT(d) (count) | ||
277 | signal(SIGALRM,sig_done); | ||
278 | alarm(10); | ||
279 | #endif | ||
280 | |||
281 | time_it(BF_encrypt_normal, "BF_encrypt_normal ", 0); | ||
282 | time_it(BF_encrypt_ptr, "BF_encrypt_ptr ", 1); | ||
283 | time_it(BF_encrypt_ptr2, "BF_encrypt_ptr2 ", 2); | ||
284 | num+=3; | ||
285 | |||
286 | str[0]="<nothing>"; | ||
287 | print_it("BF_encrypt_normal ",0); | ||
288 | max=tm[0]; | ||
289 | max_idx=0; | ||
290 | str[1]="ptr "; | ||
291 | print_it("BF_encrypt_ptr ",1); | ||
292 | if (max < tm[1]) { max=tm[1]; max_idx=1; } | ||
293 | str[2]="ptr2 "; | ||
294 | print_it("BF_encrypt_ptr2 ",2); | ||
295 | if (max < tm[2]) { max=tm[2]; max_idx=2; } | ||
296 | |||
297 | printf("options BF ecb/s\n"); | ||
298 | printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]); | ||
299 | d=tm[max_idx]; | ||
300 | tm[max_idx]= -2.0; | ||
301 | max= -1.0; | ||
302 | for (;;) | ||
303 | { | ||
304 | for (i=0; i<3; i++) | ||
305 | { | ||
306 | if (max < tm[i]) { max=tm[i]; j=i; } | ||
307 | } | ||
308 | if (max < 0.0) break; | ||
309 | printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0); | ||
310 | tm[j]= -2.0; | ||
311 | max= -1.0; | ||
312 | } | ||
313 | |||
314 | switch (max_idx) | ||
315 | { | ||
316 | case 0: | ||
317 | printf("-DBF_DEFAULT_OPTIONS\n"); | ||
318 | break; | ||
319 | case 1: | ||
320 | printf("-DBF_PTR\n"); | ||
321 | break; | ||
322 | case 2: | ||
323 | printf("-DBF_PTR2\n"); | ||
324 | break; | ||
325 | } | ||
326 | exit(0); | ||
327 | #if defined(LINT) || defined(OPENSSL_SYS_MSDOS) | ||
328 | return(0); | ||
329 | #endif | ||
330 | } | ||