blob: 42bf87659ae5d126b1269dfa7d784899bcf4fc65 [file] [log] [blame]
Denis Vlasenkode7684a2008-02-18 21:08:49 +00001/*
2 * volume_id - reads filesystem label and uuid
3 *
4 * Copyright (C) 2005 W. Michael Petullo <mike@flyn.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library 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 GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
Sven-Göran Bergh3b458012013-07-31 15:45:20 +020021//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_LUKS) += luks.o
22
Sven-Göran Bergh15d0a862013-07-31 15:57:59 +020023//config:
24//config:config FEATURE_VOLUMEID_LUKS
25//config: bool "luks filesystem"
26//config: default y
27//config: depends on VOLUMEID
28//config: help
29//config: TODO
30//config:
31
Denis Vlasenkode7684a2008-02-18 21:08:49 +000032#include "volume_id_internal.h"
33
Denis Vlasenkod5e30592008-10-12 11:17:49 +000034#define LUKS_MAGIC_L 6
35#define UUID_STRING_L 40
36#define LUKS_CIPHERNAME_L 32
37#define LUKS_CIPHERMODE_L 32
38#define LUKS_HASHSPEC_L 32
39#define LUKS_DIGESTSIZE 20
40#define LUKS_SALTSIZE 32
41#define LUKS_NUMKEYS 8
Denis Vlasenkode7684a2008-02-18 21:08:49 +000042
43static const uint8_t LUKS_MAGIC[] = { 'L','U','K','S', 0xba, 0xbe };
Denis Vlasenkode7684a2008-02-18 21:08:49 +000044
45struct luks_phdr {
46 uint8_t magic[LUKS_MAGIC_L];
47 uint16_t version;
48 uint8_t cipherName[LUKS_CIPHERNAME_L];
49 uint8_t cipherMode[LUKS_CIPHERMODE_L];
50 uint8_t hashSpec[LUKS_HASHSPEC_L];
51 uint32_t payloadOffset;
52 uint32_t keyBytes;
53 uint8_t mkDigest[LUKS_DIGESTSIZE];
54 uint8_t mkDigestSalt[LUKS_SALTSIZE];
55 uint32_t mkDigestIterations;
56 uint8_t uuid[UUID_STRING_L];
57 struct {
58 uint32_t active;
59 uint32_t passwordIterations;
60 uint8_t passwordSalt[LUKS_SALTSIZE];
61 uint32_t keyMaterialOffset;
62 uint32_t stripes;
63 } keyblock[LUKS_NUMKEYS];
64};
65
Denis Vlasenkod5e30592008-10-12 11:17:49 +000066enum {
67 EXPECTED_SIZE_luks_phdr = 0
68 + 1 * LUKS_MAGIC_L
69 + 2
70 + 1 * LUKS_CIPHERNAME_L
71 + 1 * LUKS_CIPHERMODE_L
72 + 1 * LUKS_HASHSPEC_L
73 + 4
74 + 4
75 + 1 * LUKS_DIGESTSIZE
76 + 1 * LUKS_SALTSIZE
77 + 4
78 + 1 * UUID_STRING_L
79 + LUKS_NUMKEYS * (0
80 + 4
81 + 4
82 + 1 * LUKS_SALTSIZE
83 + 4
84 + 4
85 )
86};
87
88struct BUG_bad_size_luks_phdr {
89 char BUG_bad_size_luks_phdr[
90 sizeof(struct luks_phdr) == EXPECTED_SIZE_luks_phdr ?
91 1 : -1];
92};
93
Denys Vlasenko89300962009-11-01 23:07:18 +010094int FAST_FUNC volume_id_probe_luks(struct volume_id *id /*,uint64_t off*/)
Denis Vlasenkode7684a2008-02-18 21:08:49 +000095{
Denis Vlasenko28ea4292009-02-15 05:51:19 +000096#define off ((uint64_t)0)
Denis Vlasenkode7684a2008-02-18 21:08:49 +000097 struct luks_phdr *header;
98
Denis Vlasenkod5e30592008-10-12 11:17:49 +000099 header = volume_id_get_buffer(id, off, sizeof(*header));
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000100 if (header == NULL)
101 return -1;
102
103 if (memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L))
104 return -1;
105
Denis Vlasenkoc5b73722008-03-17 09:21:26 +0000106// volume_id_set_usage(id, VOLUME_ID_CRYPTO);
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000107 volume_id_set_uuid(id, header->uuid, UUID_DCE_STRING);
Denys Vlasenko90615a02010-12-30 00:40:11 +0100108 IF_FEATURE_BLKID_TYPE(id->type = "crypto_LUKS";)
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000109
110 return 0;
111}