Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/mty-makai/mty.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 223 - (hide annotations) (download) (as text)
Fri May 15 09:22:32 2009 UTC (14 years, 10 months ago) by notanpe
File MIME type: text/x-csrc
File size: 48729 byte(s)
全空間テストその2
1 chapuni 1 /***********************************************************************
2     *
3 chapuni 26 * file: mty.c
4 chapuni 1 *
5 chapuni 2 * ‚Ü‚ A‘Ň‚Ä‰ŽB
6 chapuni 1 *
7     * $Id$
8     *
9     */
10    
11     #include <assert.h>
12     #include <ctype.h>
13 chapuni 24 #include <errno.h>
14 chapuni 9 #include <limits.h>
15 chapuni 24 #include <stdarg.h>
16 chapuni 20 #include <stddef.h>
17 chapuni 1 #include <stdio.h>
18     #include <stdlib.h>
19     #include <string.h>
20     #include <time.h>
21 notanpe 192 #include <sys/timeb.h>
22 notanpe 148 #include <sys/types.h>
23 chapuni 10
24 notanpe 197 /* MAKAI start */
25     #include <unistd.h>
26     #include <libgen.h>
27 notanpe 203 #include <limits.h>
28 notanpe 213 #ifdef REON
29     #ifdef ONI
30     #include <onigposix.h>
31     #else /* ONI */
32     /* #include <rxposix.h> */
33     #include <regex.h>
34     #endif /* ONI */
35     #endif /* REON */
36 notanpe 197 /* MAKAI end */
37    
38 chapuni 10 #if defined(WIN32)
39    
40     #include <windows.h>
41 notanpe 148 #include <process.h>
42 chapuni 10
43     #elif defined(__GNUC__)
44    
45     #include <sys/time.h>
46    
47     #endif
48    
49 chapuni 26 #include "config.h"
50 chapuni 39 #include "cp932.h"
51 chapuni 1 #include "crypt64.h"
52 chapuni 41 #include "desconst.h"
53 chapuni 46 #include "expr_parse.h"
54     #include "scoreboard.h"
55     #include "synth.h"
56 chapuni 74 #include "tr64.h"
57 chapuni 26 #include "translate.h"
58 notanpe 148 #include "util.h"
59 chapuni 99 #include "wdict.h"
60 chapuni 1
61 notanpe 197 /* MAKAI start */
62 notanpe 198 #define TRIP_LEN 10
63    
64 notanpe 197 #define MIN_THREAD 1
65     #define MAX_THREAD 32
66     int nThread = 0;
67 notanpe 199 uint64_t pmask = 0;
68 notanpe 197
69     #define MIN_UME 3
70     #define MAX_UME 6
71     unsigned char umeStr[10];
72     int umeLen;
73 notanpe 198
74 notanpe 204 FILE *nfp; /* ‘S” */
75     FILE *tfp; /* ŞˆČŠO‚Ě“ÁŽęŒŸő */
76 notanpe 218 #ifdef CHIN
77     FILE *cfp; /* ‚ż */
78     #endif /* CHIN */
79 notanpe 213 #ifdef REON
80     FILE *rfp; /* ł‹K•\Œť */
81     #endif /* REON */
82 notanpe 203
83 notanpe 214 /*
84     Cygwin 32bit
85     time_t = long = int
86     INT_MIN -2147483648
87     INT_MAX 2147483647
88     (2009 - 1970) * 365 * 24 * 60 * 60 = 1229904000
89     2147483647 - 1229904000 = 917579647
90     10y * 365 * 24 * 60 * 60 = 315360000
91 notanpe 217
92     perl -e 'use POSIX;printf(strftime("%Y/%m/%d %T\n",localtime (1234567890)));'
93 notanpe 214 */
94     #define MIN_SOFF -1229904000
95     #define MAX_SOFF 315360000
96 notanpe 203 unsigned int seed;
97 notanpe 214 int seedOffset;
98 notanpe 203 int verbose;
99 notanpe 197 /* MAKAI end */
100    
101 notanpe 192 /* CRYPT64 ‹LqŽq */
102     static
103     struct CRYPT64_DESC const *const crypt64_descs[] =
104     {
105     &crypt64_desc,
106     };
107    
108 chapuni 1 /* ŒŽƒNƒ‰ƒX */
109 chapuni 41 static
110 chapuni 1 struct
111     {
112 notanpe 148 unsigned short map[256];
113 notanpe 223 } kcls[8 + 8]; /* atode ‚Č‚ş 8 + 8 ? */
114 chapuni 1
115 chapuni 26 /* Šg’ŁŒŽƒNƒ‰ƒX */
116 chapuni 1 #define KCLS_DT0 64
117     #define KCLS_DT1 128
118     #define KCLS_K2 256
119    
120 notanpe 198 /* MAKAI start */
121     int special = 0;
122 notanpe 207 #define ST_ALLN 1 /* ‘S” */
123     #define ST_NIKO 1<<0x1 /* “ń\ */
124     #define ST_BUOO 1<<0x8 /* ‚Ô‚¨ */
125     #define ST_DOSU 1<<0x9 /* “{” */
126     #define ST_HREN 1<<0xd /* ”ň˜A */
127 notanpe 222 #define ST_CHIN 1<<0xb /* ^Chinko Uni ‚Ĺ‚Í Š´’Q—p‚Ěƒtƒ‰ƒO */
128 notanpe 198
129 notanpe 213 #ifdef REON
130     #define REGEXPLEN 1024
131     char regExpStr[REGEXPLEN];
132     regex_t regExp;
133     #endif /* REON */
134    
135 notanpe 198 void
136     comment( str )
137     char *str;
138     {
139     if ( strlen( str ) >= 4 ) {
140     if ( str[1] == '[' && str[3] == ']' ) {
141     switch ( str[2] ) {
142 notanpe 203 case '0': special |= ST_ALLN; break;
143     case '1': special |= ST_NIKO; break;
144     case '8': special |= ST_BUOO; break;
145 notanpe 204 case '9': special |= (ST_DOSU | ST_ALLN); break;
146 notanpe 207 case 'd': special |= ST_HREN; break;
147 notanpe 214 case 'S':
148     seedOffset = atoi( str + 4 );
149     if ( seedOffset < MIN_SOFF || seedOffset > MAX_SOFF ) {
150     fprintf( stderr, "—”‚ĚŽí‚ĚƒIƒtƒZƒbƒg‚́A%d ˆČă %d ˆČ‰ş‚ĹŽw’肾‚ĂˁB\n", MIN_SOFF, MAX_SOFF );
151     fprintf( stderr, "%d ‚͔͈͊O‚Ȃ̂ŖłŽ‹‚ľ‚Ü‚ˇB\n", seedOffset );
152     seedOffset = 0;
153     }
154     break;
155 notanpe 213 case 'R':
156     #ifdef REON
157     if ( strlen( str ) >= REGEXPLEN ) {
158     fprintf( stderr, "ł‹K•\Œť (%s) ‚Ş’ˇ‚ˇ‚Ź", str );
159     exit( 1 );
160     }
161     strcpy( regExpStr, str + 4 );
162     if ( regcomp( &regExp, regExpStr, REG_NOSUB|REG_EXTENDED ) != 0 ) {
163     fprintf( stderr, "ł‹K•\Œť (%s) ‚Ş‚¨‚Š‚ľ‚˘H\n", str );
164     exit( 1 );
165     }
166     #else /* REON */
167     fprintf( stderr, "‚ą‚ĚƒoƒCƒiƒŠ‚́Ał‹K•\Œť‚đƒTƒ|[ƒg‚ľ‚Ä‚˘‚Ü‚š‚ńB\n" );
168     fprintf( stderr, "%s ‚Í–łŽ‹‚ľ‚Ü‚ˇB\n", str );
169     #endif /* REON */
170     break;
171 notanpe 198 }
172     }
173     }
174     }
175     /* MAKAI end */
176    
177 chapuni 1 /* Žw’肳‚ę‚˝ƒNƒ‰ƒX‚Ć“ü‚Á‚Ä‚˘‚éƒL[‚Š‚çAclassify ‚đs‚¤ */
178     void
179 notanpe 148 key_make_map(uint8_t *key, int n)
180 chapuni 1 {
181     int i, j;
182     unsigned c = kcls[n].map[key[n]];
183    
184     /* ĹŒă‚Ě•”•Ş‚Í class map ‚đśŹ‚ˇ‚é•K—vƒiƒV */
185     if (n >= 6)
186     return;
187    
188     for (i = 0; i < 256; i++)
189     {
190 chapuni 25 unsigned bm = 0;
191 chapuni 1 #if 1
192     if (c & KCLS_K1)
193     {
194     if (cp932[256 * key[n] + i] & KCLS_K1)
195     bm |= KCLS_K2 | (cp932[256 * key[n] + i] & KCLS_DT1);
196     if (cp932[256 * (key[n] ^ 0x80) + i] & KCLS_K1)
197     bm |= KCLS_K2 | (cp932[256 * (key[n] ^ 0x80) + i] & KCLS_DT1);
198     #if 0
199     bm |= ((cp932[256 * key[n] + i] & KCLS_K1)
200     || (cp932[256 * (key[n] ^ 0x80) + i] & KCLS_K1)
201     ? KCLS_K2 : 0);
202     #endif
203     }
204     if (c & (KCLS_AN | KCLS_KA | KCLS_K2))
205     for (j = 0; j < 256; j++)
206     {
207 notanpe 222 bm |= cp932[256 * i + j] & (KCLS_AN | KCLS_KA | KCLS_K1 | KCLS_DT0);
208 chapuni 1 #if 0
209     if (j >= 127 && !(n == 0 || n == 1))
210     break;
211     #endif
212     }
213     kcls[n + 1].map[i] = bm;
214     #endif
215     if (i >= 128 && !(n == 0 || n == 1))
216     kcls[n + 1].map[i - 128] |= kcls[n + 1].map[i];
217     }
218    
219     if (n < 6)
220 notanpe 223 /* MAKAI start */
221     #ifdef ALKEY
222     kcls[n + 1].map[0x00] = 0;
223     #else /* ALLKEY */
224 chapuni 1 kcls[n + 1].map[0x00] = kcls[n + 1].map[0x80] = 0;
225 notanpe 223 #endif /* ALLKEY */
226     /* MAKAI end */
227 chapuni 1 if (n == 6)
228     kcls[7].map[0x00] |= KCLS_AN;
229     }
230    
231     /* ƒ}ƒbƒv‚Š‚ç•śŽš‚đE‚Á‚ăZƒbƒg */
232     unsigned
233     key_set(int n, unsigned ch)
234     {
235     int cnt = 0, i;
236    
237     #if DEBUG>=3
238     if (cnt == 0)
239     {
240     printf("n=%d, ch=%d, (n-1)=%02X\n", n, ch, key[n - 1]);
241     int j;
242     for (i = 0; i < 16; i++)
243     {
244     printf("map[0x%02X] =", 16 * i);
245     for (j = 0; j < 16; j++)
246     printf(" %03X", kcls[n].map[16 * i + j]);
247     printf("\n");
248     }
249     }
250     #endif
251 notanpe 223
252     /* MAKAI start */
253     #ifdef NOMORE
254     /* if ( ch != 0 ) printf( "ch = %d -> ", ch ); */
255     ch %= 256;
256     /* if ( ch != 0 ) printf( "%d\n", ch ); */
257     #endif /* NOMORE */
258     /* MAKAI end */
259    
260 chapuni 1 for (i = 0; i < 256; i++)
261     {
262     if (kcls[n].map[i])
263     {
264     if (ch-- == 0)
265     return i;
266     cnt++;
267     }
268 notanpe 223 /* MAKAI start */
269     #ifdef ALLKEY
270     if (n != 1 && n != 2 && i >= 128)
271     break;
272     #else /* ALLKEY */
273 chapuni 1 if (n != 1 && n != 2 && i >= 127)
274     break;
275 notanpe 223 #endif /* ALLKEY */
276     /* MAKAI end */
277 chapuni 1 }
278     /* ŒŠ‚Â‚Š‚ç‚ȂЂÁ‚˝‚Ě‚Ĺ‚ŕ‚˘‚Á‚Ř‚ń */
279     assert(cnt > 0);
280     ch %= cnt;
281     for (i = 0; i < 256; i++)
282     if (kcls[n].map[i])
283     {
284     if (ch-- == 0)
285     return i;
286     }
287     assert(!"not matched");
288     return 0;
289     }
290    
291     /* bitwise key ‚đƒZƒbƒg */
292     static
293     void
294     key_set64(struct KEY *key64,
295     int n,
296     unsigned k,
297     unsigned vk,
298     unsigned sk)
299     {
300 chapuni 6 int i, j;
301 chapuni 1 if (!((vk | sk) & 0x7F))
302     return;
303    
304     for (i = 0; i < 7; i++)
305     {
306 chapuni 6 if (n == 7 && i < N_STRIDE) continue;
307 chapuni 1 if (sk & (1 << i))
308     {
309     /* ƒZƒbƒg */
310     int o = tr_pc1[n][6 - i] - 1;
311     if (o < 28)
312     {
313     assert(o >= 0);
314 chapuni 6 for (j = 0; j < N_ALU; j++)
315     key64->k[0][0][o].a[j]
316     = key64->k[0][1][o].a[j]
317     = -!!(k & (1 << i));
318 chapuni 1 }
319     else
320     {
321     assert(o >= 28);
322     assert(o < 56);
323 chapuni 6 for (j = 0; j < N_ALU; j++)
324     key64->k[1][0][o - 28].a[j]
325     = key64->k[1][1][o - 28].a[j]
326     = -!!(k & (1 << i));
327 chapuni 1 }
328     }
329     else if (vk & (1 << i))
330     {
331     /* ”˝“] */
332     int o = tr_pc1[n][6 - i] - 1;
333     if (o < 28)
334     {
335     assert(o >= 0);
336 chapuni 10 for (j = 0; j < N_ALU; j++)
337     key64->k[0][0][o].a[j]
338     = key64->k[0][1][o].a[j]
339     = ~key64->k[0][0][o].a[j];
340 chapuni 1 }
341     else
342     {
343     assert(o >= 28);
344     assert(o < 56);
345 chapuni 10 for (j = 0; j < N_ALU; j++)
346     key64->k[1][0][o - 28].a[j]
347     = key64->k[1][1][o - 28].a[j]
348     = ~key64->k[1][0][o - 28].a[j];
349 chapuni 1 }
350     }
351     }
352     }
353    
354     /* Žw’肳‚ę‚˝ƒNƒ‰ƒX‚ĚŠJŽn’l‚ÉƒŠƒZƒbƒg
355     ’ź‘O‚Ě•śŽš‚ĚƒNƒ‰ƒX‚É”›‚ç‚ę‚é */
356     int
357 notanpe 148 key_reset(uint8_t *key, int n)
358 chapuni 1 {
359 notanpe 197 /* MAKAI start */
360     static char firstCall = 1;
361    
362     if ( firstCall ) {
363     firstCall = 0;
364     } else {
365     if ( umeStr[0] != '\0' && n == 0 ) {
366     exit( 0 );
367     }
368     }
369     /* MAKAI end */
370    
371 chapuni 1 if (n >= 8)
372     return 1;
373     if (n == 7)
374     {
375     key[7] = 0;
376     return 1;
377     }
378    
379 notanpe 197 /* MAKAI start */
380     if (n >= umeLen)
381 chapuni 1 key[n] = key_set(n, 0);
382 notanpe 197 else {
383     if ( umeStr[0] == '\0' ) {
384 notanpe 223 #ifdef ALLKEY
385     key[n] = key_set(n, rand()); /* atode +1 ‚Í—v‚é‚Ě‚Š ? */
386     #else /* ALLKEY */
387 notanpe 197 key[n] = key_set(n, rand());
388 notanpe 223 #endif /* ALLKEY */
389 notanpe 197 } else {
390     key[n] = umeStr[n];
391     }
392     }
393     /* MAKAI end */
394 chapuni 1
395     #if DEBUG>=3
396     printf("key[%d]=%02X ncls=%04X\n", n, key[n], kcls[n].map[key[n]]);
397     #endif
398    
399 notanpe 223 /* MAKAI start */
400     #ifndef ALLKEY
401 chapuni 1 /* ƒZƒbƒg‚ł‚ę‚˝•śŽš‚đŒł‚ÉAŽŸƒLƒƒƒ‰‚Ě•śŽšƒNƒ‰ƒX‚đŒˆ‚ß‚é */
402 notanpe 148 key_make_map(key, n);
403 notanpe 223 #endif /* not ALLKEY */
404     /* MAKAI end */
405 chapuni 1
406 notanpe 148 return key_reset(key, n + 1);
407 chapuni 1 }
408    
409     /* Žw’肳‚ę‚˝ŒŽ‹óŠÔ‚Ě’†‚ŁAƒL[‚đ‚ЂƂi‚ß‚é
410     ˆŔ‘S‚ɃCƒ“ƒNƒŠƒƒ“ƒg‚Ĺ‚Ť‚˝ę‡ true ‚đ•Ô‚ˇ */
411     static
412     int
413 notanpe 148 key_inc(uint8_t *key, int n)
414 chapuni 1 {
415     if (n >= 8)
416     return 0;
417     else if (n == 7)
418     {
419 chapuni 6 /* ĹŒă‚ĚƒoƒCƒg */
420 notanpe 148 uint8_t o_k = (key[7] + (1 << N_STRIDE)) & 0x7F;
421     if (!o_k)
422     return 0; /* ƒCƒ“ƒNƒŠƒƒ“ƒg‚Ĺ‚Ť‚ȂЂÁ‚˝‚Ć‚Ť‚ÍŽŸ‚֐i‚ß‚¸‘҂ */
423    
424     /* i‚ß‚é */
425     key[7] = o_k;
426     return 1;
427 chapuni 1 }
428 notanpe 148 else if (key_inc(key, n + 1)
429 chapuni 1 /*
430     && key_inc(n + 1)
431     && key_inc(n + 1)
432     && key_inc(n + 1)*/
433     )
434     return 1;
435    
436     /* Salt ‚̓Cƒ“ƒNƒŠƒƒ“ƒg‚ľ‚Č‚˘–ń‘Ђɂˇ‚é */
437     if (n == 1 || n == 2)
438     return 1;
439    
440     #if DEBUG>=3
441     printf("key_inc(n=%d,ck=%02X)\n", n, key[n]);
442     #endif
443    
444     /* ŽŔŰ‚É‘‚₾‚Ă݂é */
445     assert(n >= 3);
446     for (;;)
447     {
448     if (n <= 3
449     && !(key[n] & 0x80)
450     && kcls[n].map[key[n] ^ 0x80] & (KCLS_DT0))
451     {
452     /* ”źŠpƒJƒ^ƒJƒi‚Ě1ƒoƒCƒg–Ú */
453     key[n] ^= 0x80;
454     }
455     else
456     {
457     key[n] = (key[n] & 0x7F) + 1;
458     if (key[n] >= 0x80)
459 notanpe 148 {
460     key[n] = 0xFF; /* ŽŸ‚ɓ˓ü‚ł‚š‚Č‚˘‚˝‚ß */
461     return 0;
462     }
463 chapuni 1 }
464    
465     if (kcls[n].map[key[n]])
466     {
467 notanpe 223 /* MAKAI start */
468     #ifndef ALLKEY
469 notanpe 148 key_make_map(key, n);
470 notanpe 223 #endif /* not ALLKEY */
471     /* MAKAI end */
472 notanpe 148 key_reset(key, n + 1);
473 chapuni 1 return 1;
474     }
475     }
476     }
477    
478     /* ŒŽ‚đŠŽ‘S‚ÉƒŠƒZƒbƒg‚ˇ‚é
479     Salt‚ŕƒZƒbƒg‚ľ’ꂎ */
480     static
481     void
482 notanpe 148 key_init(uint8_t *key)
483 chapuni 1 {
484     int i, j;
485    
486     key[8] = 0;
487    
488     /* ‰Šúƒ}ƒbƒv‚đ‘g‚Ţ */
489 notanpe 222 for ( i = 0; i < 256; i++ ) {
490     unsigned bm = 0;
491 chapuni 1
492 notanpe 222 for ( j = 0; j < 256; j++ ) {
493     bm |= cp932[256 * i + j];
494     }
495     kcls[0].map[i] = bm & (KCLS_AN | KCLS_KA | KCLS_K1);
496     if ( i >= 128 ) {
497     kcls[0].map[i - 128] |= kcls[0].map[i];
498     }
499     }
500    
501 notanpe 223 /* MAKAI start */
502     #ifdef ALLKEY
503     {
504     int idx;
505     kcls[0].map[0] = 0;
506     for ( idx = 1; idx < 8; idx++ ) {
507     for ( i = 0; i < 256; i++ ) {
508     unsigned bm = 0;
509    
510     for ( j = 0; j < 256; j++ ) {
511     bm |= cp932[256 * i + j];
512     }
513     kcls[idx].map[i] = bm & (KCLS_AN | KCLS_KA | KCLS_K1);
514     if ( i > 128 ) {
515     kcls[idx].map[i - 128] |= kcls[idx].map[i];
516     }
517     }
518     }
519     }
520     #endif /* ALLKEY */
521     /* MAKAI end */
522    
523 notanpe 148 key_reset(key, 0);
524 chapuni 1 }
525    
526     /***************************************************************
527     *
528 chapuni 122 * ŒĹ’čƒL[‚̐śŹ
529     *
530     * ˆęŒŠ Big Endian ‚É”ń‘Ήž‚̂悤‚ÉŒŠ‚Ś‚é‚ž‚낤‚Ş
531     * Š‚łɎU‚ç‚΂Á‚Ä‚˘‚é kludge ‚É‚ć‚č
532     * ALU_T ‚Ş 64 ƒrƒbƒg‚Ĺ‚ ‚éŒŔ‚čA‚ą‚ę‚Ĺ–â‘č‚Č‚­“Ž‚­B
533     *
534     */
535    
536     static
537     void
538     key_init_sk(struct KEY *key)
539     {
540     int i, j;
541     int o;
542     uint64_t m;
543    
544     for (i = 5, m = 0xFFFFFFFF00000000ULL;
545     i >= 0;
546     m ^= (m >> (1 << --i)))
547     {
548     o = tr_pc1[7][6 - i] - 1;
549 chapuni 123 #if DEBUG>=2
550 chapuni 122 printf("%d:%d->%2d: %08X%08X\n",
551     N_Q, i, o,
552     (unsigned)(m >> 32),
553     (unsigned)m);
554 chapuni 123 #endif
555 chapuni 122 for (j = 0; j < N_Q; j++)
556     if (o < 28)
557     key->k[0][0][o ].q[j] = key->k[0][1][o ].q[j] = m;
558     else
559     key->k[1][0][o - 28].q[j] = key->k[1][1][o - 28].q[j] = m;
560     }
561     #if N_STRIDE==7
562     /* bit 6 ‚Í Little Endian ‚Ć‚ľ‚Ĉľ‚¤ */
563     o = 0;
564     assert(tr_pc1[7][0] - 1 == o);
565     assert(N_Q == 2);
566     key->k[0][0][o].q[0] = key->k[0][1][o].q[0] = 0x0000000000000000ULL;
567     key->k[0][0][o].q[1] = key->k[0][1][o].q[1] = 0xFFFFFFFFFFFFFFFFULL;
568     #endif
569     }
570    
571     /***************************************************************
572     *
573 chapuni 1 * Salt ‚ĚƒZƒbƒg
574     * ƒIƒyƒ‰ƒ“ƒh‚ĚƒIƒtƒZƒbƒg‚đ‘‚ŤŠˇ‚ڂĉń‚Á‚Ä‚é‚̂ŒˆÓ
575     *
576     */
577    
578     void
579 notanpe 148 set_salt(CODE_T *code,
580 notanpe 192 struct CRYPT64_DESC const *desc,
581 notanpe 148 uint8_t const *k)
582 chapuni 1 {
583     int i, j;
584    
585     for (i = 0; i < 2; i++)
586     {
587     unsigned s = k[1 + i] & 255;
588     if (s > 'z')
589     s = 0;
590     else if (s >= 'a')
591     s = s - 'a' + 2 + 10 + 26;
592     else if (s >= 'A')
593     s = s - 'A' + 2 + 10;
594     else if (s >= '.')
595     s = s - '.';
596     else
597     s = 0;
598    
599     #if DEBUG>=1
600     printf("Salt %d:%3o\n", i, s & 63);
601     #endif
602     for (j = 0; j < 6; j++)
603     {
604     #if DEBUG>=2
605 chapuni 6 //printf("Salt %d:%d %+3d:%+3d",
606     printf("Salt %d:%d %08lX:%08lX",
607 chapuni 1 i, j,
608 notanpe 192 LSALT(desc, code, 0, i, j, 0),
609     LSALT(desc, code, 0, i, j, 24));
610 chapuni 1 #endif
611     if (s & (1 << j))
612     {
613 notanpe 192 LSALT(desc, code, 0, i, j, 0) = sizeof(WS_T) * (((4 * i + j + 15) & 31) - 16);
614     LSALT(desc, code, 0, i, j, 24) = sizeof(WS_T) * (((4 * i + j - 1) & 31) - 16);
615 chapuni 1 }
616     else
617     {
618 notanpe 192 LSALT(desc, code, 0, i, j, 0) = sizeof(WS_T) * (((4 * i + j - 1) & 31) - 16);
619     LSALT(desc, code, 0, i, j, 24) = sizeof(WS_T) * (((4 * i + j + 15) & 31) - 16);
620 chapuni 1 }
621 notanpe 192 LSALT(desc, code, 0, i, j, 12) = sizeof(WS_T) * (((4 * i + j + 7) & 31) - 16);
622     LSALT(desc, code, 0, i, j, 36) = sizeof(WS_T) * (((4 * i + j + 23) & 31) - 16);
623 chapuni 1 #if DEBUG>=2
624 chapuni 6 //printf(" => %+3d:%+3d\n",
625     printf(" => %08lX:%08lX\n",
626 notanpe 192 LSALT(desc, code, 0, i, j, 0),
627     LSALT(desc, code, 0, i, j, 24));
628 chapuni 1 #endif
629     }
630     }
631     }
632    
633 notanpe 192 #define USEC_SEC 1000 /* 1•b */
634    
635 chapuni 1 static
636 notanpe 192 uint64_t
637 notanpe 148 usec(void)
638 notanpe 119 {
639 notanpe 120 uint32_t sec, msec;
640    
641 notanpe 119 #if !defined(WIN32)
642     struct timeval tv;
643     gettimeofday(&tv, NULL);
644 notanpe 120 sec = tv.tv_sec;
645 notanpe 192 msec = tv.tv_usec / (1000000 / USEC_SEC);
646 notanpe 119 #else
647     struct timeb tm;
648     ftime(&tm);
649 notanpe 120 sec = tm.time;
650 notanpe 192 msec = tm.millitm / (1000 / USEC_SEC);
651 notanpe 119 #endif
652 notanpe 120
653 notanpe 192 return (uint64_t)USEC_SEC * sec + msec;
654 notanpe 119 }
655    
656     static
657 chapuni 24 int
658     log_printf(FILE *ofp, char const *fmt, ...)
659     {
660     int r;
661     va_list ap;
662     va_start(ap, fmt);
663 notanpe 204
664     /* MAKAI start */
665     if ( ofp != nfp ) {
666     vfprintf(stdout, fmt, ap);
667     }
668     /* MAKAI end */
669    
670 chapuni 24 r = vfprintf(ofp, fmt, ap);
671     va_end(ap);
672 notanpe 223 #ifdef HITEXIT
673     exit( 0 );
674     #endif /* HITEXIT */
675 chapuni 24 if (r > 0)
676     return r;
677     perror("log_printf");
678     exit(errno);
679     }
680    
681 chapuni 1 /***************************************************************
682     *
683 notanpe 192 * CPU capabilities ‚đŽć“ž
684     * [XXX] ‚ ‚Ü‚č‚É‚ŕŒĂ‚˘ƒvƒƒZƒbƒT‚Ě‚ą‚Ć‚Íl‚ڂȂ˘B
685 chapuni 1 *
686 notanpe 192 * a[4] = {EAX,EBX,ECX,EDX}
687     *
688 chapuni 1 */
689    
690 notanpe 192 #if defined(__GNUC__)
691    
692     #define cpuid(n,a,b,c,d) \
693     asm("cpuid" \
694     : "=a"(a), "=b"(b), "=c"(c), "=d"(d) \
695     : "a"(n))
696    
697     #elif defined(WIN32)
698    
699     #define cpuid(n,a,b,c,d) \
700     do {int r[4]; __cpuid(r,n); \
701     (a) = r[0]; (b) = r[1]; (c) = r[2]; (d) = r[3];} while (0)
702    
703     #endif
704    
705     static
706     unsigned
707     cpuid_getfflags(void)
708 notanpe 148 {
709 notanpe 192 unsigned a, b, c, d;
710     cpuid(1, a, b, c, d);
711     return d;
712     }
713 chapuni 1
714 notanpe 148 static
715 notanpe 192 int
716     cpuid_issupported(void)
717     {
718     unsigned m = REQUIRED_CAPS;
719     return !((cpuid_getfflags() ^ m) & m);
720     }
721    
722     /***************************************************************
723     *
724     * ƒoƒbƒ`ˆ——pƒpƒPƒbƒg
725     *
726     */
727    
728     static
729 notanpe 148 struct PACKET_CRYPT64 *
730     packet_create(int n, /* ƒpƒPƒbƒg” */
731     int tn, /* ––”ö—v‘f‚ɂĕK—v‚Čƒ[ƒN” */
732     uint8_t const *ini_key)
733     {
734     int i;
735     int siz;
736     void *p;
737 notanpe 192 intptr_t a = 128;
738 notanpe 148 struct PACKET_CRYPT64 *pkts;
739     assert(IS_POWER2(sizeof(struct PACKET_CRYPT64)));
740     assert(n >= 1);
741    
742 notanpe 192 siz = (a - 1
743 notanpe 148 + (n - 1) * sizeof(struct PACKET_CRYPT64)
744     + offsetof(struct PACKET_CRYPT64, param64.hit[tn]));
745     p = calloc(siz, 1);
746     /* ƒoƒ“ƒ_ƒŠ‚ ‚킚 */
747     pkts = (struct PACKET_CRYPT64 *)(((intptr_t)p
748 notanpe 192 + a - 1)
749     & -a);
750 notanpe 148 #if DEBUG>=1
751     fprintf(stderr,
752     "packet(n=%d,tn=%d) %d allocated; %p aligned to %p\n",
753     n, tn,
754     siz, p, pkts);
755     #endif
756    
757     /* “ŕ•”‚̏‰Šú‰ť
758     ƒRƒs[‚ľ‚ĉń‚é‚̂́AŒľ–§‚É‚Í
759     ĹI—v‘f‚ĚƒPƒc‚đ”j‚Á‚Ä‚ľ‚Ü‚¤‚ą‚ƂɂȂé‚Ě‚Ĺ
760     ‚Ç‚¤‚š‘Ź“x‚ŕ—v‹‚ł‚ę‚Č‚˘‚ľƒxƒ^ƒR[ƒh */
761     for (i = 0; i < n; i++)
762     {
763 notanpe 192 int j, k;
764 notanpe 148
765     /* t[16] ‚́A“ŕ•”‰‰ŽZ‚ĹŽg—p‚ˇ‚éAall 1 ‚Ş“ü‚Á‚Ä‚˘‚é */
766     memset(&pkts[i].param64.t[T_INV], -1, sizeof(SLICE));
767    
768     /* ŒĹ’čƒL[‚̐śŹ */
769     key_init_sk(&pkts[i].key64);
770    
771     /* ƒL[ƒXƒPƒWƒ…[ƒ‹‚đ‚ą‚ą‚ɉŸ‚ľž‚߂è‚­
772     ]—ˆ‚Í crypt64.S “ŕ‚ĹŠŽŒ‹‚ˇ‚é‚悤‚Ɉř‚˘‚Ä‚˘‚˝ */
773     for (j = 0; j < 28; j++)
774 notanpe 192 for (k = 0; k < N_ALU; k++)
775     pkts[i].key64.ks[j].a[k] = sizeof(WS_T) * ks_ls[j];
776 notanpe 148
777     /* ”O‚Ě‚˝‚߁AŒŽ‚đ‚ą‚ą‚Ĺ—Ž‚ż’…‚݂è‚­(•s—v?) */
778     for (j = 0; j < 8; j++)
779     key_set64(&pkts[i].key64, j, pkts[i].uk.key[j] = ini_key[j], 0, 0x7F);
780     }
781    
782     return pkts;
783     }
784    
785     /***************************************************************
786     *
787     * thread
788     *
789     */
790    
791     #define NQ_CRYPT 64
792     #define NQ_CMP 32
793    
794     #if defined(__GNUC__)
795    
796     typedef int32_t ATOMWORD_T;
797    
798     #define LOCK_INC(p) \
799     asm volatile ("lock incl %0" \
800     : "=m"(*(p)) \
801     : /*nil*/ \
802     : "memory")
803    
804     #define LOCK_DEC(p) \
805     asm volatile ("lock decl %0" \
806     : "=m"(*(p)) \
807     : /*nil*/ \
808     : "memory")
809    
810     #define LOCK_CAS(pd,s,r) \
811     ({ ATOMWORD_T a; \
812     asm volatile ("lock cmpxchg %2,%1" \
813     : "=a"(a) \
814     : "m"(*(pd)), "r"(s), "0"(r) \
815     : "memory");a;})
816    
817     #define LOCK_CASP(pd,s,r) \
818     ({ void *a; \
819     asm volatile ("lock cmpxchg %2,%1" \
820     : "=a"(a) \
821     : "m"(*(pd)), "r"(s), "0"(r) \
822     : "memory");a;})
823    
824     #elif defined(WIN32)
825    
826     typedef LONG ATOMWORD_T;
827    
828     #define LOCK_INC(p) InterlockedIncrement((LONG *)(p))
829     #define LOCK_DEC(p) InterlockedDecrement((LONG *)(p))
830     #define LOCK_CAS(pd,s,r) InterlockedCompareExchange((LONG *)(pd), s, r)
831     #define LOCK_CASP(pd,s,r) InterlockedCompareExchangePointer((PVOID *)(pd), (PVOID)(s), (PVOID)r)
832    
833     #else
834     #error "configuration not implemented"
835     #endif
836    
837     #if defined(WIN32)
838    
839     typedef DWORD THREAD_TIMEOUT_T;
840    
841     #define THREAD_INFINITE INFINITE
842    
843     typedef HANDLE THREAD_TH_T;
844     typedef HANDLE THREAD_EV_T;
845    
846     #define thread_sleep(n) Sleep(n)
847     #define thread_create(th, proc, arg) {(th) = (HANDLE)_beginthread(proc, 8192, arg);}
848     #define thread_create_event(ev, f) {(ev) = CreateEvent(NULL, TRUE, f, NULL);}
849     #define thread_signal_event(ev) SetEvent(ev)
850     #define thread_clear_event(ev) ResetEvent(ev)
851     #define thread_get_tid() GetCurrentThread()
852     #define thread_set_priority(tid,n) SetThreadPriority(tid, n)
853 notanpe 200 #if 0
854     #undef thread_set_priority /* MAKAI */
855     #endif
856 notanpe 148 #define thread_set_affinity(tid,m) SetThreadAffinityMask(tid, (DWORD_PTR)1 << (m))
857    
858     static
859 chapuni 1 int
860 notanpe 148 thread_wait_event(THREAD_EV_T ev, DWORD tmo)
861     {
862     DWORD r = WaitForSingleObject(ev, tmo);
863     return (r < 0
864     ? r
865     : (r == WAIT_TIMEOUT
866     ? -1
867     : r));
868     }
869    
870 notanpe 212 #elif defined(_POSIX_SOURCE) || defined(FREEBSD) /* MAKAI */
871 notanpe 148
872     #include <pthread.h>
873     #include <unistd.h>
874    
875     typedef int THREAD_TIMEOUT_T;
876    
877     #define THREAD_INFINITE INT_MAX
878    
879     #if defined(THREAD_PRIORITY_BELOW_NOROMAL) || defined(THREAD_PRIORITY_IDLE)
880     #error "unsupported implementation"
881     #endif
882    
883     #define THREAD_PRIORITY_NORMAL 14
884     #define THREAD_PRIORITY_BELOW_NORMAL 15
885     #define THREAD_PRIORITY_IDLE 16
886    
887     typedef pthread_t THREAD_TH_T;
888     typedef struct
889     {
890     pthread_mutex_t m;
891     pthread_cond_t c;
892     int volatile f;
893     } THREAD_EV_T;
894    
895     #define thread_sleep(n) (usleep(1000 * (n)) != EINVAL || sleep((n) / 1000))
896     #define thread_create(th, proc, arg) thread_create_p(&(th), proc, arg)
897     #define thread_create_event(ev, f) thread_create_event_p(&(ev), f)
898     #define thread_signal_event(ev) thread_set_event_p(&(ev), 1)
899     #define thread_clear_event(ev) thread_set_event_p(&(ev), 0)
900     #define thread_wait_event(ev,tmo) thread_wait_event_p(&(ev), tmo)
901    
902     static
903     void
904     thread_create_p(pthread_t *th, NORETURN (*proc)(void *), void *param)
905     {
906     pthread_create(th, NULL, (void *(*)(void *))proc, param);
907     }
908    
909     static
910     void
911     thread_create_event_p(THREAD_EV_T *ev, int f)
912     {
913     ev->f = f;
914     pthread_cond_init(&ev->c, NULL);
915     pthread_mutex_init(&ev->m, NULL);
916     }
917    
918     static
919     void
920     thread_set_event_p(THREAD_EV_T *ev, int f)
921     {
922     pthread_mutex_lock(&ev->m);
923     if (ev->f != f)
924     {
925     ev->f = f;
926     pthread_cond_broadcast(&ev->c);
927     }
928     pthread_mutex_unlock(&ev->m);
929     }
930    
931     static
932     int
933     thread_wait_event_p(THREAD_EV_T *ev, int a_tmo)
934     {
935     int timeout = a_tmo;
936     struct timeval now;
937     struct timespec tmo;
938     int r;
939    
940     pthread_mutex_lock(&ev->m);
941    
942     /* ŒťÝŽž‚Š‚çƒ^ƒCƒ€ƒAƒEƒgŽž‚đ‹‚ß‚é
943     ‚ß‚ń‚Ç‚­‚š[ */
944     gettimeofday(&now, NULL);
945     tmo.tv_sec = now.tv_sec + (timeout / 1000);
946     timeout %= 1000;
947     timeout *= 1000;
948     if (now.tv_usec >= 1000000 - timeout)
949     {
950     timeout -= 1000000;
951     tmo.tv_sec++;
952     }
953     tmo.tv_nsec = 1000 * (now.tv_usec + timeout);
954     r = 0;
955     while (!ev->f)
956     {
957     r = pthread_cond_timedwait(&ev->c, &ev->m, &tmo);
958     if (r == ETIMEDOUT
959     && a_tmo < THREAD_INFINITE)
960     break;
961     }
962    
963     pthread_mutex_unlock(&ev->m);
964    
965     return (r == ETIMEDOUT
966     ? (ETIMEDOUT < 0 ? ETIMEDOUT : -1)
967     : 0);
968     }
969    
970     #if defined(__linux__)
971    
972     /* ƒfƒtƒHƒ‹ƒgƒXƒPƒWƒ…[ƒŠƒ“ƒOƒ|ƒŠƒV[‚Ĺ‚Í
973     —Dć“xÝ’肾‚˝‚čƒAƒCƒhƒ‹ƒXƒŒƒbƒh‹N‚ą‚ľ‚Ä‚ŕ
974     ‚¨‚ŕ‚ľ‚ë‚­‚Č‚˘‚̂ŁA‚ť‚̂ւń‚͍ĄŒă‚ĚŒ¤‹†‰Ű‘čB */
975    
976     #include <linux/unistd.h>
977     _syscall0(pid_t,gettid)
978    
979     #define thread_get_tid() gettid()
980    
981     static
982     int thread_set_affinity(pid_t tid, int i)
983     {
984     cpu_set_t m;
985     CPU_ZERO(&m);
986     CPU_SET(i, &m);
987     return sched_setaffinity(tid, sizeof(m), &m);
988     }
989    
990     #else
991    
992     /* POSIX ‚ł́AƒXƒŒƒbƒh’PˆĘ‚ĚƒXƒPƒWƒ…[ƒŠƒ“ƒO‚ɉî“ü‚Ĺ‚Ť‚Č‚˘B */
993    
994     #endif
995    
996     #else
997     #error "configuration not supported"
998     #endif
999    
1000     struct THREAD_PARAM
1001     {
1002     /* ˆČ‰ş‚Í‹¤’ʏî•ń‚ĚƒRƒs[ */
1003     CODE_T *code;
1004 notanpe 192 THREAD_EV_T *p_ev_ks_activated;
1005 notanpe 148 ATOMWORD_T volatile *p_nidle; /* ‘Ň‚ż‚É“ü‚Á‚˝‚瑝‰Á */
1006    
1007     /* ˆČ‰ş‚̓XƒŒƒbƒhŒĹ—L */
1008     #ifdef thread_set_priority
1009     THREAD_TH_T th;
1010     int pri;
1011     #endif
1012     };
1013    
1014     static
1015     volatile ATOMWORD_T wp_crypt, rp_crypt;
1016     static
1017     struct PACKET_CRYPT64 *volatile q_crypt[NQ_CRYPT];
1018    
1019     static
1020     volatile ATOMWORD_T wp_cmp, rp_cmp;
1021     static
1022     struct PACKET_CRYPT64 *volatile q_cmp[NQ_CMP];
1023    
1024     static
1025     uint64_t
1026     thread_avail(void)
1027     {
1028     #if !USE_MT
1029    
1030     return 0x1U;
1031    
1032     #elif defined(WIN32) /* Win32 API */
1033     DWORD_PTR mask, mask_s;
1034     if (!GetProcessAffinityMask(GetCurrentProcess(),
1035     &mask,
1036     &mask_s)
1037     || !mask
1038     || !mask_s)
1039     return 0x1U;
1040     #if DEBUG>=1
1041     fprintf(stderr,
1042     "m=%08X s=%08X\n",
1043     (unsigned)mask,
1044     (unsigned)mask_s);
1045     #endif
1046     if (popcnt64(mask_s) == 1)
1047     /* ‰˝‚ŕŒž‚¤‚Ü‚˘ */;
1048     else if (mask == mask_s)
1049     fprintf(stderr,
1050     "’ʏí‚Ě%d”{‚Ƃ͂悭Œž‚Á‚˝‚ŕ‚̂łˇB\n",
1051     popcnt64(mask));
1052     else
1053     fprintf(stderr,
1054     "Ĺ‚‘Ź—Í‚Ě%g”{‚̗͂łĂŤ‚Ć‚¤‚ɂނń‚΂é‚ćB\n",
1055     (double)popcnt64(mask) / popcnt64(mask_s));
1056     return mask;
1057    
1058     #elif defined(__linux__) /* sched.h Šg’Ł */
1059    
1060     int i;
1061     uint64_t m = 0;
1062     cpu_set_t am;
1063     if (sched_getaffinity(getpid(), sizeof(am), &am) < 0)
1064     return 0x1U;
1065    
1066     for (i = 0; i < 64 && i < CPU_SETSIZE; i++)
1067     if (CPU_ISSET(i, &am))
1068     m |= 1ULL << i;
1069    
1070     return m;
1071     #else
1072    
1073     /* XXX ƒvƒƒZƒbƒT”‚đ’˛‚×ă‚°‚Ä‚­‚ž‚ł‚˘ */
1074     return 0x01U;
1075    
1076     #endif
1077     }
1078    
1079     static
1080     NORETURN
1081     thread_crypt64(void *a_param)
1082     {
1083     struct THREAD_PARAM *param = a_param;
1084     CODE_T *code = param->code;
1085     struct PACKET_CRYPT64 *pkt;
1086     #ifdef thread_set_priority
1087     THREAD_TH_T th = thread_get_tid();
1088     thread_set_priority(th, param->pri);
1089     #endif
1090    
1091     for(;;)
1092     {
1093     ATOMWORD_T rp;
1094     ATOMWORD_T wp;
1095    
1096     /* ƒLƒ…[‚Š‚ç—v‹‚đŽć‚čo‚ˇ */
1097     for (;;)
1098     {
1099     while ((rp = rp_crypt,
1100     WRAP(wp_crypt, NQ_CRYPT) == WRAP(rp, NQ_CRYPT)
1101     /*|| q_crypt[WRAP(rp, NQ_CRYPT)] == NULL*/))
1102     {
1103     THREAD_TIMEOUT_T tmo = (WRAP(wp_crypt, NQ_CRYPT) == WRAP(rp, NQ_CRYPT)
1104     ? THREAD_INFINITE
1105     : 1);
1106     int r;
1107    
1108 notanpe 192 /* Q‚˝ */
1109 notanpe 148 if (tmo == THREAD_INFINITE)
1110     {
1111     LOCK_INC(param->p_nidle);
1112     }
1113    
1114     /* —v‹‘Ň‚ż */
1115 notanpe 192 r = thread_wait_event(*param->p_ev_ks_activated, tmo);
1116 notanpe 148
1117     if (tmo == THREAD_INFINITE)
1118     {
1119     /* ‹N‚ą‚ł‚ę‚˝ */
1120     LOCK_DEC(param->p_nidle);
1121     }
1122     else if (r >= 0)
1123     {
1124     /* ‚ŕ‚¤‚ż‚ĺ‚Á‚ƐQ‚Ă݂é */
1125     thread_sleep(tmo);
1126     }
1127    
1128     /* ŽŠ‚ç‚Ě—Dć“x‚đ–ß‚ˇ
1129     (ŠO‚Š‚çƒu[ƒXƒg‚ł‚ę‚Ă邊‚ŕ) */
1130     #ifdef thread_set_priority
1131     if (r >= 0)
1132     thread_set_priority(th, param->pri);
1133     #endif
1134     }
1135    
1136     if (LOCK_CAS(&rp_crypt, rp + 1, rp) != rp)
1137     continue;
1138     rp = WRAP(rp, NQ_CRYPT);
1139     break;
1140     }
1141    
1142     pkt = q_crypt[rp];
1143     assert(pkt != NULL);
1144     pkt = LOCK_CASP(&q_crypt[rp], NULL, pkt);
1145     assert(pkt != NULL);
1146    
1147     /* ŽŔs‚ľ‚Ă݂é */
1148     CALL_CRYPT64(code, &pkt->key64, &pkt->param64);
1149    
1150     /* Œ‹‰Ę‚đƒLƒ…[‚É‚˝‚˝‚Ťž‚Ţ */
1151     for (;;)
1152     {
1153     while ((wp = wp_cmp,
1154     WRAP(rp_cmp - 1, NQ_CMP) == WRAP(wp, NQ_CMP))
1155     || q_cmp[WRAP(wp, NQ_CMP)] != NULL)
1156     {
1157     #if DEBUG>=1
1158     fprintf(stderr,
1159     "q_cmp stalled(%d,%d) %p\n",
1160     (unsigned)WRAP(wp, NQ_CMP),
1161     (unsigned)WRAP(rp_cmp - 1, NQ_CMP),
1162     q_cmp[WRAP(wp, NQ_CMP)]);
1163     #endif
1164     thread_sleep(1);
1165     }
1166    
1167     if (LOCK_CAS(&wp_cmp, wp + 1, wp) != wp)
1168     continue;
1169     wp = WRAP(wp, NQ_CMP);
1170     break;
1171     }
1172    
1173     pkt = LOCK_CASP(&q_cmp[wp], pkt, NULL);
1174     assert(pkt == NULL);
1175     }
1176     }
1177    
1178 notanpe 197 /* MAKAI start */
1179     void
1180     usage( path )
1181     char *path;
1182     {
1183     char *myName, *chPtr;
1184    
1185     myName = basename( path );
1186     for ( chPtr = myName; *chPtr != '\0'; chPtr++ ) {
1187     if ( *chPtr == '.' ) {
1188     *chPtr = '\0';
1189     break;
1190     }
1191     }
1192 notanpe 203 printf( "%s [-t num|-m mask] [-s num] [-v] [\"str\"]\n", myName );
1193 notanpe 197 printf( " -t num : ŒŸőƒXƒŒƒbƒh” ( %d … num … %d )\n",
1194     MIN_THREAD, MAX_THREAD );
1195 notanpe 199 printf( " -m mask : ŽŔs‚ˇ‚é CPU ‚đŽw’股‚éƒ}ƒXƒN ( 1 ƒrƒbƒg … mask ‚Ěƒrƒbƒg” … %d ƒrƒbƒg )\n",
1196     MAX_THREAD );
1197 notanpe 203 printf( " -s num : —”‚ĚŽí ( 1 … num … %u )\n", UINT_MAX );
1198     printf( " -v : ç’ˇƒƒbƒZ[ƒW\n" );
1199 notanpe 197 printf( " str : ć“ނɖ„‚ߍž‚Ţ•śŽš—ń ( %d … str ‚ĚƒoƒCƒg” … %d )\n",
1200     MIN_UME, MAX_UME );
1201     }
1202 notanpe 198
1203     /* ƒqƒbƒgŽž‚ɂ͏o—̓tƒ@ƒCƒ‹‚Ö‚Ěƒ|ƒCƒ“ƒ^‚đ•Ô‚ˇ */
1204     FILE *
1205 notanpe 202 checkSpecial( trip, kind )
1206 notanpe 198 char *trip;
1207 notanpe 202 unsigned char *kind;
1208 notanpe 198 {
1209 notanpe 218 #ifdef CHIN
1210 notanpe 222 /* ‹­§“I‚ÉŒŸő */
1211 notanpe 218 if ( trip[0] == 'C' && trip[1] == 'h' && trip[2] == 'i' &&
1212     trip[3] == 'n' && trip[4] == 'k' && trip[5] == 'o' ) {
1213     strcpy( kind, "‚ż" );
1214     return( cfp );
1215     }
1216     #endif /* CHIN */
1217    
1218 notanpe 202 if ( special & ST_BUOO ) {
1219     /* ‚Ô‚¨ [A-Za-z]aoo[A-Za-z]uoo$ */
1220     if ( trip[3] == 'a' && trip[4] == 'o' && trip[5] == 'o' &&
1221     trip[7] == 'u' && trip[8] == 'o' && trip[9] == 'o' &&
1222     isalpha( trip[2] ) && isalpha( trip[6] ) ) {
1223     strcpy( kind, "‚Ô" );
1224 notanpe 198 return( tfp );
1225     }
1226     }
1227    
1228     if ( special & ST_NIKO ) {
1229     /* “ń\ */
1230     int i;
1231     char ch1, ch2;
1232     ch1 = trip[0];
1233     for ( i = 1; i < TRIP_LEN; i++ ) {
1234     if ( trip[i] != ch1 ) break;
1235     }
1236     ch2 = trip[i];
1237     for ( ; i < TRIP_LEN; i++ ) {
1238     if ( trip[i] != ch1 && trip[i] != ch2 ) goto NONIKO;
1239     }
1240 notanpe 202 strcpy( kind, "“ń" );
1241 notanpe 198 return( tfp );
1242     }
1243     NONIKO:
1244    
1245 notanpe 212 /* ”ň˜AŠÖ˜A‚ĚƒR[ƒh‚́AžŰŘÝ ŸCeleron/rc ě */
1246     if ( special & ST_HREN ) {
1247     /* ”ň˜A */
1248     int w, x = 0, y = 0;
1249     for ( w = 0; w < TRIP_LEN; w++ ) {
1250     if ( trip[w] == trip[0] ) x += 1;
1251     if ( trip[w] == trip[1] ) y += 1;
1252     if ( x >= 8 || y >= 8 ) {
1253     strcpy( kind, "”ň" );
1254     return( tfp );
1255     }
1256     }
1257     }
1258    
1259 notanpe 202 if ( special & ST_ALLN ) {
1260 notanpe 204 /* ‘S” ‚Š “{” */
1261 notanpe 202 if ( isdigit( trip[0] ) && isdigit( trip[1] ) && isdigit( trip[2] ) &&
1262     isdigit( trip[3] ) && isdigit( trip[4] ) && isdigit( trip[5] ) &&
1263     isdigit( trip[6] ) && isdigit( trip[7] ) && isdigit( trip[8] ) &&
1264     isdigit( trip[9] ) ) {
1265 notanpe 204 if ( special & ST_DOSU ) {
1266     /* ‘S” & ‰ń•ś */
1267     if ( trip[0] == trip[9] && trip[1] == trip[8] && trip[2] == trip[7] &&
1268     trip[3] == trip[6] && trip[4] == trip[5] ) {
1269     strcpy( kind, "“{" );
1270     return( tfp );
1271     }
1272     /* ‘S” & ‘o˜A */
1273     if ( trip[0] == trip[1] && trip[2] == trip[3] && trip[4] == trip[5] &&
1274     trip[6] == trip[7] && trip[8] == trip[9] ) {
1275     strcpy( kind, "“{" );
1276     return( tfp );
1277     }
1278     /* ‘S” & ŽR•F */
1279     if ( trip[0] == trip[5] && trip[1] == trip[6] && trip[2] == trip[7] &&
1280     trip[3] == trip[8] && trip[4] == trip[9] ) {
1281     strcpy( kind, "“{" );
1282     return( tfp );
1283     }
1284     /* ĹŹ‚˂炢 */
1285     if ( trip[0] == '0' && trip[1] == '0' && trip[2] == '0' &&
1286     trip[3] == '0' && trip[4] == '0' && trip[5] == '0' &&
1287     trip[6] == '0' ) {
1288     strcpy( kind, "“{" );
1289     return( tfp );
1290     }
1291 notanpe 212 /* Ĺ‘ĺ (9999999966 ˆČă) ‚́Aƒ 8 ˜A‚ŏo‚é‚Ě‚Ĺíœ */
1292 notanpe 204 } else {
1293     strcpy( kind, "”" );
1294     return( nfp );
1295     }
1296 notanpe 202 }
1297     }
1298    
1299 notanpe 198 return( NULL );
1300     }
1301 notanpe 197 /* MAKAI end */
1302    
1303 notanpe 148 /***************************************************************
1304     *
1305     * ƒƒCƒ“ƒ‹[ƒv‚Ć‚Š
1306     *
1307     */
1308    
1309     int
1310 chapuni 1 main(int argc, char *argv[])
1311     {
1312 chapuni 74 int i;
1313 chapuni 1 int mincnt;
1314 chapuni 77 int nblk_hit, nblk_total;
1315 chapuni 84 int nap_hit, nap_total;
1316 notanpe 148 CODE_T *code = NULL;
1317     off_t code_cmp;
1318 chapuni 1 FILE *ofp;
1319 chapuni 46 FILE *sfp; /* scoreboard */
1320     struct ITREE *root_expr;
1321 notanpe 148 uint64_t proc_mask;
1322     int ks_activated;
1323 notanpe 192 static THREAD_EV_T event_ks_activated;
1324 notanpe 148 static ATOMWORD_T volatile nidle;
1325     struct THREAD_PARAM *threads = NULL;
1326     int nthreads;
1327     int npkts;
1328     struct PACKET_CRYPT64 *pkts, *pkt_hit;
1329     uint64_t pkts_vacant;
1330     int tn;
1331 chapuni 1 int cr;
1332    
1333 notanpe 148 /* ŒŽ•śŽš—ń */
1334     uint8_t key[8 + 8];
1335    
1336 chapuni 74 int xhash_loaded;
1337    
1338 notanpe 119 #define UPDATE_INTERVAL 8 /* ‘Ź“x•\ŽŚ‚ĚŠÔŠu •b */
1339 notanpe 115 struct status {
1340 notanpe 192 uint64_t startTime; /* ŠJŽnŽž ƒ~ƒŠ•b */
1341     uint64_t lastTime; /* ĹŒă‚É•\ŽŚ‚ľ‚˝Žž ƒ~ƒŠ•b */
1342     uint64_t loop; /* ‘ŒŸőŒÂ” */
1343     uint64_t lastloop; /* ĹŒă‚É•\ŽŚ‚ľ‚˝Žž‚Ě loop */
1344 notanpe 115 } status;
1345 notanpe 192 uint64_t curTime;
1346     uint32_t upd_int = 0;
1347 chapuni 1
1348 notanpe 193 /* MAKAI start */
1349 notanpe 197 /* ŽŔŰ‚̏ˆ—‚Ć‚ ‚Á‚Ä‚˘‚Č‚˘ƒRƒƒ“ƒg‚đíœ */
1350    
1351 notanpe 193 #if defined(WIN32)
1352     SetPriorityClass( GetCurrentProcess(), IDLE_PRIORITY_CLASS );
1353     #endif
1354 notanpe 197
1355     {
1356     int optChar;
1357     extern char *optarg;
1358     extern int optind;
1359 notanpe 199 char *chPtr;
1360 notanpe 197
1361     nThread = 0;
1362 notanpe 199 pmask = 0;
1363 notanpe 203 seed = 0;
1364 notanpe 214 seedOffset = 0; /* ƒRƒ}ƒ“ƒhƒ‰ƒCƒ“ƒIƒvƒVƒ‡ƒ“‚ł͂Ȃ˘‚ށA‚ą‚ą‚ŏ‰Šú‰ť */
1365 notanpe 203 verbose = 0;
1366     while ( (optChar = getopt(argc, argv, "t:m:s:vh")) != EOF ) {
1367 notanpe 197 switch ( optChar ) {
1368     case 't':
1369     nThread = atoi( optarg );
1370     if ( nThread < MIN_THREAD || nThread > MAX_THREAD ) {
1371     usage( argv[0] );
1372     exit( 1 );
1373     }
1374     break;
1375 notanpe 199 case 'm':
1376     if ( strlen( optarg ) > MAX_THREAD ) {
1377     usage( argv[0] );
1378     exit( 1 );
1379     }
1380     for ( chPtr = optarg; *chPtr != '\0'; chPtr++ ) {
1381     pmask <<= 1;
1382     switch ( *chPtr ) {
1383     case '0':
1384     /* ‚Č‚É‚ŕ‚ľ‚Č‚˘ */
1385     break;
1386     case '1':
1387     pmask |= 1;
1388     break;
1389     default:
1390     usage( argv[0] );
1391     exit( 1 );
1392     break;
1393     }
1394     }
1395 notanpe 200 if ( pmask < MIN_THREAD ) {
1396     usage( argv[0] );
1397     exit( 1 );
1398     }
1399 notanpe 199 break;
1400 notanpe 203 case 's':
1401     if ( optarg[0] == '-' ) {
1402     usage( argv[0] );
1403     exit( 1 );
1404     }
1405     seed = (unsigned int)atoi( optarg );
1406     if ( seed < 1 || seed > UINT_MAX ) {
1407     usage( argv[0] );
1408     exit( 1 );
1409     }
1410     break;
1411     case 'v':
1412     verbose = 1;
1413     break;
1414 notanpe 197 case 'h':
1415     usage( argv[0] );
1416     exit( 0 );
1417     break;
1418     }
1419     }
1420    
1421     switch ( argc - optind ) {
1422     case 0:
1423     umeStr[0] = '\0';
1424     umeLen = KEY_SHUFFLE_POS;
1425     break;
1426     case 1:
1427     strcpy( umeStr, argv[optind] );
1428     umeLen = strlen( umeStr );
1429     if ( umeLen < MIN_UME || umeLen > MAX_UME ) {
1430     usage( argv[0] );
1431     exit( 1 );
1432     }
1433     break;
1434     default:
1435     usage( argv[0] );
1436     exit( 1 );
1437     }
1438     }
1439 notanpe 213 #ifdef REON
1440     regExpStr[0] = '\0';
1441     #endif /* REON */
1442 notanpe 222
1443     #ifdef MAKEY
1444 notanpe 218 fprintf(stderr, "–‚ƒL[‹óŠÔƒo[ƒWƒ‡ƒ“‚ɂ‚ŤAƒVƒƒEƒg‚ɂ͂¨‚ˇ‚ˇ‚߂łŤ‚Č‚˘B\n");
1445 notanpe 222 #endif /* MAKEY */
1446    
1447     #ifdef ALLKEY
1448     fprintf(stderr, "ƒL[‘S‹óŠÔƒo[ƒWƒ‡ƒ“‚ɂ‚ŤAƒVƒƒEƒg‚ɂ͂¨‚ˇ‚ˇ‚߂łŤ‚Č‚˘B\n");
1449     #endif /* MAKEY */
1450 notanpe 193 /* MAKAI end */
1451    
1452 notanpe 192 if (!cpuid_issupported())
1453 chapuni 1 {
1454 notanpe 192 fprintf(stderr, "‚ą‚̊‹Ť‚Ĺ‘–‚炚‚邹‚Ć‚Ş‘z’肳‚ę‚Ä‚˘‚Ü‚š‚ńB\n");
1455     exit(1);
1456 chapuni 1 }
1457    
1458 chapuni 10 assert((1 << N_STRIDE) == N_ALU * ALU_BITS);
1459    
1460 chapuni 46 /* ƒ^ƒQ“ǂݍž‚Ý */
1461     root_expr = expr_parse("target.txt");
1462 chapuni 2
1463 notanpe 203 /* MAKAI start */
1464 notanpe 222 #ifdef CHIN
1465     special |= ST_CHIN;
1466     #endif /* CHIN */
1467 notanpe 203 if ( verbose ) {
1468     printf( "“ÁŽęŒŸőƒIƒvƒVƒ‡ƒ“ : " );
1469 notanpe 204 if ( special & ST_DOSU ) {
1470     printf( "“{” " );
1471     } else {
1472     if ( special & ST_ALLN ) {
1473     printf( "‘S” " );
1474     }
1475 notanpe 203 }
1476     if ( special & ST_NIKO ) {
1477     printf( "“ń\ " );
1478     }
1479     if ( special & ST_BUOO ) {
1480     printf( "‚Ô‚¨ " );
1481     }
1482 notanpe 207 if ( special & ST_HREN ) {
1483     printf( "”ň˜A " );
1484     }
1485 notanpe 203 if ( special ) {
1486     printf( "ƒIƒ“I\n" );
1487     } else {
1488     printf( "ƒI[ƒ‹ƒIƒtI\n" );
1489     }
1490 notanpe 214 if ( seedOffset != 0 ) {
1491     printf( "—”‚ĚŽí‚ĚƒIƒtƒZƒbƒg = %d\n", seedOffset );
1492     }
1493 notanpe 213 #ifdef REON
1494     if ( regExpStr[0] != '\0' ) {
1495     printf( "ł‹K•\Œť : %s\n", regExpStr );
1496     }
1497     #endif /* REON */
1498 notanpe 203 }
1499     /* MAKAI end */
1500    
1501 notanpe 148 /* ƒR[ƒh‚đśŹE“WŠJ
1502     ‹N“Ž—\’čƒXƒŒƒbƒh”‚ɉž‚ś‚Ä
1503     śŹ‚ˇ‚éƒR[ƒh‚đ•Ď‚Ś‚é */
1504 chapuni 46 sfp = scoreboard_open();
1505 notanpe 192 fwrite(crypt64_descs[0]->pro, 1, crypt64_descs[0]->cmp_pro - crypt64_descs[0]->pro, sfp); /* prologue & ƒRƒAƒ‹[ƒv */
1506 notanpe 197
1507     /* MAKAI start */
1508 notanpe 214 /* proc_mask ‚ÉŽg—p‚ˇ‚é CPU ‚Ěƒ}ƒXƒN‚đƒZƒbƒg */
1509 notanpe 199 if ( pmask == 0 ) {
1510 notanpe 214 /* Žw’肪‚Ȃ݂ę‚΁AŽg‚Ś‚é CPU ‘S•” */
1511 notanpe 199 proc_mask = thread_avail();
1512     } else {
1513 notanpe 214 /* Žw’肳‚ę‚˝ CPU ‚Ě‘śÝƒ`ƒFƒbƒNB‚ž‚ށAĄ‚Í Win32 ‚ĚƒR[ƒh‚ľ‚ЂȂ˘B */
1514 notanpe 205 #ifdef WIN32
1515     DWORD_PTR processMask, systemMask;
1516     if ( GetProcessAffinityMask( GetCurrentProcess(), &processMask, &systemMask )
1517 notanpe 206 == 0 ) {
1518 notanpe 205 printf( "CPU ‚ĚŠ„‚č“–‚ĂɎ¸”s ‚ť‚Ě 1\n" );
1519     exit( 1 );
1520     }
1521     if ( (processMask & pmask) != pmask ) {
1522     printf( "‚ť‚ń‚Č CPU ‚͂˂ĽI\n" );
1523     exit( 1 );
1524     }
1525     #endif /* WIN32 */
1526 notanpe 214
1527 notanpe 199 proc_mask = pmask;
1528 notanpe 200 printf( "CPU : " );
1529     for ( i = 0; i < MAX_THREAD; i++ ) {
1530     if ( pmask & 1 ) {
1531     printf( "%d ", i );
1532     }
1533     pmask >>= 1;
1534     }
1535     printf( "‚đŽg—p‚ľ‚Ü‚ˇB\n" );
1536 notanpe 214
1537     /* CPU ‚ĚŠ„‚č“–‚āB‚ž‚ށAĄ‚Í Wi(r */
1538 notanpe 200 #ifdef WIN32
1539 notanpe 205 if ( SetProcessAffinityMask( GetCurrentProcess(), proc_mask ) == 0 ) {
1540     printf( "CPU ‚ĚŠ„‚č“–‚ĂɎ¸”s ‚ť‚Ě 2\n" );
1541     exit( 1 );
1542     }
1543 notanpe 200 #endif /* WIN32 */
1544 notanpe 199 }
1545 notanpe 214
1546     /* ƒXƒŒƒbƒh”‚ĚŽw’肪‚Č‚˘ę‡‚́Aproc_mask ‚Š‚çƒQƒbƒc */
1547     if ( nThread == 0 ) {
1548     nThread = popcnt64( proc_mask );
1549 notanpe 197 }
1550 notanpe 214
1551 notanpe 222 fprintf( stderr, "%d ŒÂ‚ĚŒŸőƒXƒŒƒbƒh‚𐜐Ź\n", nThread );
1552 notanpe 197 /* MAKAI end */
1553    
1554 notanpe 214 if (nThread == 1) /* MAKAI */
1555 notanpe 148 {
1556     /* single */
1557     npkts = 1;
1558     pkts_vacant = 1;
1559     code_cmp = 0;
1560     }
1561     else
1562     {
1563     /* multi */
1564 notanpe 192 fwrite(crypt64_descs[0]->ep, 1, crypt64_descs[0]->ep_end - crypt64_descs[0]->ep, sfp); /* epilogue */
1565 chapuni 2
1566 notanpe 148 /* ”äŠrŠí‚݂̂𐜐Ź(‘O”ź) */
1567     code_cmp = ftell(sfp);
1568     fseek(sfp, (-code_cmp) & 63, SEEK_CUR);
1569     code_cmp = ftell(sfp);
1570 notanpe 192 fwrite(crypt64_descs[0]->pro, 1, crypt64_descs[0]->crypt - crypt64_descs[0]->pro, sfp); /* prologue */
1571 notanpe 148 npkts = 64;
1572     pkts_vacant = (uint64_t)-1; /* (1 << 64) - 1 ‚đŒvŽZ‚ľ‚˝‚­‚Č‚˘ */
1573     }
1574    
1575     /* ”äŠr•”‚đśŹ */
1576 notanpe 192 fwrite(crypt64_descs[0]->cmp_pro, 1, crypt64_descs[0]->cmp_ep - crypt64_descs[0]->cmp_pro, sfp); /* ”äŠrŠí€”ő */
1577 notanpe 148 tn = synth_synthesize(sfp, root_expr);
1578 notanpe 192 fwrite(crypt64_descs[0]->cmp_ep, 1, crypt64_descs[0]->ep_end - crypt64_descs[0]->cmp_ep, sfp); /* epilogue */
1579 notanpe 148
1580 chapuni 46 /* ƒR[ƒh‚đƒƒ‚ƒŠ‚É“\‚č•t‚Ż‚é */
1581     code = scoreboard_map(sfp);
1582 chapuni 1
1583     /* ƒL[‚̏‰Šú‰ť */
1584 notanpe 199 /* MAKAI start */
1585 notanpe 203 if ( seed == 0 ) {
1586 notanpe 214 seed = (unsigned int)time( NULL ) + seedOffset;
1587 notanpe 203 }
1588 notanpe 204 if ( verbose ) {
1589     printf( "—”‚ĚŽí = %u\n", seed );
1590     }
1591     srand( seed );
1592 notanpe 199 /* MAKAI end */
1593 notanpe 148 key_init(key);
1594 notanpe 222
1595     #ifdef KEYCHK
1596     {
1597     /*
1598     ƒm[ƒ}ƒ‹
1599     1, 4 0x01 - 0x7e 126 ŒÂ
1600     1 ‚É 0x05, 0x06 ‚ޏo‚Č‚˘
1601     4 ‚Í‘S•”o‚邪 0x05 ‚Ć 0x06 ‚ރŒƒA
1602     2, 3 0x20 - 0xfc 221 ŒÂ
1603     2 ”˛‚Ż‚Í 8 ŒÂ 0x22 0x26 0x3c 0x3e 0x7f 0x80 0xef 0xf2
1604     3 ”˛‚Ż‚Í 9 ŒÂ 0x22 0x26 0x3c 0x3e 0x7f 0x80 0xf5 0xf7 0xf9
1605     */
1606     int i;
1607    
1608 notanpe 223 for ( i = 0; i < 100000; i++ ) {
1609 notanpe 222 printf( "%02x %02x %02x %02x %02x %02x %02x %02x\n",
1610     key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7] );
1611     key_init(key);
1612     }
1613     exit( 0 );
1614     }
1615     #endif /* KEYCHK */
1616    
1617 notanpe 192 set_salt(code, crypt64_descs[0], key);
1618 chapuni 1
1619 notanpe 148 /* ‰‰ŽZƒpƒPƒbƒg‚đěŹ */
1620     pkts = packet_create(npkts, tn, key);
1621     pkt_hit = &pkts[npkts - 1];
1622    
1623     /* “­‚­‚¨‚ś‚ł‚ń‚đ—ĘŽY */
1624     thread_create_event(event_ks_activated, 1);
1625     ks_activated = 1;
1626     nthreads = 0;
1627     if (code_cmp)
1628     {
1629     THREAD_TH_T h;
1630     int ots = -1;
1631 notanpe 214 threads = calloc(2 * nThread, sizeof(*threads));
1632     for (i = 0; i < nThread; i++ ) { /* MAKAI */
1633 notanpe 148 if (ots < 0)
1634     {
1635     /* ŽŠ•ŞŽŠg‚ĚƒXƒPƒWƒ…[ƒŠƒ“ƒO
1636     ‚ą[‚ä[Œn‚ĚƒAƒvƒŠ‚Í’á‚߂ɐݒ股‚é‚Ě‚Ş‹g(‚Š‚ŕ) */
1637     #ifdef WIN32
1638     h = GetCurrentProcess();
1639     SetPriorityClass(h, BELOW_NORMAL_PRIORITY_CLASS);
1640 chapuni 1 #endif
1641 notanpe 148 #if defined(thread_set_priority)
1642     /* S‚ĚŒ„ŠÔ‚¨–„‚ß‚ľ‚Ü‚ˇ */
1643     threads[nthreads].code = code;
1644 notanpe 192 threads[nthreads].p_ev_ks_activated = &event_ks_activated;
1645 notanpe 148 threads[nthreads].p_nidle = &nidle;
1646     threads[nthreads].pri = THREAD_PRIORITY_IDLE;
1647     thread_create(h, thread_crypt64, &threads[nthreads]);
1648     threads[nthreads].th = h;
1649     nthreads++;
1650     #endif
1651     if (!code_cmp)
1652     break;
1653 chapuni 1
1654 notanpe 148 /* ŽŠ•ŞŽŠg‚ĚŽc‚č‚̐ݒč‚đA‚ ‚Ƃłâ‚é */
1655     ots = i;
1656     }
1657     else
1658     {
1659     /* ‘źƒXƒŒƒbƒh‚́A‚â‚â’á‚߂̗Dć“x‚ŁB */
1660     threads[nthreads].code = code;
1661 notanpe 192 threads[nthreads].p_ev_ks_activated = &event_ks_activated;
1662 notanpe 148 threads[nthreads].p_nidle = &nidle;
1663     #ifdef thread_set_priority
1664     threads[nthreads].pri = THREAD_PRIORITY_BELOW_NORMAL;
1665     #endif
1666     thread_create(h, thread_crypt64, &threads[nthreads]);
1667     #ifdef thread_set_priority
1668     threads[nthreads].th = h;
1669     #endif
1670 notanpe 214 /* MAKAI start */
1671     #if 0
1672 notanpe 148 #ifdef thread_get_tid
1673     thread_set_affinity(h, i);
1674     #endif
1675 notanpe 214 #endif /* 0 */
1676     /* MAKAI end */
1677 notanpe 148 nthreads++;
1678     }
1679 notanpe 214 }
1680     /* MAKAI start */
1681     #if 0
1682 notanpe 148 #ifdef thread_get_tid
1683     if (ots)
1684     thread_set_affinity(thread_get_tid(), ots);
1685     #endif
1686 notanpe 214 #endif /* 0 */
1687     /* MAKAI end */
1688 notanpe 148 }
1689    
1690 chapuni 24 if ((ofp = fopen("log.txt", "at")) == NULL)
1691     {
1692     perror("log.txt");
1693     return errno;
1694     }
1695 chapuni 1
1696 chapuni 24 setvbuf(ofp, NULL, _IONBF, BUFSIZ); /* XXX MSVCRT ‚Ĺ‚Í _IOLBF ‚ŞŠú‘Ň’Ę‚č‚É“Žě‚ľ‚Č‚˘ */
1697    
1698 notanpe 198 /* MAKAI start */
1699     if ( (tfp = fopen("logspe.txt", "at")) == NULL ) {
1700     perror("logspe.txt");
1701     return errno;
1702     }
1703     setvbuf( tfp, NULL, _IONBF, BUFSIZ );
1704 notanpe 204 if ( (nfp = fopen("lognum.txt", "at")) == NULL ) {
1705     perror("lognum.txt");
1706     return errno;
1707     }
1708     setvbuf( nfp, NULL, _IONBF, BUFSIZ );
1709 notanpe 218 #ifdef CHIN
1710     if ( (cfp = fopen("logchi.txt", "at")) == NULL ) {
1711     perror("logchi.txt");
1712     return errno;
1713     }
1714     setvbuf( cfp, NULL, _IONBF, BUFSIZ );
1715     #endif /* CHIN */
1716 notanpe 213 #ifdef REON
1717     if ( (rfp = fopen("logreg.txt", "at")) == NULL ) {
1718     perror("logreg.txt");
1719     return errno;
1720     }
1721     setvbuf( rfp, NULL, _IONBF, BUFSIZ );
1722     #endif /* REON */
1723 notanpe 198 /* MAKAI end */
1724    
1725 chapuni 1 mincnt = 0x7FFFFFFF;
1726 chapuni 77 nblk_hit = nblk_total = 0;
1727 chapuni 84 nap_hit = nap_total = 0;
1728 chapuni 1 cr = 0;
1729 notanpe 120 memset( &status, 0, sizeof( struct status ) );
1730 notanpe 119 status.startTime = status.lastTime = usec();
1731 notanpe 213
1732     /* MAKAI start */
1733     #ifdef MINAST
1734     #undef assert
1735     #define assert(x)
1736     #endif /* MINAST */
1737     /* MAKAI end */
1738    
1739 chapuni 1 /* ’Tőƒ‹[ƒv‚ž‚ź‚Á‚Ć */
1740     for (;;)
1741     {
1742 notanpe 148 struct PACKET_CRYPT64 *pkt_c;
1743 chapuni 121 uint64_t cnt;
1744 notanpe 205 #if DEBUG>=1 /* MAKAI */
1745 chapuni 121 int cnt1, cnt2;
1746 notanpe 205 #endif /* MAKAI */
1747 chapuni 1 int k, kk;
1748    
1749 notanpe 148 /* ”äŠrŠíŒó•â(may be NULL)
1750     ć‚ɃLƒ…[‚Š‚çŽć‚čo‚ˇ */
1751     pkt_c = q_cmp[WRAP(rp_cmp, NQ_CMP)];
1752 notanpe 192 if (pkt_c != NULL && WRAP(rp_cmp, NQ_CMP) != WRAP(wp_cmp, NQ_CMP))
1753 chapuni 1 {
1754 notanpe 148 pkt_c = LOCK_CASP(&q_cmp[WRAP(rp_cmp, NQ_CMP)], NULL, pkt_c);
1755     assert(pkt_c != NULL);
1756     LOCK_INC(&rp_cmp);
1757    
1758     /* ƒpƒPƒbƒg‚đ vacant ‚ɉń‚ľ‚Ä‚¨‚­ */
1759     pkts_vacant |= 1ULL << (pkt_c - pkts);
1760 chapuni 1 }
1761    
1762 notanpe 148 /* Saltƒ`ƒFƒ“ƒW‘Ň‚ż */
1763     if (!ks_activated)
1764     {
1765 notanpe 192 ATOMWORD_T rp;
1766    
1767     if (pkt_c == NULL)
1768     {
1769     if ((rp = rp_crypt,
1770     WRAP(rp, NQ_CRYPT) != WRAP(wp_crypt, NQ_CRYPT))
1771     && LOCK_CAS(&rp_crypt, rp + 1, rp) == rp)
1772     {
1773     /* !ks_activate ó‘Ԃł́AŽŠ‚ç‚ŕ—v‹ƒLƒ…[‚đ‚â‚Á‚Â‚Ż‚É‚˘‚­ */
1774     rp = WRAP(rp, NQ_CRYPT);
1775     pkt_c = q_crypt[rp];
1776     assert(pkt_c != NULL);
1777     pkt_c = LOCK_CASP(&q_crypt[rp], NULL, pkt_c);
1778     assert(pkt_c != NULL);
1779     assert(pkt_c != pkt_hit);
1780     CALL_CRYPT64(code,
1781     &pkt_c->key64,
1782     &pkt_c->param64);
1783    
1784     /* ƒpƒPƒbƒg‚đ vacant ‚ɉń‚ľ‚Ä‚¨‚­ */
1785     pkts_vacant |= 1ULL << (pkt_c - pkts);
1786     }
1787     else
1788     {
1789     /* ‚â‚͂股‚邹‚Ć‚Ş‚Č‚˘‚̂ł܂Á‚˝‚č‚Ɖ߂˛‚ˇ */
1790     if (nidle != nthreads)
1791     thread_sleep(1);
1792     }
1793     }
1794    
1795 notanpe 148 if (nidle == nthreads)
1796     {
1797     assert(WRAP(rp_crypt, NQ_CRYPT) == WRAP(wp_crypt, NQ_CRYPT));
1798     /* Salt ƒ`ƒFƒ“ƒW‚މ”\ */
1799 notanpe 192 set_salt(code, crypt64_descs[0], key);
1800     if (nthreads)
1801 notanpe 148 thread_signal_event(event_ks_activated);
1802     ks_activated = 1;
1803     }
1804     }
1805    
1806     /* ŒŽ‚đƒLƒ…[‚É‚˝‚˝‚Ťž‚݂܂­‚é */
1807     if (!ks_activated)
1808     {
1809     /* ŒŽ‚đ“o˜^‚ľ‚Č‚˘ */
1810     ;
1811     }
1812     else for (i = npkts - 1; i >= 0; i--)
1813     if (pkts_vacant & (1ULL << i))
1814     {
1815     int j;
1816    
1817     if (i == npkts - 1)
1818     {
1819     /* ‘O’i‚ŁA“­‚­‚¨‚ś‚ł‚ń‚Š‚ç
1820     Œ‹‰Ę‚đ‚ŕ‚ç‚Á‚Ä‚˘‚˝‚çA‰˝‚ŕ‚ľ‚Č‚˘ */
1821     if (pkt_c != NULL)
1822     continue;
1823     }
1824     else
1825     {
1826     /* ‘O’i‚ĹŽć‚čo‚ľ‚˝‚Î‚Š‚č‚Ě
1827     “­‚­‚¨‚ś‚ł‚ń‚́A‘¸d‚ˇ‚é */
1828     if (&pkts[i] == pkt_c)
1829     continue;
1830    
1831     /* queue full ‚Ěę‡‚ÍŒŠ‘—‚é */
1832 notanpe 192 if (WRAP(wp_crypt, NQ_CRYPT) == WRAP(rp_crypt - 16, NQ_CRYPT) /* XXX 16 ‚͂ĂŤ‚Ć‚¤ */
1833 notanpe 148 || q_crypt[WRAP(wp_crypt, NQ_CRYPT)] != NULL)
1834     break;
1835     }
1836    
1837     /* ŒŽ‚ĚƒZƒbƒg */
1838     for (j = 0; j < 8; j++)
1839     {
1840     key_set64(&pkts[i].key64, j, key[j], key[j] ^ pkts[i].uk.key[j], 0);
1841     pkts[i].uk.key[j] = key[j];
1842     }
1843    
1844     if (i == npkts - 1)
1845     {
1846     /* ŽŸ’i‚Ĺ CRYPT64->CMP */
1847     assert(pkt_c == NULL);
1848     pkt_c = &pkts[i];
1849     assert(pkt_c == pkt_hit);
1850     }
1851     else
1852     {
1853     /* ƒLƒ…[‚É‚˝‚˝‚Ťž‚Ţ */
1854     while (LOCK_CASP(&q_crypt[WRAP(wp_crypt, NQ_CRYPT)], &pkts[i], NULL) != NULL)
1855     {
1856     /* ÝŒvă‚Í‚ą‚ą‚É—ˆ‚Č‚˘ */
1857     #if DEBUG>=1
1858     fprintf(stderr,
1859     "[XXX] q_crypt ‚đ‰˜‚ľ‚Ä‚é‚̂͒N‚ž? (rp=%3d, wp=%3d, v=%08X%08X)\n",
1860     (unsigned)WRAP(rp_crypt, NQ_CRYPT),
1861     (unsigned)WRAP(wp_crypt, NQ_CRYPT),
1862     (unsigned)(pkts_vacant >> 32),
1863     (unsigned)pkts_vacant);
1864     thread_sleep(1000);
1865     #endif
1866     thread_sleep(1);
1867     }
1868     LOCK_INC(&wp_crypt);
1869     pkts_vacant ^= 1ULL << i;
1870     assert(!(pkts_vacant & (1ULL << i))); /* í‚ę */
1871     }
1872    
1873     /* ŒŽ‘‰Á‚Í‚ą‚ń‚ȂƂą‚ë‚ɈړŽ! */
1874     assert(ks_activated);
1875 notanpe 197 /* MAKAI start */
1876     if (!key_inc(key, 6) && !key_inc(key, umeLen))
1877     /* MAKAI end */
1878 notanpe 148 {
1879     /* ŒŽ‚ĚƒVƒƒƒbƒtƒ‹
1880     q_crypt ‚ŞŽJ‚Ż‚é‚܂ŁAset_salt() ‚͂łŤ‚Č‚˘ */
1881     #if DEBUG>=1
1882     fprintf(stderr, "********************************SHUFFLE!\n");
1883     #endif
1884 notanpe 192 if (nthreads)
1885     thread_clear_event(event_ks_activated);
1886 notanpe 148 key_reset(key, 0);
1887    
1888     /* ƒLƒ…[‚ĚŒŽ‚ŞŽJ‚Ż‚é‚Ü‚ĹƒAƒCƒhƒ‹ó‘Ô‚É */
1889     ks_activated = 0;
1890    
1891     /* ƒXƒŒƒbƒh‚đƒu[ƒXƒg‚ľ‚ĉń‚é */
1892     #ifdef thread_set_priority
1893     for (j = 0; j < nthreads; j++)
1894     {
1895     assert(threads != NULL);
1896     thread_set_priority(threads[j].th, THREAD_PRIORITY_NORMAL);
1897     }
1898     #endif
1899    
1900     /* ƒ‹[ƒv‘ąs‚Í‚ŕ‚Í‚â•s—v */
1901     break;
1902     }
1903     }
1904    
1905     /* ‚ˇ‚邹‚Ć‚Ş‚Č‚­‚Č‚Á‚Ä‚˘‚éę‡ */
1906     if (pkt_c == NULL)
1907     {
1908     assert(!ks_activated);
1909     continue;
1910     }
1911    
1912 chapuni 14 /* ŒÄ‚Ô!
1913     LR ‰Šú‰ť‚́AƒTƒuƒ‚ƒWƒ…[ƒ‹“ŕ‚ōs‚¤‚ׂľ
1914     FASTCALL ‚ɏ€‚ś‚˝ŒÄ‚яo‚ľ‚Ě‚˝‚߁A
1915     ƒzƒ“ƒg‚Í‚˘‚낢‚냌ƒWƒXƒ^‚Ş”j‰ó‚ł‚ę‚éƒnƒYc‚Č‚ń‚ž‚ށB */
1916 notanpe 148 if (pkt_c != pkt_hit)
1917     {
1918 notanpe 192 assert(code_cmp != 0);
1919 notanpe 148 cnt = CALL_CMP64(code + code_cmp,
1920     pkt_hit->param64.hit,
1921     pkt_c->param64.lr);
1922     }
1923     else
1924     {
1925     /* ‚悤‚â‚­ŽŠƒXƒŒƒbƒh‚ʼnń‚š‚é */
1926     cnt = CALL_CRYPT64(code,
1927     &pkt_c->key64,
1928     &pkt_c->param64);
1929     if (code_cmp)
1930     cnt = CALL_CMP64(code + code_cmp,
1931     pkt_c->param64.hit,
1932     pkt_c->param64.lr);
1933     }
1934 chapuni 42
1935 chapuni 46 #if DEBUG>=1
1936 chapuni 121 cnt2 = (int32_t)(cnt >> 32);
1937     cnt1 = (int32_t)cnt;
1938     if (mincnt > cnt1 && cnt1 > 0)
1939 chapuni 1 {
1940 chapuni 121 mincnt = cnt1;
1941 chapuni 1 if (cr)
1942     fprintf(stderr, "\n");
1943     cr = 0;
1944 chapuni 121 fprintf(stderr, "cycle=%6d/%6d\n", cnt1, cnt2);
1945 chapuni 1 }
1946 chapuni 46 #endif
1947 chapuni 1
1948 notanpe 148 /* ƒqƒbƒg‚ľ‚˝‚Ć‚Ť‚̏ˆ—
1949     key ‚¨‚ć‚Ń lr ‚Í pkt_c ‚É
1950     ‡’v”ť’č‚Í pkt_hit ‚É“ü‚Á‚Ä‚˘‚éƒnƒY */
1951 chapuni 74 xhash_loaded = 0;
1952 chapuni 6 for (kk = 0; kk < N_ALU; kk++)
1953 chapuni 1 {
1954 chapuni 6 ALU_T t;
1955 notanpe 198
1956     /* MAKAI start */
1957     static uint64_t xhash[64];
1958    
1959 notanpe 213 if ( special
1960     #ifdef REON
1961     || regExpStr[0] != '\0'
1962     #endif /* REON */
1963     ) {
1964 notanpe 198 CALL_TR64( &pkt_c->param64.lr[0][0].q[kk / (N_ALU / N_Q)], xhash );
1965     xhash_loaded = 1;
1966     }
1967     /* MAKAI end */
1968    
1969 chapuni 84 if (!(kk & (N_ALU / N_Q - 1)))
1970 chapuni 77 nblk_total++, xhash_loaded = 0;
1971 chapuni 9
1972 notanpe 198 /* MAKAI start */
1973 notanpe 213 if ( special
1974     #ifdef REON
1975     || regExpStr[0] != '\0'
1976     #endif /* REON */
1977     ) {
1978     char hash[16];
1979     uint8_t buf[32];
1980     FILE *lfp;
1981     unsigned char kind[3];
1982 notanpe 198
1983 notanpe 213 for ( k = 0; k < ALU_BITS; k++ ) {
1984     for ( i = 1; i < 11; i++ ) {
1985     unsigned c = 0;
1986 notanpe 198
1987 notanpe 213 c = (xhash[(ALU_BITS * kk + k) & 63] >> (6 * (i - 1))) & 0x3F;
1988     hash[i - 1] = C64[c];
1989     }
1990     hash[10] = 0;
1991 notanpe 198
1992 notanpe 213 #ifdef REON
1993     if ( regExpStr[0] != '\0' ) {
1994     if ( regexec( &regExp, hash, (size_t)0, NULL, 0 ) == 0 ) {
1995     struct timeb tb;
1996     struct tm *plt;
1997     uint8_t buf2[32];
1998    
1999     ftime( &tb );
2000     plt = localtime( &tb.time );
2001     buf[0] = '#';
2002     memcpy( buf+1, pkt_c->uk.key, 8 );
2003     buf[9] = buf[10] = 0;
2004     buf[8] = ( buf[8] & - ( 1 << N_STRIDE ) & 0x7F ) + ALU_BITS * kk + k;
2005     if ( cr ) fprintf( stderr, "\n" );
2006     cr = 0;
2007 notanpe 223 /* MAKAI start */
2008     #ifdef ALLKEY
2009     strcpy( buf2, "‘S‹óŠÔ‚Ĺ‚ˇ" );
2010     #else /* ALLKEY */
2011 notanpe 213 if ( translate( buf+1, 0, 1 ) ) {
2012     strcpy( buf2, buf );
2013     } else {
2014     strcpy( buf2, "Žc”O‚Ĺ‚ľ‚˝" );
2015     }
2016 notanpe 223 #endif /* ALLKEY */
2017     /* MAKAI end */
2018 notanpe 213 log_printf( rfp, "Ÿ%s %s"
2019     "\t%04d/%02d/%02d %02d:%02d:%02d.%03d"
2020     "\t(%02X %02X %02X %02X %02X %02X %02X %02X/%02X) %s\n",
2021     hash, buf2,
2022     plt->tm_year + 1900, plt->tm_mon + 1, plt->tm_mday,
2023     plt->tm_hour, plt->tm_min, plt->tm_sec, tb.millitm,
2024     buf[1], buf[2], buf[3], buf[4], buf[5],
2025     buf[6], buf[7], buf[8], buf[9], "ł" );
2026     }
2027 notanpe 198 }
2028 notanpe 213 #endif /* REON */
2029    
2030     if ( special ) {
2031     if ( (lfp = checkSpecial( hash, kind )) != NULL ) {
2032     struct timeb tb;
2033     struct tm *plt;
2034     uint8_t buf2[32];
2035    
2036     ftime( &tb );
2037     plt = localtime( &tb.time );
2038     buf[0] = '#';
2039     memcpy( buf+1, pkt_c->uk.key, 8 );
2040     buf[9] = buf[10] = 0;
2041     buf[8] = ( buf[8] & - ( 1 << N_STRIDE ) & 0x7F ) + ALU_BITS * kk + k;
2042     if ( cr ) fprintf( stderr, "\n" );
2043     cr = 0;
2044 notanpe 223 /* MAKAI start */
2045     #ifdef ALLKEY
2046     strcpy( buf2, "‘S‹óŠÔ‚Ĺ‚ˇ" );
2047     #else /* ALLKEY */
2048 notanpe 213 if ( translate( buf+1, 0, 1 ) ) {
2049     strcpy( buf2, buf );
2050     } else {
2051     strcpy( buf2, "Žc”O‚Ĺ‚ľ‚˝" );
2052     }
2053 notanpe 223 #endif /* ALLKEY */
2054     /* MAKAI end */
2055 notanpe 213 log_printf( lfp, "Ÿ%s %s"
2056     "\t%04d/%02d/%02d %02d:%02d:%02d.%03d"
2057     "\t(%02X %02X %02X %02X %02X %02X %02X %02X/%02X) %s\n",
2058     hash, buf2,
2059     plt->tm_year + 1900, plt->tm_mon + 1, plt->tm_mday,
2060     plt->tm_hour, plt->tm_min, plt->tm_sec, tb.millitm,
2061     buf[1], buf[2], buf[3], buf[4], buf[5],
2062     buf[6], buf[7], buf[8], buf[9], kind );
2063     }
2064     }
2065 notanpe 198 }
2066     }
2067     /* MAKAI end */
2068    
2069 notanpe 148 t = pkt_hit->param64.hit[HIT_ANY].a[kk];
2070 chapuni 1 if (!t)
2071     continue;
2072 chapuni 9
2073 chapuni 84 nap_total += ALU_BITS;
2074    
2075 chapuni 6 for (k = 0; k < ALU_BITS; k++)
2076 chapuni 1 {
2077 notanpe 198
2078     /* MAKAI start */
2079     #if 0
2080 chapuni 74 static uint64_t xhash[64];
2081 notanpe 198 #endif /* 0 */
2082     /* MAKAI end */
2083    
2084 chapuni 1 char hash[16];
2085 notanpe 148 uint8_t buf[32];
2086 notanpe 213 uint8_t buf2[32];
2087 notanpe 192 struct timeb tb;
2088     struct tm *plt;
2089 notanpe 198
2090 notanpe 196 /* MAKAI start */
2091     int hitLen;
2092     /* MAKAI end */
2093 chapuni 9
2094     if (!(t & ((ALU_T)1 << k)))
2095 chapuni 1 continue;
2096 chapuni 9
2097 chapuni 84 nap_hit++;
2098    
2099 chapuni 74 /* “]’u */
2100     if (!xhash_loaded)
2101     {
2102 chapuni 77 nblk_hit++;
2103 notanpe 148 CALL_TR64(&pkt_c->param64.lr[0][0].q[kk / (N_ALU / N_Q)], xhash);
2104 chapuni 74 xhash_loaded = 1;
2105     }
2106    
2107     /* ŽŤ‘‚𒲂ׂé */
2108 notanpe 196 /* MAKAI hitLen ’ljÁ */
2109 notanpe 148 if (!((pkt_hit->param64.hit[HIT_BOOL].a[kk] & ((ALU_T)1 << k))
2110 notanpe 196 || (hitLen = wdict_ishit(pkt_hit->param64.hit,
2111 chapuni 99 kk, k,
2112 notanpe 196 xhash[(ALU_BITS * kk + k) & 0x3F]))))
2113 chapuni 74 continue;
2114    
2115 notanpe 192 /* ƒqƒbƒgŽž; –‚‰ü‘˘‚Ć‚ż‚ĺ‚Á‚Ćˆá‚¤ */
2116     ftime(&tb);
2117     plt = localtime(&tb.time);
2118    
2119 chapuni 1 for (i = 1; i < 11; i++)
2120     {
2121     unsigned c = 0;
2122 chapuni 74 c = (xhash[(ALU_BITS * kk + k) & 63] >> (6 * (i - 1))) & 0x3F; /* XXX */
2123     hash[i - 1] = C64[c];
2124 chapuni 1 }
2125     hash[10] = 0;
2126    
2127 notanpe 148 memcpy(buf, pkt_c->uk.key, 8);
2128 chapuni 1 buf[8] = buf[9] = 0;
2129 chapuni 10 buf[7] = (buf[7] & -(1 << N_STRIDE) & 0x7F) + ALU_BITS * kk + k;
2130 notanpe 213
2131 notanpe 196 /* MAKAI start */
2132 notanpe 213 /* ŒŠ‚É‚­‚˘‚Ě‚ĹŽ— */
2133     if (cr)
2134     fprintf(stderr, "\n");
2135     cr = 0;
2136 notanpe 223 /* MAKAI start */
2137     #ifdef ALLKEY
2138     strcpy( buf2, "‘S‹óŠÔ‚Ĺ‚ˇ" );
2139     #else /* ALLKEY */
2140 notanpe 213 if (translate(buf, 0, 1)) {
2141     buf2[0] = '#';
2142     strcpy( buf2+1, buf );
2143     } else {
2144     strcpy( buf2, "Žc”O‚Ĺ‚ľ‚˝" );
2145     }
2146 notanpe 223 #endif /* ALLKEY */
2147     /* MAKAI end */
2148 notanpe 213 log_printf(ofp, "Ÿ%s %s"
2149     "\t%04d/%02d/%02d %02d:%02d:%02d.%03d"
2150     "\t(%02X %02X %02X %02X %02X %02X %02X %02X/%02X) %02d\n",
2151     hash, buf2,
2152     plt->tm_year + 1900, plt->tm_mon + 1, plt->tm_mday,
2153     plt->tm_hour, plt->tm_min, plt->tm_sec, tb.millitm,
2154     buf[0], buf[1], buf[2], buf[3],
2155     buf[4], buf[5], buf[6], buf[7],
2156     buf[8], hitLen);
2157 notanpe 196 /* MAKAI end */
2158 notanpe 193
2159 chapuni 1 }
2160     }
2161    
2162 notanpe 192 /* ‘Ź“xŒv‘Ş */
2163 notanpe 115 status.loop += N_ALU * ALU_BITS;
2164 notanpe 192 if (status.loop>= status.lastloop + upd_int
2165     && (curTime = usec()) != status.lastTime)
2166 chapuni 1 {
2167 notanpe 192 uint64_t diffTime;
2168 notanpe 120 int a, b, c;
2169 notanpe 119
2170 notanpe 192 /* ’ĘŽZ(’PˆĘ ktrips/sec) */
2171     diffTime = curTime - status.startTime;
2172     a = status.loop / ((1000 / USEC_SEC) * diffTime);
2173    
2174 notanpe 213 /* MAKAI start */
2175     #ifdef BENCH
2176     if ( (diffTime / USEC_SEC) > (BENCH * 60) ) {
2177     fprintf( stderr, "\n%6dktrips/s\n", a );
2178     exit( 0 );
2179     }
2180     #endif /* BENCH */
2181     /* MAKAI end */
2182    
2183 notanpe 192 /* ‹ćŠÔ(’PˆĘ trips/sec) */
2184 notanpe 120 diffTime = curTime - status.lastTime;
2185 notanpe 192 b = USEC_SEC * (status.loop - status.lastloop) / diffTime;
2186    
2187     /* —\‘Ş */
2188     c = UPDATE_INTERVAL * b;
2189    
2190     /* —§‚żă‚Ş‚č‚ȂǁAŒëˇ‚Ş‚ ‚č upd_int ‚ŞŹ‚ł‚ˇ‚Ź‚˝‚Ć‚Ť‚Í
2191     ‚˘‚Ť‚Č‚č‘S•␳‚š‚¸ 1 •b(==b)‚ŽűĘ‚ł‚š‚éB */
2192     upd_int = (upd_int + b < c
2193     ? upd_int + b
2194     : c);
2195    
2196 notanpe 120 status.lastTime = curTime;
2197     status.lastloop = status.loop;
2198 chapuni 77 #if DEBUG>=1
2199 notanpe 119 fprintf(stderr,
2200     "%5d/%5d(%3d%%)",
2201     nblk_hit, nblk_total, 100 * nblk_hit / nblk_total);
2202     nblk_hit = nblk_total = 0;
2203     if (nap_total)
2204     fprintf(stderr,
2205     " %5d/%5d(%3d%%)",
2206     nap_hit, nap_total, 100 * nap_hit / nap_total);
2207     else
2208     fprintf(stderr,
2209     " -----/-----(---%%)");
2210     nap_hit = nap_total = 0;
2211 chapuni 77 #endif
2212 notanpe 119 fprintf( stderr,
2213 notanpe 120 "%6dktrips/s [%6d.%03dktrips/s]\r",
2214     a, b / 1000, b % 1000 );
2215 notanpe 192 cr++;
2216 chapuni 1 }
2217     }
2218    
2219     return 0;
2220     }
2221    
2222 chapuni 2 /*
2223     * Local Variables:
2224     * tab-width: 4
2225     * End:
2226     *
2227     * EOF */

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Rev URL

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26