Add basic TCRYPT library.
[platform/upstream/cryptsetup.git] / lib / tcrypt / tcrypt.h
1 /*
2  * TCRYPT - 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 65536
34
35 #define TCRYPT_LRW_IKEY_LEN 16
36
37 #define TCRYPT_HDR_FLAG_SYSTEM    (1 << 0)
38 #define TCRYPT_HDR_FLAG_NONSYSTEM (1 << 1)
39
40 struct tcrypt_phdr {
41         char salt[TCRYPT_HDR_SALT_LEN];
42
43         /* encrypted part, TCRYPT_HDR_LEN bytes */
44         union {
45         struct __attribute__((__packed__)) {
46                 char     magic[TCRYPT_HDR_MAGIC_LEN];
47                 uint16_t version;
48                 uint16_t version_tc;
49                 uint32_t keys_crc32;
50                 uint64_t _reserved1[2]; /* data/header ctime */
51                 uint64_t hidden_volume_size;
52                 uint64_t volume_size;
53                 uint64_t mk_offset;
54                 uint64_t mk_size;
55                 uint32_t flags;
56                 uint32_t sector_size;
57                 uint8_t  _reserved2[120];
58                 uint32_t header_crc32;
59                 char     keys[256];
60         } d;
61         char e[TCRYPT_HDR_LEN];
62         };
63 } __attribute__((__packed__));
64
65 int TCRYPT_read_phdr(struct crypt_device *cd,
66                      struct tcrypt_phdr *hdr,
67                      struct crypt_params_tcrypt *params,
68                      const char *passphrase,
69                      size_t passphrase_size,
70                      uint32_t flags);
71
72 int TCRYPT_activate(struct crypt_device *cd,
73                      const char *name,
74                      struct tcrypt_phdr *hdr,
75                      struct crypt_params_tcrypt *params,
76                      uint32_t flags);
77
78 #endif