2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2005 W. Michael Petullo <mike@flyn.org>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
31 #include "libvolume_id.h"
32 #include "libvolume_id-private.h"
34 #define SECTOR_SHIFT 9
35 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
37 #define LUKS_CIPHERNAME_L 32
38 #define LUKS_CIPHERMODE_L 32
39 #define LUKS_HASHSPEC_L 32
40 #define LUKS_DIGESTSIZE 20
41 #define LUKS_SALTSIZE 32
42 #define LUKS_NUMKEYS 8
44 #define LUKS_MAGIC_L 6
45 #define LUKS_PHDR_SIZE (sizeof(struct luks_phdr)/SECTOR_SIZE+1)
46 #define UUID_STRING_L 40
47 static const uint8_t LUKS_MAGIC[] = {'L','U','K','S', 0xba, 0xbe};
50 uint8_t magic[LUKS_MAGIC_L];
52 uint8_t cipherName[LUKS_CIPHERNAME_L];
53 uint8_t cipherMode[LUKS_CIPHERMODE_L];
54 uint8_t hashSpec[LUKS_HASHSPEC_L];
55 uint32_t payloadOffset;
57 uint8_t mkDigest[LUKS_DIGESTSIZE];
58 uint8_t mkDigestSalt[LUKS_SALTSIZE];
59 uint32_t mkDigestIterations;
60 uint8_t uuid[UUID_STRING_L];
63 uint32_t passwordIterations;
64 uint8_t passwordSalt[LUKS_SALTSIZE];
65 uint32_t keyMaterialOffset;
67 } keyblock[LUKS_NUMKEYS];
70 int volume_id_probe_luks(struct volume_id *id, uint64_t off, uint64_t size)
72 struct luks_phdr *header;
74 header = (struct luks_phdr*) volume_id_get_buffer(id, off, LUKS_PHDR_SIZE);
78 if (memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L))
81 volume_id_set_usage(id, VOLUME_ID_CRYPTO);
82 volume_id_set_uuid(id, header->uuid, 36, UUID_HEX_STRING);
83 snprintf(id->type_version, sizeof(header->version), "%u", le16_to_cpu(header->version));
84 id->type = "crypto_LUKS";