Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 260 - (show annotations) (download) (as text)
Wed Jan 12 09:00:49 2011 UTC (13 years, 3 months ago) by notanpe
File MIME type: text/x-csrc
File size: 3680 byte(s)
特殊検索を実装。
gettid() をちょっとマシにした。
1 /***********************************************************************
2 *
3 * file: hit.c
4 *
5 * $Id: hit.c 244 2010-03-16 13:54:51Z chapuni $
6 *
7 */
8
9 #include <stdio.h>
10 #include <string.h>
11
12 #include "desconst.h"
13 #include "hit.h"
14 #include "log.h"
15 #include "synth.h"
16 #include "tr64.h"
17 #include "translate.h"
18 #include "wdict.h"
19
20 /***************************************************************
21 *
22 * ŒŽ“]’u
23 *
24 */
25
26 static
27 void tr8_32(uint32_t (*A)[4])
28 {
29 int j, k;
30 uint32_t m, t;
31 m = 0xF0F0F0F0UL;
32 for (j = 4; j != 0; j >>= 1, m = m ^ (m >> j))
33 {
34 for (k = 0; k < 64; k = (k + j + 1) & ~j)
35 {
36 t = (A[k][0] ^ (A[k + j][0] << j)) & m;
37 A[k][0] ^= t;
38 A[k + j][0] ^= (t >> j);
39 }
40 }
41 }
42
43 static
44 void trk8(struct PACKET_CRYPT64 const *pkt, uint8_t *k8)
45 {
46 int i, j;
47
48 for (i = 0; i < 8; i++)
49 {
50 memset(&k8[128 * i + 16 * 7],
51 ((i == 1 || i == 2) && pkt->uk.key[i] & 0x80 ? -1 : 0),
52 16);
53 for (j = 0; j < 7; j++)
54 {
55 int o = tr_pc1[i][6 - j] - 1;
56 memcpy(&k8[128 * i + 16 * j],
57 (o < 28
58 ? &pkt->key64.k[0][0][o]
59 : &pkt->key64.k[1][0][o - 28]),
60 16);
61 }
62 }
63 for (i = 0; i < 4; i++)
64 {
65 tr8_32((uint32_t (*)[4])&k8[4 * i]);
66 }
67 }
68
69 /***************************************************************
70 *
71 * ƒqƒbƒg”ť’č
72 *
73 */
74
75 void
76 check_hit(struct PACKET_CRYPT64 const *pkt_c,
77 SLICE const *hit)
78 {
79 int i, k, kk;
80
81 int xhash_loaded = 0;
82 uint64_t xhash[64];
83
84 int xkey_loaded = 0;
85 uint8_t xkey_buf[8][16][8];
86
87 #ifdef SPECIAL
88 extern int special;
89 #endif /* SPECIAL */
90
91 for (kk = 0; kk < N_ALU; kk++)
92 {
93
94 ALU_T t;
95 if (!(kk & (N_ALU / N_Q - 1)))
96 xhash_loaded = 0;
97
98 #ifdef SPECIAL
99 if ( special ) {
100 char hash[16];
101 FILE *lfp;
102 unsigned char kind[3];
103 uint8_t buf[32];
104
105 CALL_TR64(&pkt_c->param64.lr[0][0].q[kk / (N_ALU / N_Q)], xhash);
106 xhash_loaded = 1;
107 for ( k = 0; k < ALU_BITS; k++ ) {
108 for ( i = 1; i < 11; i++ ) {
109 unsigned c = 0;
110 c = (xhash[(ALU_BITS * kk + k) & 63] >> (6 * (i - 1))) & 0x3F;
111 hash[i - 1] = C64[c];
112 }
113 hash[10] = 0;
114 if ( (lfp = checkSpecial( hash, kind )) != NULL ) {
115 trk8(pkt_c, &xkey_buf[0][0][0]);
116 xkey_loaded = 1;
117 for ( i = 0; i < 8; i++ ) {
118 buf[i] = xkey_buf[i][0][((ALU_BITS * kk + k) >> 3) | (((ALU_BITS * kk + k) & 7) << 4)];
119 }
120 buf[8] = buf[9] = 0;
121 log_print(lfp, translate(buf, 0, 1), hash, buf);
122 }
123 }
124 }
125 #endif /* SPECIAL */
126
127 t = hit[HIT_ANY].a[kk];
128 if (!t)
129 continue;
130
131 for (k = 0; k < ALU_BITS; k++)
132 {
133 char hash[16];
134 uint8_t buf[32];
135
136 if (!(t & ((ALU_T)1 << k)))
137 continue;
138
139 /* “]’u */
140 if (!xhash_loaded)
141 {
142 CALL_TR64(&pkt_c->param64.lr[0][0].q[kk / (N_ALU / N_Q)], xhash);
143 xhash_loaded = 1;
144 }
145
146 /* ŽŤ‘‚𒲂ׂé */
147 if (!((hit[HIT_BOOL].a[kk] & ((ALU_T)1 << k))
148 || wdict_ishit(hit,
149 kk, k,
150 xhash[(ALU_BITS * kk + k) & 0x3F])))
151 continue;
152
153 for (i = 1; i < 11; i++)
154 {
155 unsigned c = 0;
156 c = (xhash[(ALU_BITS * kk + k) & 63] >> (6 * (i - 1))) & 0x3F; /* XXX */
157 hash[i - 1] = C64[c];
158 }
159 hash[10] = 0;
160 if (!xkey_loaded)
161 {
162 trk8(pkt_c, &xkey_buf[0][0][0]);
163 xkey_loaded = 1;
164 }
165
166 for (i = 0; i < 8; i++)
167 buf[i] = xkey_buf[i][0][((ALU_BITS * kk + k) >> 3) | (((ALU_BITS * kk + k) & 7) << 4)];
168 buf[8] = buf[9] = 0;
169 if ((buf[0] & 0x7F) == 0)
170 {
171 /* do nothing */
172 }
173 else
174 {
175 log_print(NULL, translate(buf, 0, 1), hash, buf);
176 }
177 }
178 }
179 }
180
181 /*
182 * Local Variables:
183 * tab-width: 4
184 * End:
185 *
186 * EOF */

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26