Debian Codegraph @

src/ntproba/pattern.c

raw symbols SCIP
1 /*
2 *
3 * Ophcrack is a Lanmanager/NTLM hash cracker based on the faster time-memory
4 * trade-off using rainbow tables.
5 *
6 * Created with the help of: Maxime Mueller, Luca Wullschleger, Claude
7 * Hochreutiner, Andreas Huber and Etienne Dysli.
8 *
9 * Copyright (c) 2013 Philippe Oechslin, Cedric Tissieres,
10 * Bertrand Mesot, Pierre Lestringant
11 *
12 * Ophcrack is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * Ophcrack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with Ophcrack; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * This program is released under the GPL with the additional exemption
27 * that compiling, linking, and/or using OpenSSL is allowed.
28 *
29 *
30 *
31 *
32 */
33 /* WARNING: this file is a NOT copy from implCPU/v6 */
34
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <math.h>
39 #include <time.h>
40
41 #include "pattern.h"
42 #include "patternDescriptor.h"
43
44
45 uint64_t power(unsigned int a, unsigned int b){
46 uint64_t result = 1;
47 unsigned int i;
48
49 for (i = 0; i < b; i++){
50 result *= a;
51 }
52
53 return result;
54 }
55
56
57 uint64_t getPatternStructSpace(markovDynProgWrapper* mdpw, markovImprobaStruct* mis, uint64_t descriptor, uint64_t length){
58 uint64_t result = 1;
59 unsigned int i = 0;
60 unsigned int l;
61
62 for (i = 0; i < PATTERN_ARRAY_MAX_LENGTH; i++){
63 switch ((char)(descriptor >> (i*4)) & 0x0f){
64 case DESC_NUMERAL : {
65 result = result*10;
66 break;
67 }
68 case DESC_SPECIAL : {
69 result = result*33;
70 break;
71 }
72 case DESC_UPPER_NOMARK : {
73 result = result*26;
74 break;
75 }
76 case DESC_UPPER_MARKFIRST : {
77 l = (unsigned int)((char)(length >> (i*4)) & 0x0f) + 1;
78 result = result*getMarkovDynProgRootValue(mdpw, mis, l);
79 break;
80 }
81 case DESC_LOWER_NOMARK : {
82 result = result*26;
83 break;
84 }
85 case DESC_LOWER_MARKFIRST : {
86 l = (unsigned int)((char)(length >> (i*4)) & 0x0f) + 1;
87 result = result*getMarkovDynProgRootValue(mdpw, mis, l);
88 break;
89 }
90 default : {break;}
91 }
92 }
93 return result;
94 }
95
96
97 char checkPatternArrayCrackMarkov(patternArray* array, markovDynProgWrapper* mdpw, markovImprobaStruct* mis){
98 unsigned int i;
99 char result = 1;
100
101 for (i = 0; i < array->size-1; i++){
102 if (array->sizeArray[i] != getPatternStructSpace(mdpw, mis, array->patternDescriptor[i], array->patternLength[i])){
103 printf("Pattern %d: size error %llu vs %llu\n", i,
104 (long long unsigned int)array->sizeArray[i],
105 (long long unsigned int)getPatternStructSpace(mdpw, mis, array->patternDescriptor[i], array->patternLength[i]));
106 result = 0;
107 }
108 }
109 if (array->sizeArray[array->size-1] > getPatternStructSpace(mdpw, mis, array->patternDescriptor[array->size-1], array->patternLength[array->size-1])){
110 printf("Pattern %d: size error %llu vs %llu\n", i,
111 (long long unsigned int)array->sizeArray[array->size-1],
112 (long long unsigned int)getPatternStructSpace(mdpw, mis, array->patternDescriptor[array->size-1], array->patternLength[array->size-1]));
113 result = 0;
114 }
115 return result;
116 }
117
118 void deletePatternArray(patternArray* array){
119 if (array->patternDescriptor != NULL){
120 free(array->patternDescriptor);
121 }
122 if (array->patternLength != NULL){
123 free(array->patternLength);
124 }
125 if (array->lut != NULL){
126 deleteLookUpTable(array->lut);
127 free(array->lut);
128 }
129 if (array->sizeArray != NULL){
130 free(array->sizeArray);
131 }
132 }
133
134
135
136 unsigned int getMaxPatternLength(patternArray* array){
137 unsigned int i;
138 unsigned int maxLength = 0;
139 unsigned int currentLength;
140 unsigned int c;
141
142 for (i = 0; i < array->size; i++){
143 currentLength = 0;
144 for (c = 0; c < PATTERN_ARRAY_MAX_LENGTH; c++){
145 if (((array->patternDescriptor[i] >> (4*c))&0x000000000000000f) != DESC_IGNORED){
146 currentLength++;
147 }
148 }
149 if (currentLength > maxLength){
150 maxLength = currentLength;
151 }
152 }
153
154 return maxLength;
155 }