| 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 <stdint.h> |
| 33 |
#include <string.h> |
| 34 |
|
| 35 |
#include "lmflash.h" |
| 36 |
#include "lmtable.h" |
| 37 |
#include "hash.h" |
| 38 |
#include "ophel.h" |
| 39 |
#include "original.h" |
| 40 |
#include "misc.h" |
| 41 |
|
| 42 |
static uint64_t lmflash_sizes[14] = { 6, 268435456, 5279834004ULL, 10559668008ULL, 5279862016ULL, 10559724032ULL, 5279757448ULL, 10559514896ULL, 5279801098ULL, 10559602196ULL, 5279747172ULL, 10559494344ULL, 5279855682ULL, 10559711364ULL}; |
| 43 |
|
| 44 |
int lmflash_setup(void *tbl_) { |
| 45 |
table_t *tbl = tbl_; |
| 46 |
|
| 47 |
tbl->ncols = 2200; |
| 48 |
tbl->offset = 100000; |
| 49 |
tbl->sizes = lmflash_sizes; |
| 50 |
|
| 51 |
tbl->find = lmflash_find; |
| 52 |
tbl->check = lmtable_check; |
| 53 |
tbl->isvalid = lmtable_isvalid; |
| 54 |
|
| 55 |
tbl->lookup_idx = lmtable_lookup_idx; |
| 56 |
tbl->lookup_end = lmtable_lookup_end; |
| 57 |
tbl->lookup_srt = lmflash_lookup_srt; |
| 58 |
|
| 59 |
return 1; |
| 60 |
} |
| 61 |
|
| 62 |
void lmflash_find(void *hsh_, void *tbl_, void *el_) { |
| 63 |
hash_t *hsh = hsh_; |
| 64 |
table_t *tbl = tbl_; |
| 65 |
ophel_t *el = el_; |
| 66 |
uchar_t *hash = hsh->hash;; |
| 67 |
uchar_t *pwd = (uchar_t*)el->pwd; |
| 68 |
ophstat_t *stat = el->stat; |
| 69 |
|
| 70 |
int c; |
| 71 |
int col = el->col; |
| 72 |
int ncols = tbl->ncols; |
| 73 |
int n_redux = col + tbl->idx * tbl->offset; |
| 74 |
|
| 75 |
uchar_t tmp[8]; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
lmtable_mkredux(tbl, hash, pwd, n_redux); |
| 80 |
|
| 81 |
for (c=1; c<ncols-col; ++c) { |
| 82 |
++n_redux; |
| 83 |
|
| 84 |
lmtable_mkhash(pwd, tmp); |
| 85 |
lmtable_mkredux(tbl, tmp, pwd, n_redux); |
| 86 |
++stat->hredux; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
uint64_t pw_bin = lmflash_bin69(pwd); |
| 92 |
uint32_t prefix = (uint32_t)(pw_bin >> 17 & 0x00000000FFFFFFFF); |
| 93 |
uint16_t postfix = (uint16_t)(pw_bin & 0x000000000000FFFF); |
| 94 |
|
| 95 |
el->prefix = prefix; |
| 96 |
el->postfix = postfix; |
| 97 |
} |
| 98 |
|
| 99 |
int lmflash_lookup_srt(void *hsh_, void *tbl_, void *el_) { |
| 100 |
table_t *tbl = tbl_; |
| 101 |
ophel_t *el = el_; |
| 102 |
|
| 103 |
uint64_t offset = el->offset; |
| 104 |
uint32_t start; |
| 105 |
|
| 106 |
ophstat_t *stat = el->stat; |
| 107 |
++stat->start; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
if (tbl->srtmem) { |
| 112 |
uint32_t *mem = (uint32_t*)(tbl->srtmem + offset); |
| 113 |
start = mem[0]; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
else { |
| 119 |
FILE *srtfile = tbl->srtfile; |
| 120 |
|
| 121 |
fseeko(srtfile, offset, SEEK_SET); |
| 122 |
fread(&start, sizeof(start), 1, srtfile); |
| 123 |
++stat->fseek_srt; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
start = ftohl(start); |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
uchar_t *pwd = (uchar_t*)el->pwd; |
| 133 |
|
| 134 |
memset(pwd, 0, 8); |
| 135 |
|
| 136 |
lmflash_unbin69(start, pwd); |
| 137 |
|
| 138 |
return 1; |
| 139 |
} |
| 140 |
|
| 141 |
uint64_t lmflash_bin69(uchar_t *input) { |
| 142 |
int i = 0; |
| 143 |
uint64_t sum = 0; |
| 144 |
uint64_t offset = 7446353252589ULL; |
| 145 |
|
| 146 |
for (i=0; i<7; i++) { |
| 147 |
if (input[i]) { |
| 148 |
char *x1 = (char*)memchr(extended_chars, input[i], 73); |
| 149 |
char *x2 = (char*)extended_chars; |
| 150 |
|
| 151 |
sum = sum*69 + (uint64_t)(x1-x2); |
| 152 |
} else { |
| 153 |
sum += offset; |
| 154 |
offset /= 69; |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
return sum; |
| 159 |
} |
| 160 |
|
| 161 |
void lmflash_unbin69(uint32_t input, uchar_t *output) { |
| 162 |
int i = 0; |
| 163 |
|
| 164 |
for (i=5; i>=0; i--) { |
| 165 |
output[i] = extended_chars[input % 69]; |
| 166 |
input /= 69; |
| 167 |
} |
| 168 |
} |