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