From: Karel Zak Date: Wed, 5 Nov 2008 13:39:36 +0000 (+0100) Subject: blkid: add LUKS support X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06da6d00e4ea4eeeecfa3d4cc046d6383e041ed3;p=util-linux blkid: add LUKS support Signed-off-by: Karel Zak --- diff --git a/libs/blkid/src/probe.c b/libs/blkid/src/probe.c index 9f40d642..118a355a 100644 --- a/libs/blkid/src/probe.c +++ b/libs/blkid/src/probe.c @@ -51,7 +51,7 @@ static const struct blkid_idinfo *idinfos[] = &jmraid_idinfo, &lvm2_idinfo, /* TODO: lvm1 */ - /* TODO: LUKS */ + &luks_idinfo, /* Filesystems */ &vfat_idinfo, diff --git a/libs/blkid/src/probers/Makefile.am b/libs/blkid/src/probers/Makefile.am index 8cccc806..5bca88c4 100644 --- a/libs/blkid/src/probers/Makefile.am +++ b/libs/blkid/src/probers/Makefile.am @@ -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 index 00000000..7ded56d5 --- /dev/null +++ b/libs/blkid/src/probers/luks.c @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2004 Kay Sievers + * Copyright (C) 2008 Karel Zak + * + * 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 +#include +#include +#include +#include +#include +#include + +#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 } + } +}; diff --git a/libs/blkid/src/probers/probers.h b/libs/blkid/src/probers/probers.h index 2947446c..ee1603b3 100644 --- a/libs/blkid/src/probers/probers.h +++ b/libs/blkid/src/probers/probers.h @@ -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 */