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 it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
26 #include "libvolume_id.h"
29 #define SECTOR_SHIFT 9
30 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
32 #define LUKS_CIPHERNAME_L 32
33 #define LUKS_CIPHERMODE_L 32
34 #define LUKS_HASHSPEC_L 32
35 #define LUKS_DIGESTSIZE 20
36 #define LUKS_SALTSIZE 32
37 #define LUKS_NUMKEYS 8
39 #define LUKS_MAGIC_L 6
40 #define LUKS_PHDR_SIZE (sizeof(struct luks_phdr)/SECTOR_SIZE+1)
41 #define UUID_STRING_L 40
42 static const uint8_t LUKS_MAGIC[] = {'L','U','K','S', 0xba, 0xbe};
45 uint8_t magic[LUKS_MAGIC_L];
47 uint8_t cipherName[LUKS_CIPHERNAME_L];
48 uint8_t cipherMode[LUKS_CIPHERMODE_L];
49 uint8_t hashSpec[LUKS_HASHSPEC_L];
50 uint32_t payloadOffset;
52 uint8_t mkDigest[LUKS_DIGESTSIZE];
53 uint8_t mkDigestSalt[LUKS_SALTSIZE];
54 uint32_t mkDigestIterations;
55 uint8_t uuid[UUID_STRING_L];
58 uint32_t passwordIterations;
59 uint8_t passwordSalt[LUKS_SALTSIZE];
60 uint32_t keyMaterialOffset;
62 } keyblock[LUKS_NUMKEYS];
65 int volume_id_probe_luks(struct volume_id *id, uint64_t off, uint64_t size)
67 struct luks_phdr *header;
69 header = (struct luks_phdr*) volume_id_get_buffer(id, off, LUKS_PHDR_SIZE);
73 if (memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L))
76 volume_id_set_usage(id, VOLUME_ID_CRYPTO);
77 volume_id_set_uuid(id, header->uuid, 36, UUID_HEX_STRING);
78 snprintf(id->type_version, sizeof(header->version), "%u", le16_to_cpu(header->version));
79 id->type = "crypto_LUKS";