Add basic support for system TCRYPT device.
[platform/upstream/cryptsetup.git] / lib / tcrypt / tcrypt.h
1 /*
2  * TCRYPT (TrueCrypt-compatible)  header defitinion
3  *
4  * Copyright (C) 2012, Red Hat, Inc. All rights reserved.
5  * Copyright (C) 2012, Milan Broz
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #include "libcryptsetup.h"
22
23 #ifndef _CRYPTSETUP_TCRYPT_H
24 #define _CRYPTSETUP_TCRYPT_H
25
26 #define TCRYPT_HDR_SALT_LEN 64
27 #define TCRYPT_HDR_IV_LEN   16
28 #define TCRYPT_HDR_LEN     448
29 #define TCRYPT_HDR_KEY_LEN 192
30 #define TCRYPT_HDR_MAGIC "TRUE"
31 #define TCRYPT_HDR_MAGIC_LEN 4
32
33 #define TCRYPT_HDR_HIDDEN_OFFSET_OLD -1536
34 #define TCRYPT_HDR_HIDDEN_OFFSET 65536
35
36 #define TCRYPT_HDR_HIDDEN_OFFSET_BCK -65536
37 #define TCRYPT_HDR_OFFSET_BCK -131072
38
39 #define TCRYPT_HDR_SYSTEM_OFFSET 31744
40
41 #define TCRYPT_LRW_IKEY_LEN 16
42 #define TCRYPT_KEY_POOL_LEN 64
43 #define TCRYPT_KEYFILE_LEN  1048576
44
45 #define TCRYPT_HDR_FLAG_SYSTEM    (1 << 0)
46 #define TCRYPT_HDR_FLAG_NONSYSTEM (1 << 1)
47
48 struct tcrypt_phdr {
49         char salt[TCRYPT_HDR_SALT_LEN];
50
51         /* encrypted part, TCRYPT_HDR_LEN bytes */
52         union {
53         struct __attribute__((__packed__)) {
54                 char     magic[TCRYPT_HDR_MAGIC_LEN];
55                 uint16_t version;
56                 uint16_t version_tc;
57                 uint32_t keys_crc32;
58                 uint64_t _reserved1[2]; /* data/header ctime */
59                 uint64_t hidden_volume_size;
60                 uint64_t volume_size;
61                 uint64_t mk_offset;
62                 uint64_t mk_size;
63                 uint32_t flags;
64                 uint32_t sector_size;
65                 uint8_t  _reserved2[120];
66                 uint32_t header_crc32;
67                 char     keys[256];
68         } d;
69         char e[TCRYPT_HDR_LEN];
70         };
71 } __attribute__((__packed__));
72
73 struct crypt_dm_active_device;
74 struct volume_key;
75 struct device;
76
77 int TCRYPT_read_phdr(struct crypt_device *cd,
78                      struct tcrypt_phdr *hdr,
79                      struct crypt_params_tcrypt *params);
80
81 int TCRYPT_init_by_name(struct crypt_device *cd, const char *name,
82                         const struct crypt_dm_active_device *dmd,
83                         struct device **device,
84                         struct crypt_params_tcrypt *tcrypt_params,
85                         struct tcrypt_phdr *tcrypt_hdr);
86
87 int TCRYPT_activate(struct crypt_device *cd,
88                      const char *name,
89                      struct tcrypt_phdr *hdr,
90                      struct crypt_params_tcrypt *params,
91                      uint32_t flags);
92
93 int TCRYPT_deactivate(struct crypt_device *cd,
94                       const char *name);
95
96 uint64_t TCRYPT_get_data_offset(struct crypt_device *cd,
97                                 struct tcrypt_phdr *hdr,
98                                 struct crypt_params_tcrypt *params);
99
100 uint64_t TCRYPT_get_iv_offset(struct crypt_device *cd,
101                               struct tcrypt_phdr *hdr,
102                               struct crypt_params_tcrypt *params);
103
104 int TCRYPT_get_volume_key(struct crypt_device *cd,
105                           struct tcrypt_phdr *hdr,
106                           struct crypt_params_tcrypt *params,
107                           struct volume_key **vk);
108
109 int TCRYPT_dump(struct crypt_device *cd,
110                 struct tcrypt_phdr *hdr,
111                 struct crypt_params_tcrypt *params);
112
113 #endif