]> err.no Git - util-linux/commitdiff
blkid: add LUKS support
authorKarel Zak <kzak@redhat.com>
Wed, 5 Nov 2008 13:39:36 +0000 (14:39 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 11 Feb 2009 22:21:47 +0000 (23:21 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libs/blkid/src/probe.c
libs/blkid/src/probers/Makefile.am
libs/blkid/src/probers/luks.c [new file with mode: 0644]
libs/blkid/src/probers/probers.h

index 9f40d6425e4a5ab8a172d409f63d3acd5d4da057..118a355a74a7540f3ed211f35b441d6d09a5bfb0 100644 (file)
@@ -51,7 +51,7 @@ static const struct blkid_idinfo *idinfos[] =
        &jmraid_idinfo,
        &lvm2_idinfo,
        /* TODO: lvm1 */
-       /* TODO: LUKS */
+       &luks_idinfo,
 
        /* Filesystems */
        &vfat_idinfo,
index 8cccc806ba1ef210356378dffbc428e3ef94ea28..5bca88c4e21e6a9aa82daf4e244b1ae35f128e4b 100644 (file)
@@ -29,6 +29,7 @@ libprobers_a_SOURCES =        probers.h \
                        iso9660.c \
                        udf.c \
                        vfat.c \
+                       luks.c \
                        lvm.c
 
 all-local: $(lib_LIBRARIES)
diff --git a/libs/blkid/src/probers/luks.c b/libs/blkid/src/probers/luks.c
new file mode 100644 (file)
index 0000000..7ded56d
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <ctype.h>
+#include <stdint.h>
+
+#include "blkidP.h"
+
+#define LUKS_CIPHERNAME_L              32
+#define LUKS_CIPHERMODE_L              32
+#define LUKS_HASHSPEC_L                        32
+#define LUKS_DIGESTSIZE                        20
+#define LUKS_SALTSIZE                  32
+#define LUKS_MAGIC_L                   6
+#define UUID_STRING_L                  40
+
+struct luks_phdr {
+       uint8_t         magic[LUKS_MAGIC_L];
+       uint16_t        version;
+       uint8_t         cipherName[LUKS_CIPHERNAME_L];
+       uint8_t         cipherMode[LUKS_CIPHERMODE_L];
+       uint8_t         hashSpec[LUKS_HASHSPEC_L];
+       uint32_t        payloadOffset;
+       uint32_t        keyBytes;
+       uint8_t         mkDigest[LUKS_DIGESTSIZE];
+       uint8_t         mkDigestSalt[LUKS_SALTSIZE];
+       uint32_t        mkDigestIterations;
+       uint8_t         uuid[UUID_STRING_L];
+};
+
+static int probe_luks(blkid_probe pr, const struct blkid_idmag *mag)
+{
+       struct luks_phdr *header;
+
+       header = blkid_probe_get_sb(pr, mag, struct luks_phdr);
+       if (header == NULL)
+               return -1;
+
+       blkid_probe_sprintf_uuid(pr, header->uuid, 36, "%s", header->uuid);
+       blkid_probe_sprintf_version(pr, "%u", le16_to_cpu(header->version));
+       return 0;
+}
+
+const struct blkid_idinfo luks_idinfo =
+{
+       .name           = "crypto_LUKS",
+       .usage          = BLKID_USAGE_CRYPTO,
+       .probefunc      = probe_luks,
+       .magics         =
+       {
+               { .magic = "LUKS\xba\xbe", .len = 6 },
+               { NULL }
+       }
+};
index 2947446ce98a6d172d1eecaf0bc3ca2063eef183..ee1603b3b64ed886f04d4664d33eb0f4a55955eb 100644 (file)
@@ -50,5 +50,6 @@ extern const struct blkid_idinfo iso9660_idinfo;
 extern const struct blkid_idinfo udf_idinfo;
 extern const struct blkid_idinfo vfat_idinfo;
 extern const struct blkid_idinfo lvm2_idinfo;
+extern const struct blkid_idinfo luks_idinfo;
 
 #endif /* _BLKID_PROBE_H */