| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#include <string.h> |
| 33 |
|
| 34 |
#include "ntextended.h" |
| 35 |
#include "table.h" |
| 36 |
#include "hash.h" |
| 37 |
#include "ophel.h" |
| 38 |
#include "original.h" |
| 39 |
#include "lmtable.h" |
| 40 |
|
| 41 |
static uint64_t ntextended_sizes[10] = { 4, 108118236, 672425284, 1344850568, 672442590, 1344885180, 672411252, 1344822504, 672417770, 1344835540}; |
| 42 |
|
| 43 |
int ntextended_setup(void *tbl_) { |
| 44 |
table_t *tbl = tbl_; |
| 45 |
|
| 46 |
tbl->ncols = 24320; |
| 47 |
tbl->offset = 50000; |
| 48 |
tbl->sizes = ntextended_sizes; |
| 49 |
|
| 50 |
tbl->find = ntextended_find; |
| 51 |
tbl->check = ntextended_check; |
| 52 |
tbl->isvalid = ntextended_isvalid; |
| 53 |
|
| 54 |
tbl->lookup_idx = lmtable_lookup_idx; |
| 55 |
tbl->lookup_end = lmtable_lookup_end; |
| 56 |
tbl->lookup_srt = ntextended_lookup_srt; |
| 57 |
|
| 58 |
return 1; |
| 59 |
} |
| 60 |
|
| 61 |
void ntextended_find(void *hsh_, void *tbl_, void *el_) { |
| 62 |
hash_t *hsh = hsh_; |
| 63 |
table_t *tbl = tbl_; |
| 64 |
ophel_t *el = el_; |
| 65 |
uchar_t *hash = hsh->hash; |
| 66 |
uchar_t *pwd = (uchar_t*)el->pwd; |
| 67 |
ophstat_t *stat = el->stat; |
| 68 |
|
| 69 |
int c; |
| 70 |
int col = el->col; |
| 71 |
int ncols = tbl->ncols; |
| 72 |
int n_redux = col + tbl->idx * tbl->offset; |
| 73 |
|
| 74 |
uchar_t tmp[16]; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
ntextended_mkredux(tbl, hash, pwd, n_redux); |
| 79 |
|
| 80 |
for (c=1; c<ncols-col; ++c) { |
| 81 |
++n_redux; |
| 82 |
|
| 83 |
ntextended_mkhash(pwd, tmp); |
| 84 |
ntextended_mkredux(tbl, tmp, pwd, n_redux); |
| 85 |
++stat->hredux; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
uint64_t pw_bin = ntextended_bin43(pwd); |
| 91 |
uint32_t prefix = (uint32_t)(pw_bin >> 18 & 0x00000000FFFFFFFF); |
| 92 |
uint16_t postfix = (uint16_t)(pw_bin & 0x000000000000FFFF); |
| 93 |
|
| 94 |
el->prefix = prefix; |
| 95 |
el->postfix = postfix; |
| 96 |
} |
| 97 |
|
| 98 |
int ntextended_lookup_srt(void *hsh_, void *tbl_, void *el_) { |
| 99 |
table_t *tbl = tbl_; |
| 100 |
ophel_t *el = el_; |
| 101 |
|
| 102 |
uint64_t offset = el->offset; |
| 103 |
uint32_t start; |
| 104 |
|
| 105 |
ophstat_t *stat = el->stat; |
| 106 |
++stat->start; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
if (tbl->srtmem) { |
| 111 |
uint32_t *mem = (uint32_t*)(tbl->srtmem + offset); |
| 112 |
start = mem[0]; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
else { |
| 118 |
FILE *srtfile = tbl->srtfile; |
| 119 |
|
| 120 |
fseeko(srtfile, offset, SEEK_SET); |
| 121 |
fread(&start, sizeof(start), 1, srtfile); |
| 122 |
++stat->fseek_srt; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
start = ftohl(start); |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
uchar_t *pwd = (uchar_t*)el->pwd; |
| 132 |
|
| 133 |
pwd[5] = 0; |
| 134 |
pwd[6] = 0; |
| 135 |
pwd[7] = 0; |
| 136 |
|
| 137 |
ntextended_unbin95(start, pwd); |
| 138 |
|
| 139 |
return 1; |
| 140 |
} |
| 141 |
|
| 142 |
int ntextended_check(void *hsh_, void *tbl_, void *el_) { |
| 143 |
hash_t *hsh = hsh_; |
| 144 |
table_t *tbl = tbl_; |
| 145 |
ophel_t *el = el_; |
| 146 |
uchar_t *hash = hsh->hash; |
| 147 |
uchar_t *pwd = (uchar_t*)el->pwd; |
| 148 |
ophstat_t *stat = el->stat; |
| 149 |
|
| 150 |
int c; |
| 151 |
int col = el->col; |
| 152 |
int ncols = tbl->ncols; |
| 153 |
int n_redux = tbl->idx * tbl->offset; |
| 154 |
|
| 155 |
uchar_t tmp[16]; |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
stat->falarm_hredux = 0; |
| 160 |
|
| 161 |
for (c=ncols-col; c<ncols; ++c) { |
| 162 |
ntextended_mkhash(pwd, tmp); |
| 163 |
ntextended_mkredux(tbl, tmp, pwd, n_redux); |
| 164 |
|
| 165 |
++n_redux; |
| 166 |
++stat->hredux; |
| 167 |
++stat->falarm_hredux; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
ntextended_mkhash(pwd, tmp); |
| 173 |
|
| 174 |
if (memcmp(tmp, hash, sizeof(tmp)) == 0) { |
| 175 |
++stat->match_table; |
| 176 |
stat->falarm_hredux = 0; |
| 177 |
return 1; |
| 178 |
} |
| 179 |
|
| 180 |
else { |
| 181 |
++stat->falarm; |
| 182 |
return 0; |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
int ntextended_isvalid(void *hsh_, void *tbl_) { |
| 187 |
hash_t *hsh = hsh_; |
| 188 |
|
| 189 |
return hsh->kind == nt ? 1 : 0; |
| 190 |
} |
| 191 |
|
| 192 |
void ntextended_mkredux(table_t *tbl, uchar_t *hash, uchar_t *pwd, |
| 193 |
int n_redux) { |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
uint32_t idx[4]; |
| 198 |
|
| 199 |
idx[0] = ftohl(*(uint32_t*)hash) ^ n_redux; |
| 200 |
idx[1] = ftohl(*(uint32_t*)(hash+4)); |
| 201 |
idx[2] = ftohl(*(uint32_t*)(hash+8)); |
| 202 |
idx[3] = ftohl(*(uint32_t*)(hash+12)); |
| 203 |
|
| 204 |
int n = idx[3]; |
| 205 |
int i; |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
pwd[8] = 0; |
| 210 |
|
| 211 |
if (n > ntextended_max[8]) { |
| 212 |
for (i=0; i<3; ++i) { |
| 213 |
pwd[i] = ntextended_low36[idx[0] % 36]; |
| 214 |
idx[0] /= 36; |
| 215 |
} |
| 216 |
|
| 217 |
for (i=3; i<6; ++i) { |
| 218 |
pwd[i] = ntextended_low36[idx[1] % 36]; |
| 219 |
idx[1] /= 36; |
| 220 |
} |
| 221 |
|
| 222 |
for (i=6; i<8; ++i) { |
| 223 |
pwd[i] = ntextended_low36[idx[2] % 36]; |
| 224 |
idx[2] /= 36; |
| 225 |
} |
| 226 |
} else if (n > ntextended_max[7]) { |
| 227 |
for (i=0; i<3; ++i) { |
| 228 |
pwd[i] = ntextended_alphanum62[idx[0] % 62]; |
| 229 |
idx[0] /= 62; |
| 230 |
} |
| 231 |
|
| 232 |
for (i=3; i<7; ++i) { |
| 233 |
pwd[i] = ntextended_alphanum62[idx[1] % 62]; |
| 234 |
idx[1] /= 62; |
| 235 |
} |
| 236 |
|
| 237 |
pwd[7] = 0; |
| 238 |
} else { |
| 239 |
for (i=0; i<3; ++i) { |
| 240 |
pwd[i] = ntextended_ext95[idx[0] % 95]; |
| 241 |
idx[0] /= 95; |
| 242 |
} |
| 243 |
|
| 244 |
for (i=3; i<6; ++i) { |
| 245 |
pwd[i] = ntextended_ext95[idx[1] % 95]; |
| 246 |
idx[1] /= 95; |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
pwd[7] = 0; |
| 252 |
pwd[6] = 0; |
| 253 |
|
| 254 |
if (n < ntextended_max[6]) { |
| 255 |
pwd[5]=0; |
| 256 |
if (n < ntextended_max[5]) { |
| 257 |
pwd[4]=0; |
| 258 |
if (n < ntextended_max[4]) { |
| 259 |
pwd[3]=0; |
| 260 |
if (n < ntextended_max[3]) { |
| 261 |
pwd[2]=0; |
| 262 |
if (n < ntextended_max[2]) { |
| 263 |
pwd[1]=0; |
| 264 |
} |
| 265 |
} |
| 266 |
} |
| 267 |
} |
| 268 |
} |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
void ntextended_mkhash(uchar_t *pwd, uchar_t *hash) { |
| 273 |
make_nthash((char*)pwd, (char*)hash); |
| 274 |
} |
| 275 |
|
| 276 |
uint64_t ntextended_bin43(uchar_t *input) { |
| 277 |
int i; |
| 278 |
int l = (int)strlen((char*)input); |
| 279 |
uint64_t sum = 0; |
| 280 |
|
| 281 |
if (l<7) |
| 282 |
for (i=0; i<l && i<6; i++) { |
| 283 |
char *x1 = strchr((char*)ntextended_ext95, input[i]); |
| 284 |
char *x2 = (char*)ntextended_ext95; |
| 285 |
|
| 286 |
sum = sum*95 + (uint64_t)(x1-x2); |
| 287 |
} |
| 288 |
|
| 289 |
else if (l==7) |
| 290 |
for (i=0; i<7; i++) { |
| 291 |
char *x1 = strchr((char*)ntextended_alphanum62, input[i]); |
| 292 |
char *x2 = (char*)ntextended_alphanum62; |
| 293 |
|
| 294 |
sum = sum*62 + (uint64_t)(x1-x2); |
| 295 |
} |
| 296 |
|
| 297 |
else if (l==8) |
| 298 |
for (i=0; i<8; i++) { |
| 299 |
char *x1 = strchr((char*)ntextended_low36, input[i]); |
| 300 |
char *x2 = (char*)ntextended_low36; |
| 301 |
|
| 302 |
sum = sum*36 + (uint64_t)(x1-x2); |
| 303 |
} |
| 304 |
|
| 305 |
sum += ntextended_offset[l-1]; |
| 306 |
|
| 307 |
return sum; |
| 308 |
} |
| 309 |
|
| 310 |
void ntextended_unbin95(uint32_t input, uchar_t *output) { |
| 311 |
int i = 0; |
| 312 |
|
| 313 |
for (i=4; i>=0; i--) { |
| 314 |
output[i] = ntextended_ext95[input % 95]; |
| 315 |
input /= 95; |
| 316 |
} |
| 317 |
} |