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