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