Initial import of truecrypt cracking project.
[delutions.git] / tc / python / tc.c~
blobf2b995f9c1f083691242745eca0fdf4665bdfaac
1 #include <stdlib.h>
2 #include <stdio.h>
4 #include "pbkdf2.h"
5 #include "crypt.h"
6 // #include "hash_wrappers.h"
7 // #include "hmac.h"
9 #define VERSION 0.1
11 #define TC_HIDDEN_VOLUME_OFFSET 1536
12 #define TC_SALT_SZ 64
13 #define TC_HEADER_SZ 448
15 char * name;
17 void usage() {
18         fprintf(stderr,"trueCRACK v%f\m",version);
19         fprintf(stderr,"usage:\n\t%s tc_volume wordlist starting_word",name);
20         exit(EXIT_FAILURE);
23 // hmac functions
25 uint8_t * o_pad;
26 uint8_t * i_pad;
28 inline void xor_l2(uint8_t * b1, uint8_t * b2, uint8_t * b3, uint32_t len) {
29         for (uint32_t i = 0; i < len; i ++)
30                 b3[i] = (uint8_t) b1[i] ^ b2[i];
33 int hmac_init(hash_t * hash) {
34         o_pad = malloc(hash->block_sz);
35         if (o_pad==NULL)
36                 return -1;
37         i_pad = malloc(hash->block_sz);
38         if (i_pad==NULL)
39                 return -2;
40         memset(o_pad, 0x5c, hash->block_sz);
41         memset(i_pad, 0x36, hash->block_sz);
43         tmp_key = malloc(hash->block_sz);
44         if (tmp_key==NULL)
45                 return -3;
49 void hmac(hash_t * hash, uint8_t * key, uint32_t key_len, uint8_t * message, uint32_t message_len, uint8_t * out, uint32_t out_len) {
50 //      out = hash(K^opad ++ hash(K^ipad ++ message) 
53         if ( key_len > hash->block_sz ) {
54                 //key = hash->digest(key)
55                 hash->digest(key, key_len, NULL, 0, key, key_len); // this may cause issues....
56                 key_len = hash->digest_sz
57         }
59         xor_l2(key,opad,key_len);
60         memset(key+hash->digest,0x5c,key_len-
63 int main (int argc, char ** argv) {
64         name = argv[0];
65         if (argc<4)
66                 usage();
68         FILE * tc_volume_file = fopen(argv[1], "rb");
69         FILE * wordlist_file  = fopen(argv[2], "r" );
71         uint8_t salt            [TC_SALT_SZ+4]; 
72         uint8_t header          [TC_HEADER_SZ];
73         uint8_t header_hidden   [TC_HEADER_SZ];
75         size_t s = fread(tc_volume_file,1,TC_SALT_SZ,salt);
76         if (s < TC_SALT_SZ) {
77                 exit(EXIT_FAILURE);
78         }
80         s = fread(tc_volume_file,1,TC_HEADER_SZ,header);
81         if (s < TC_HEADER_SZ) {
82                 exit(EXIT_FAILURE);
83         }
85         fseek ( tc_volume_file , TC_HIDDEN_VOLUME_OFFSET , SEEK_SET );
86         s = fread(tc_volume_file,1,TC_HEADER_SZ,header_hidden);
87         if (s < TC_HEADER_SZ) {
88                 exit(EXIT_FAILURE);
89         }
90         
91         int ret = hmac_init();
92         if ( ret < 0 ) {
93                 exit(EXIT_FAILURE);
94         }
96         uint8_t password [TC_PASSWORD_MAX];
98         while ( !feof(wordlist_file) ) {
99                 //read line??
100                 read_line(wordlist_file, password);
101                 PBKDF2(hmac_???, password, sizeof(password), salt, sizeof(salt), iterations, derived_key, derived_key_len);
102         }
104         exit(EXIT_SUCCESS);