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