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"
30 #define SECTOR_SHIFT 9
31 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
33 #define LUKS_CIPHERNAME_L 32
34 #define LUKS_CIPHERMODE_L 32
35 #define LUKS_HASHSPEC_L 32
36 #define LUKS_DIGESTSIZE 20
37 #define LUKS_SALTSIZE 32
38 #define LUKS_NUMKEYS 8
40 const uint8_t LUKS_MAGIC[] = {'L','U','K','S', 0xba, 0xbe};
41 #define LUKS_MAGIC_L 6
42 #define LUKS_PHDR_SIZE (sizeof(struct luks_phdr)/SECTOR_SIZE+1)
43 #define UUID_STRING_L 40
46 uint8_t magic[LUKS_MAGIC_L];
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;
53 uint8_t mkDigest[LUKS_DIGESTSIZE];
54 uint8_t mkDigestSalt[LUKS_SALTSIZE];
55 uint32_t mkDigestIterations;
56 uint8_t uuid[UUID_STRING_L];
59 uint32_t passwordIterations;
60 uint8_t passwordSalt[LUKS_SALTSIZE];
61 uint32_t keyMaterialOffset;
63 } keyblock[LUKS_NUMKEYS];
66 int volume_id_probe_luks(struct volume_id *id, uint64_t off)
68 struct luks_phdr *header;
70 header = (struct luks_phdr*) volume_id_get_buffer(id, off, LUKS_PHDR_SIZE);
74 if (memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L))
77 volume_id_set_usage(id, VOLUME_ID_CRYPTO);
78 volume_id_set_uuid(id, header->uuid, UUID_DCE_STRING);
80 id->type = "crypto_LUKS";