Rev 8472 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8251 | superturbo | 1 | |
2 | |||
3 | |||
4 | #include "tea.c" |
||
5 | #include |
||
6 | #include |
||
7 | #include |
||
8 | #include "lang_en.c" |
||
9 | #include |
||
10 | |||
11 | |||
12 | #define DECRYPT 2 |
||
13 | |||
14 | |||
15 | uint32_t key[4]; |
||
16 | |||
17 | |||
18 | { |
||
19 | fseek(file, 0, SEEK_END); |
||
20 | long size = ftell(file); |
||
21 | fseek(file, 0, SEEK_SET); |
||
22 | return size; |
||
23 | } |
||
24 | |||
25 | |||
26 | { |
||
27 | fseek(file, 0, SEEK_END); |
||
28 | long size = ftell(file); |
||
29 | fseek(file, 0, SEEK_SET); |
||
30 | if(size%8==0) |
||
31 | { |
||
32 | return size; |
||
33 | } |
||
34 | else |
||
35 | { |
||
36 | return (size/8+1)*8; |
||
37 | } |
||
38 | } |
||
39 | |||
40 | |||
41 | { |
||
42 | FILE *input, *output; |
||
43 | |||
44 | |||
45 | { |
||
46 | printf(FILE_NOT_FOUND, in_file); |
||
47 | exit(1); |
||
48 | } |
||
49 | |||
50 | |||
51 | |||
52 | |||
53 | uint8_t size_diff; |
||
54 | size_diff=(uint8_t)(size_f-size_orig_file(input)); |
||
55 | uint32_t *buff; |
||
56 | buff=malloc(size_f); |
||
57 | if(!buff) |
||
58 | { |
||
59 | puts(MEMORY_ERROR); |
||
60 | exit(-1); |
||
61 | } |
||
62 | |||
63 | |||
64 | { |
||
65 | printf(LOAD_IN_RAM,in_file); |
||
66 | fread(buff, 1,size_f, input); |
||
67 | printf(FILE_ENCRYPTION); |
||
68 | |||
69 | |||
70 | { |
||
71 | TEA_encrypt(buff+i,key); |
||
72 | } |
||
73 | |||
74 | |||
75 | fwrite(&size_diff,1, 1, output); |
||
76 | fwrite(buff,1,size_f, output); |
||
77 | fclose(input); |
||
78 | fclose(output); |
||
79 | printf(DATA_ENCRYPT,in_file,out_file); |
||
80 | exit(0); |
||
81 | } |
||
82 | |||
83 | |||
84 | { |
||
85 | long size_f=size_orig_file(input); |
||
86 | printf(LOAD_IN_RAM,in_file); |
||
87 | fread(&size_diff,1,1,input); |
||
88 | fread(buff,1,size_f-1, input); |
||
89 | printf(FILE_DECRYPTION); |
||
90 | |||
91 | |||
92 | { |
||
93 | TEA_decrypt(buff+i,key); |
||
94 | } |
||
95 | |||
96 | |||
97 | fwrite(buff,1,size_f-size_diff-1, output); |
||
98 | fclose(input); |
||
99 | fclose(output); |
||
100 | printf(DATA_DECRYPT,in_file,out_file); |
||
101 | exit(0); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | |||
106 | { |
||
107 | uint32_t temp_block[2]; |
||
108 | FILE *input, *output; |
||
109 | |||
110 | |||
111 | { |
||
112 | printf(FILE_NOT_FOUND, in_file); |
||
113 | exit(1); |
||
114 | } |
||
115 | |||
116 | |||
117 | |||
118 | |||
119 | uint8_t size_diff=(uint8_t)(size_f-size_orig_file(input)); |
||
120 | |||
121 | |||
122 | fwrite(&size_diff,1,1,output); |
||
123 | printf(FILE_ENCRYPTION); |
||
124 | |||
125 | |||
126 | { |
||
127 | memset(temp_block, 0x00, 2); |
||
128 | fread(temp_block, sizeof(uint32_t), 2, input) ; |
||
129 | TEA_encrypt(temp_block,key); |
||
130 | fwrite(temp_block, sizeof(uint32_t),2, output); |
||
131 | } |
||
132 | |||
133 | |||
134 | fclose(output); |
||
135 | printf(DATA_ENCRYPT,in_file,out_file); |
||
136 | exit(0); |
||
137 | |||
138 | |||
139 | else if(arg==DECRYPT){ |
||
140 | size_f = size_orig_file(input); |
||
141 | fread(&size_diff,1,1,input); |
||
142 | size_f=size_f-size_diff-1; |
||
143 | printf(FILE_DECRYPTION); |
||
144 | |||
145 | |||
146 | { |
||
147 | fread(temp_block, sizeof(uint32_t), 2, input); |
||
148 | TEA_decrypt(temp_block,key); |
||
149 | |||
150 | |||
151 | { |
||
152 | fwrite(temp_block,sizeof(uint32_t),2,output); |
||
153 | } |
||
154 | else |
||
155 | { |
||
156 | fwrite(temp_block,1,size_f,output); |
||
157 | } |
||
158 | |||
159 | |||
160 | |||
161 | |||
162 | { |
||
163 | size_f=0; |
||
164 | } |
||
165 | } |
||
166 | |||
167 | |||
168 | fclose(output); |
||
169 | printf(DATA_DECRYPT,in_file,out_file); |
||
170 | exit(0); |
||
171 | } |
||
172 | } |
||
173 | |||
174 | |||
175 | |||
176 | |||
177 | { |
||
178 | int count=0; |
||
179 | for(int i=0; i<4; i++) |
||
180 | { |
||
181 | int j=0; |
||
182 | while (j<8) |
||
183 | { |
||
184 | str_key[i][j]=str[count]; |
||
185 | count++; |
||
186 | j++; |
||
187 | } |
||
188 | } |
||
189 | } |
||
190 | |||
191 | |||
192 | { |
||
193 | int count=0; |
||
194 | char hex[]={"abcdefABCDEF0123456789"}; |
||
195 | for(int i=0; i<32; i++) |
||
196 | { |
||
197 | if(strchr(hex,str[i])!=NULL) |
||
198 | { |
||
199 | count++; |
||
200 | } |
||
201 | } |
||
202 | if(count==32){return 1;} |
||
203 | else{ return 0;} |
||
204 | } |
||
205 | |||
206 | |||
207 | |||
208 | { |
||
209 | char str_key[4][9]; |
||
210 | if(valid_key(str)&&(strlen(str)==32)) |
||
211 | { |
||
212 | for(int i=0; i<4; i++) |
||
213 | { |
||
214 | str_to_strkey(str, str_key); |
||
215 | key[i]=(uint32_t)strtol(str_key[i],NULL,16); |
||
216 | } |
||
217 | |||
218 | |||
219 | |||
220 | |||
221 | { |
||
222 | printf(INVALID_KEY_FORMAT); |
||
223 | exit(-1); |
||
224 | } |
||
225 | } |
||
226 | |||
227 | |||
228 | { |
||
229 | FILE *keyfile; |
||
230 | if((keyfile = fopen(key_file,"rb"))==NULL) |
||
231 | { |
||
232 | printf(FILE_NOT_FOUND, key_file); |
||
233 | exit(-1); |
||
234 | } |
||
235 | |||
236 | |||
237 | { |
||
238 | fread(key,sizeof(uint32_t),4, keyfile); |
||
239 | } |
||
240 | else |
||
241 | { |
||
242 | printf(INVALID_KEY_FORMAT); |
||
243 | exit(-1); |
||
244 | } |
||
245 | |||
246 | |||
247 | } |
||
248 | |||
249 | |||
250 | |||
251 | { |
||
252 | char found=0; |
||
253 | for(int j=3; j |
||
254 | { |
||
255 | if(!strcmp(argv[j],"-k")) |
||
256 | { |
||
257 | found=1; |
||
258 | key_con_read(argv[j+1]); |
||
259 | break; |
||
260 | } |
||
261 | else if(!strcmp(argv[j],"-K")) |
||
262 | { |
||
263 | found=1; |
||
264 | key_file_read(argv[j+1]); |
||
265 | break; |
||
266 | } |
||
267 | } |
||
268 | |||
269 | |||
270 | { |
||
271 | printf(NO_KEY_OR_KEYFILE); |
||
272 | exit(-1); |
||
273 | } |
||
274 | |||
275 | |||
276 | |||
277 | if(!strcmp(argv[i],"-e")) |
||
278 | { |
||
279 | if(!strcmp(argv[i+1],"normal")){xcrypt_file(in_file, out_file, ENCRYPT);} |
||
280 | if(!strcmp(argv[i+1],"speed")){xcrypt_file_speed(in_file, out_file, ENCRYPT);} |
||
281 | } |
||
282 | if(!strcmp(argv[i],"-d")) |
||
283 | { |
||
284 | if(!strcmp(argv[i+1],"normal")){xcrypt_file(in_file, out_file, DECRYPT);} |
||
285 | if(!strcmp(argv[i+1],"speed")){xcrypt_file_speed(in_file, out_file, DECRYPT);} |
||
286 | } |
||
287 | } |
||
288 | printf(INVALID_ARG); |
||
289 | exit(0); |
||
290 | } |
||
291 | |||
292 | |||
293 | { |
||
294 | FILE *keyfile; |
||
295 | if((keyfile = fopen(strcat(keyfilename, ".key"), "wb"))==NULL) |
||
296 | { |
||
297 | printf(INCORRECT_FILE, keyfilename); |
||
298 | exit(-1); |
||
299 | } |
||
300 | fwrite(key,sizeof(uint8_t), 16, keyfile); |
||
301 | printf(KEY_RECORD_IN_FILE, keyfilename); |
||
302 | fclose(keyfile); |
||
303 | exit(0); |
||
304 | |||
305 | |||
306 | |||
307 | |||
308 | |||
309 | { |
||
310 | con_init_console_dll(); |
||
311 | con_set_title("TEAtool\0"); |
||
312 | if(argc==7) |
||
313 | { |
||
314 | findopt(argc,argv, argv[1],argv[2]); |
||
315 | } |
||
316 | else if(argc==2 && !strcmp(argv[1],"-a")) |
||
317 | { |
||
318 | show_about(); |
||
319 | exit(0); |
||
320 | } |
||
321 | |||
322 | |||
323 | { |
||
324 | show_help(); |
||
325 | exit(0); |
||
326 | } |
||
327 | |||
328 | |||
329 | { |
||
330 | key_con_read(argv[2]); |
||
331 | key_write_in_file(argv[3]); |
||
332 | } |
||
333 | |||
334 | |||
335 | |||
336 | { |
||
337 | printf(INVALID_ARG); |
||
338 | exit(0); |
||
339 | } |
||
340 | |||
341 | |||
342 | |||
343 | |||
344 | >4;>0) |
||
345 |