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