Skip to content
Newer
Older
100644 217 lines (187 sloc) 7.68 KB
fff7218 @bwalex Initial commit of current state
authored May 13, 2011
1 /*
dedd95c @bwalex major refactoring, bugfixes
authored May 17, 2011
2 * Copyright (c) 2011 Alex Hornung <alex@alexhornung.com>.
3 * All rights reserved.
fff7218 @bwalex Initial commit of current state
authored May 13, 2011
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
adacd75 @bwalex shuffle things around, cleanup
authored Jul 3, 2011
29
1af29c1 @bwalex rename tc-play => tcplay
authored Jul 3, 2011
30 /* Version of tcplay */
adacd75 @bwalex shuffle things around, cleanup
authored Jul 3, 2011
31 #define MAJ_VER 0
32 #define MIN_VER 8
33
34
fa29c84 @bwalex refactoring in preparation for hidden vol support
authored May 13, 2011
35 #define MAX_BLKSZ 4096
2dc9cd0 @bwalex WIP! - support for creating TC volumes
authored May 16, 2011
36 #define MAX_KEYSZ 192
fa29c84 @bwalex refactoring in preparation for hidden vol support
authored May 13, 2011
37 #define HDRSZ 512
38 #define HDR_OFFSET_SYS 31744 /* 512 * (63 -1) */
39 #define TC_SIG "TRUE"
40 #define MAX_PASSSZ 64
41 #define KPOOL_SZ 64
42 #define MAX_KFILE_SZ 1048576 /* 1 MB */
43 #define MAX_KEYFILES 256
44 #define HDR_OFFSET_HIDDEN 65536
2dc9cd0 @bwalex WIP! - support for creating TC volumes
authored May 16, 2011
45 #define SALT_LEN 64
46 #define MIN_VOL_BLOCKS 256
6ee09f3 @bwalex half-baked cascaded cipher support
authored Jul 2, 2011
47 #define MAX_CIPHER_CHAINS 64
94d9e91 @bwalex major refactoring (move out info & map)
authored Jul 3, 2011
48 #define DEFAULT_RETRIES 3
69686eb @bwalex improve secure_erase speed; add SIGINFO support
authored Jul 3, 2011
49 #define ERASE_BUFFER_SIZE 4*1024*1024 /* 4 MB */
fa29c84 @bwalex refactoring in preparation for hidden vol support
authored May 13, 2011
50
51 /* TrueCrypt Volume flags */
52 #define TC_VOLFLAG_SYSTEM 0x01 /* system encryption */
53 #define TC_VOLFLAG_INPLACE 0x02 /* non-system in-place-encrypted volume */
54
05bf0a1 @bwalex Start C API work
authored Jul 3, 2011
55 #define LOG_BUFFER_SZ 1024
b66934b @bwalex restore default of debug off
authored Jul 2, 2011
56 #if 0
a250434 @bwalex almost-baked cascaded cipher support
authored Jul 2, 2011
57 #define DEBUG 1
58 #endif
6ee09f3 @bwalex half-baked cascaded cipher support
authored Jul 2, 2011
59
34165ed @bwalex first step to porting to linux; can be broken :)
authored Jul 20, 2011
60 #include <inttypes.h>
61
62 #if defined(__DragonFly__)
dedd95c @bwalex major refactoring, bugfixes
authored May 17, 2011
63 #include <uuid.h>
34165ed @bwalex first step to porting to linux; can be broken :)
authored Jul 20, 2011
64 #elif defined(__linux__)
65 #include <uuid/uuid.h>
66 #endif
fff7218 @bwalex Initial commit of current state
authored May 13, 2011
67
68 struct pbkdf_prf_algo {
0c6d6a0 @bwalex big warning cleanup
authored Jul 3, 2011
69 const char *name;
fff7218 @bwalex Initial commit of current state
authored May 13, 2011
70 int iteration_count;
71 };
72
73 struct tc_crypto_algo {
0c6d6a0 @bwalex big warning cleanup
authored Jul 3, 2011
74 const char *name;
75 const char *dm_crypt_str;
fff7218 @bwalex Initial commit of current state
authored May 13, 2011
76 int klen;
77 int ivlen;
78 };
79
6ee09f3 @bwalex half-baked cascaded cipher support
authored Jul 2, 2011
80 struct tc_cipher_chain {
81 struct tc_crypto_algo *cipher;
82 unsigned char *key;
a250434 @bwalex almost-baked cascaded cipher support
authored Jul 2, 2011
83 char dm_key[MAX_KEYSZ*2 + 1];
6ee09f3 @bwalex half-baked cascaded cipher support
authored Jul 2, 2011
84
85 struct tc_cipher_chain *prev;
86 struct tc_cipher_chain *next;
87 };
88
fff7218 @bwalex Initial commit of current state
authored May 13, 2011
89 struct tchdr_enc {
2dc9cd0 @bwalex WIP! - support for creating TC volumes
authored May 16, 2011
90 unsigned char salt[SALT_LEN]; /* Salt for PBKDF */
fff7218 @bwalex Initial commit of current state
authored May 13, 2011
91 unsigned char enc[448]; /* Encrypted part of the header */
92 } __attribute__((__packed__));
93
94 struct tchdr_dec {
95 char tc_str[4]; /* ASCII string "TRUE" */
96 uint16_t tc_ver; /* Volume header format version */
97 uint16_t tc_min_ver;
98 uint32_t crc_keys; /* CRC32 of the key section */
99 uint64_t vol_ctime; /* Volume creation time */
100 uint64_t hdr_ctime; /* Header creation time */
101 uint64_t sz_hidvol; /* Size of hidden volume (set to zero
102 in non-hidden volumes) */
103 uint64_t sz_vol; /* Size of volume */
104 uint64_t off_mk_scope; /* Byte offset of the start of the
105 master key scope */
106 uint64_t sz_mk_scope; /* Size of the encrypted area within
107 the master key scope */
108 uint32_t flags; /* Flag bits
109 (bit 0: system encryption;
110 bit 1: non-system in-place-encrypted volume;
111 bits 2–31 are reserved) */
112 uint32_t sec_sz; /* Sector size (in bytes) */
113 unsigned char unused3[120];
114 uint32_t crc_dhdr; /* CRC32 of dec. header (except keys) */
115 unsigned char keys[256];
116 } __attribute__((__packed__));
117
118 struct tcplay_info {
119 const char *dev;
120 struct tchdr_dec *hdr;
6ee09f3 @bwalex half-baked cascaded cipher support
authored Jul 2, 2011
121 struct tc_cipher_chain *cipher_chain;
fff7218 @bwalex Initial commit of current state
authored May 13, 2011
122 struct pbkdf_prf_algo *pbkdf_prf;
a250434 @bwalex almost-baked cascaded cipher support
authored Jul 2, 2011
123 char key[MAX_KEYSZ*2 + 1];
fff7218 @bwalex Initial commit of current state
authored May 13, 2011
124 off_t start; /* Logical volume offset in table */
125 size_t size; /* Volume size */
126
127 off_t skip; /* IV offset */
128 off_t offset; /* Block offset */
129
130 /* Populated by dm_setup */
131 uuid_t uuid;
132 };
133
dedd95c @bwalex major refactoring, bugfixes
authored May 17, 2011
134 void *read_to_safe_mem(const char *file, off_t offset, size_t *sz);
135 int get_random(unsigned char *buf, size_t len);
136 int secure_erase(const char *dev, size_t bytes, size_t blksz);
137 int get_disk_info(const char *dev, size_t *blocks, size_t *bsize);
138 int write_mem(const char *dev, off_t offset, size_t blksz, void *mem, size_t bytes);
46f7fdb @bwalex add prompt timeout support
authored Jul 11, 2011
139 int read_passphrase(const char *prompt, char *pass, size_t passlen,
140 time_t timeout);
fff7218 @bwalex Initial commit of current state
authored May 13, 2011
141
dedd95c @bwalex major refactoring, bugfixes
authored May 17, 2011
142 int tc_crypto_init(void);
a250434 @bwalex almost-baked cascaded cipher support
authored Jul 2, 2011
143 int tc_cipher_chain_populate_keys(struct tc_cipher_chain *cipher_chain,
144 unsigned char *key);
6ee09f3 @bwalex half-baked cascaded cipher support
authored Jul 2, 2011
145 int tc_encrypt(struct tc_cipher_chain *cipher_chain, unsigned char *key,
31d65e4 @bwalex Improve support for different cipher methods
authored Jul 2, 2011
146 unsigned char *iv,
dedd95c @bwalex major refactoring, bugfixes
authored May 17, 2011
147 unsigned char *in, int in_len, unsigned char *out);
6ee09f3 @bwalex half-baked cascaded cipher support
authored Jul 2, 2011
148 int tc_decrypt(struct tc_cipher_chain *cipher_chain, unsigned char *key,
31d65e4 @bwalex Improve support for different cipher methods
authored Jul 2, 2011
149 unsigned char *iv,
dedd95c @bwalex major refactoring, bugfixes
authored May 17, 2011
150 unsigned char *in, int in_len, unsigned char *out);
65808bd @bwalex separate out bits; implement gcrypt backend
authored Jul 20, 2011
151
152 /* The following two are platform dependent */
153 int syscrypt(struct tc_crypto_algo *cipher, unsigned char *key, size_t klen,
154 unsigned char *iv, unsigned char *in, unsigned char *out, size_t len,
155 int do_encrypt);
156 int pbkdf2(struct pbkdf_prf_algo *hash, const char *pass, int passlen,
157 const unsigned char *salt, int saltlen,
158 int keylen, unsigned char *out);
159
dedd95c @bwalex major refactoring, bugfixes
authored May 17, 2011
160 int apply_keyfiles(unsigned char *pass, size_t pass_memsz, const char *keyfiles[],
161 int nkeyfiles);
162
163 struct tchdr_enc *create_hdr(unsigned char *pass, int passlen,
6ee09f3 @bwalex half-baked cascaded cipher support
authored Jul 2, 2011
164 struct pbkdf_prf_algo *prf_algo, struct tc_cipher_chain *cipher_chain,
dedd95c @bwalex major refactoring, bugfixes
authored May 17, 2011
165 size_t sec_sz, size_t total_blocks,
166 off_t offset, size_t blocks, int hidden);
6ee09f3 @bwalex half-baked cascaded cipher support
authored Jul 2, 2011
167 struct tchdr_dec *decrypt_hdr(struct tchdr_enc *ehdr,
168 struct tc_cipher_chain *cipher_chain, unsigned char *key);
dedd95c @bwalex major refactoring, bugfixes
authored May 17, 2011
169 int verify_hdr(struct tchdr_dec *hdr);
170
171 void *_alloc_safe_mem(size_t req_sz, const char *file, int line);
172 void _free_safe_mem(void *mem, const char *file, int line);
173 void check_and_purge_safe_mem(void);
174
0c6d6a0 @bwalex big warning cleanup
authored Jul 3, 2011
175 struct tc_crypto_algo *check_cipher(const char *cipher, int quiet);
05bf0a1 @bwalex Start C API work
authored Jul 3, 2011
176 struct tc_cipher_chain *check_cipher_chain(char *cipher_chain, int quiet);
177 struct pbkdf_prf_algo *check_prf_algo(char *algo, int quiet);
adacd75 @bwalex shuffle things around, cleanup
authored Jul 3, 2011
178
2e3a80c @bwalex several minor fixes/cleanups
authored Jul 8, 2011
179 int tc_play_init(void);
0c6d6a0 @bwalex big warning cleanup
authored Jul 3, 2011
180 void tc_log(int err, const char *fmt, ...);
adacd75 @bwalex shuffle things around, cleanup
authored Jul 3, 2011
181 void print_info(struct tcplay_info *info);
182 int adjust_info(struct tcplay_info *info, struct tcplay_info *hinfo);
183 int process_hdr(const char *dev, unsigned char *pass, int passlen,
184 struct tchdr_enc *ehdr, struct tcplay_info **pinfo);
185 int create_volume(const char *dev, int hidden, const char *keyfiles[],
186 int nkeyfiles, const char *h_keyfiles[], int n_hkeyfiles,
05bf0a1 @bwalex Start C API work
authored Jul 3, 2011
187 struct pbkdf_prf_algo *prf_algo, struct tc_cipher_chain *cipher_chain,
c4608da @bwalex bugfix, support for different cipher for hidden vol
authored Jul 10, 2011
188 struct pbkdf_prf_algo *h_prf_algo, struct tc_cipher_chain *h_cipher_chain,
05bf0a1 @bwalex Start C API work
authored Jul 3, 2011
189 char *passphrase, char *h_passphrase, size_t hidden_blocks_in,
190 int interactive);
94d9e91 @bwalex major refactoring (move out info & map)
authored Jul 3, 2011
191 int info_volume(const char *device, int sflag, const char *sys_dev,
192 int protect_hidden, const char *keyfiles[], int nkeyfiles,
193 const char *h_keyfiles[], int n_hkeyfiles,
46f7fdb @bwalex add prompt timeout support
authored Jul 11, 2011
194 char *passphrase, char *passphrase_hidden, int interactive, int retries,
195 time_t timeout);
94d9e91 @bwalex major refactoring (move out info & map)
authored Jul 3, 2011
196 int map_volume(const char *map_name, const char *device, int sflag,
197 const char *sys_dev, int protect_hidden, const char *keyfiles[],
198 int nkeyfiles, const char *h_keyfiles[], int n_hkeyfiles,
46f7fdb @bwalex add prompt timeout support
authored Jul 11, 2011
199 char *passphrase, char *passphrase_hidden, int interactive, int retries,
200 time_t timeout);
adacd75 @bwalex shuffle things around, cleanup
authored Jul 3, 2011
201 int dm_setup(const char *mapname, struct tcplay_info *info);
1c225df @bwalex proper support for unmapping
authored Jul 12, 2011
202 int dm_teardown(const char *mapname, const char *device);
adacd75 @bwalex shuffle things around, cleanup
authored Jul 3, 2011
203
69686eb @bwalex improve secure_erase speed; add SIGINFO support
authored Jul 3, 2011
204 typedef void(*summary_fn_t)(void);
205
05bf0a1 @bwalex Start C API work
authored Jul 3, 2011
206 extern int tc_internal_verbose;
207 extern char tc_internal_log_buffer[];
69686eb @bwalex improve secure_erase speed; add SIGINFO support
authored Jul 3, 2011
208 extern summary_fn_t summary_fn;
05bf0a1 @bwalex Start C API work
authored Jul 3, 2011
209
dedd95c @bwalex major refactoring, bugfixes
authored May 17, 2011
210 #define alloc_safe_mem(x) \
211 _alloc_safe_mem(x, __FILE__, __LINE__)
212
213 #define free_safe_mem(x) \
214 _free_safe_mem(x, __FILE__, __LINE__)
34165ed @bwalex first step to porting to linux; can be broken :)
authored Jul 20, 2011
215
216 #define __unused __attribute__((__unused__))
Something went wrong with that request. Please try again.