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