2 * LUKS - Linux Unified Key Setup
4 * Copyright (C) 2004-2006, Clemens Fruhwirth <clemens@endorphin.org>
5 * Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
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.
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.
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.
21 #ifndef INCLUDED_CRYPTSETUP_LUKS_LUKS_H
22 #define INCLUDED_CRYPTSETUP_LUKS_LUKS_H
25 * LUKS partition header
28 #include "libcryptsetup.h"
30 #define LUKS_CIPHERNAME_L 32
31 #define LUKS_CIPHERMODE_L 32
32 #define LUKS_HASHSPEC_L 32
33 #define LUKS_DIGESTSIZE 20 // since SHA1
34 #define LUKS_HMACSIZE 32
35 #define LUKS_SALTSIZE 32
36 #define LUKS_NUMKEYS 8
38 // Minimal number of iterations
39 #define LUKS_MKD_ITERATIONS_MIN 1000
40 #define LUKS_SLOT_ITERATIONS_MIN 1000
42 #define LUKS_KEY_DISABLED_OLD 0
43 #define LUKS_KEY_ENABLED_OLD 0xCAFE
45 #define LUKS_KEY_DISABLED 0x0000DEAD
46 #define LUKS_KEY_ENABLED 0x00AC71F3
48 #define LUKS_STRIPES 4000
50 // partition header starts with magic
51 #define LUKS_MAGIC {'L','U','K','S', 0xba, 0xbe};
52 #define LUKS_MAGIC_L 6
54 #define LUKS_PHDR_SIZE (sizeof(struct luks_phdr)/SECTOR_SIZE+1)
56 /* Actually we need only 37, but we don't want struct autoaligning to kick in */
57 #define UUID_STRING_L 40
59 /* Offset to keyslot area [in bytes] */
60 #define LUKS_ALIGN_KEYSLOTS 4096
62 /* Any integer values are stored in network byte order on disk and must be
68 char magic[LUKS_MAGIC_L];
70 char cipherName[LUKS_CIPHERNAME_L];
71 char cipherMode[LUKS_CIPHERMODE_L];
72 char hashSpec[LUKS_HASHSPEC_L];
73 uint32_t payloadOffset;
75 char mkDigest[LUKS_DIGESTSIZE];
76 char mkDigestSalt[LUKS_SALTSIZE];
77 uint32_t mkDigestIterations;
78 char uuid[UUID_STRING_L];
83 /* parameters used for password processing */
84 uint32_t passwordIterations;
85 char passwordSalt[LUKS_SALTSIZE];
87 /* parameters used for AF store/load */
88 uint32_t keyMaterialOffset;
90 } keyblock[LUKS_NUMKEYS];
92 /* Align it to 512 sector size */
96 int LUKS_verify_volume_key(const struct luks_phdr *hdr,
97 const struct volume_key *vk);
99 int LUKS_generate_phdr(
100 struct luks_phdr *header,
101 const struct volume_key *vk,
102 const char *cipherName,
103 const char *cipherMode,
104 const char *hashSpec,
106 unsigned int stripes,
107 unsigned int alignPayload,
108 unsigned int alignOffset,
109 uint32_t iteration_time_ms,
110 uint64_t *PBKDF2_per_sec,
111 const char *metadata_device,
112 struct crypt_device *ctx);
116 struct luks_phdr *hdr,
117 int require_luks_device,
119 struct crypt_device *ctx);
121 int LUKS_read_phdr_backup(
122 const char *backup_file,
124 struct luks_phdr *hdr,
125 int require_luks_device,
126 struct crypt_device *ctx);
128 int LUKS_hdr_uuid_set(
130 struct luks_phdr *hdr,
132 struct crypt_device *ctx);
135 const char *backup_file,
137 struct luks_phdr *hdr,
138 struct crypt_device *ctx);
140 int LUKS_hdr_restore(
141 const char *backup_file,
143 struct luks_phdr *hdr,
144 struct crypt_device *ctx);
148 struct luks_phdr *hdr,
149 struct crypt_device *ctx);
153 unsigned int keyIndex,
154 const char *password,
156 struct luks_phdr *hdr,
157 struct volume_key *vk,
158 uint32_t iteration_time_ms,
159 uint64_t *PBKDF2_per_sec,
160 struct crypt_device *ctx);
162 int LUKS_open_key_with_hdr(
165 const char *password,
167 struct luks_phdr *hdr,
168 struct volume_key **vk,
169 struct crypt_device *ctx);
173 unsigned int keyIndex,
174 struct luks_phdr *hdr,
175 struct crypt_device *ctx);
177 crypt_keyslot_info LUKS_keyslot_info(struct luks_phdr *hdr, int keyslot);
178 int LUKS_keyslot_find_empty(struct luks_phdr *hdr);
179 int LUKS_keyslot_active_count(struct luks_phdr *hdr);
180 int LUKS_keyslot_set(struct luks_phdr *hdr, int keyslot, int enable);
182 int LUKS_encrypt_to_storage(
183 char *src, size_t srcLength,
184 struct luks_phdr *hdr,
185 struct volume_key *vk,
188 struct crypt_device *ctx);
190 int LUKS_decrypt_from_storage(
191 char *dst, size_t dstLength,
192 struct luks_phdr *hdr,
193 struct volume_key *vk,
196 struct crypt_device *ctx);
198 int LUKS1_activate(struct crypt_device *cd,
200 struct volume_key *vk,