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