Develop and Download Open Source Software

Browse Subversion Repository

Contents of /branches/mty-makai/mty.c

Parent Directory Parent Directory | Revision Log Revision Log


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