2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2005 W. Michael Petullo <mike@flyn.org>
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.
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.
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
29 #include <netinet/in.h>
36 #include <asm/types.h>
38 #include "volume_id.h"
43 /* from cryptsetup-luks internal.h */
44 #define SECTOR_SHIFT 9
45 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
47 /* from cryptsetup-luks luks.h */
48 #define LUKS_CIPHERNAME_L 32
49 #define LUKS_CIPHERMODE_L 32
50 #define LUKS_HASHSPEC_L 32
51 #define LUKS_DIGESTSIZE 20 /* since SHA1 */
52 #define LUKS_SALTSIZE 32
53 #define LUKS_NUMKEYS 8
55 /* from cryptsetup-luks luks.h */
56 const unsigned char LUKS_MAGIC[] = {'L','U','K','S', 0xba, 0xbe};
57 #define LUKS_MAGIC_L 6
59 /* from cryptsetup-luks luks.h */
60 #define LUKS_PHDR_SIZE (sizeof(struct luks_phdr)/SECTOR_SIZE+1)
62 /* from cryptsetup-luks luks.h */
63 #define UUID_STRING_L 40
65 int volume_id_probe_luks(struct volume_id *id, __u64 off)
67 /* from cryptsetup-luks luks.h */
69 char magic[LUKS_MAGIC_L];
71 char cipherName[LUKS_CIPHERNAME_L];
72 char cipherMode[LUKS_CIPHERMODE_L];
73 char hashSpec[LUKS_HASHSPEC_L];
74 uint32_t payloadOffset;
76 char mkDigest[LUKS_DIGESTSIZE];
77 char mkDigestSalt[LUKS_SALTSIZE];
78 uint32_t mkDigestIterations;
79 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];
93 header = (struct luks_phdr*) volume_id_get_buffer(id, off, LUKS_PHDR_SIZE);
98 if (memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L))
101 volume_id_set_usage(id, VOLUME_ID_CRYPTO);
102 volume_id_set_uuid(id, header->uuid, UUID_DCE);
103 id->type = "crypto_LUKS";