Return-Path: <klibc-bounces@zytor.com>
Received: from terminus.zytor.com (mailman@localhost [127.0.0.1])
	by terminus.zytor.com (8.13.4/8.13.4) with ESMTP id k15AQ3lc006938;
	Sun, 5 Feb 2006 02:26:15 -0800
Received: from palpatine.hardeman.nu (1-1-12-13a.han.sth.bostream.se
	[82.182.30.168])
	by terminus.zytor.com (8.13.4/8.13.4) with ESMTP id k15APUjs006923
	(version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO)
	for <klibc@zytor.com>; Sun, 5 Feb 2006 02:25:33 -0800
Received: from ip54532fb6.speed.planet.nl ([84.83.47.182] helo=austin)
	by palpatine.hardeman.nu with esmtpsa
	(TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.50) id 1F5h57-0002nr-9I
	for klibc@zytor.com; Sun, 05 Feb 2006 11:25:24 +0100
Received: by austin (Postfix, from userid 1000)
	id 336D819AF3D; Sun,  5 Feb 2006 11:24:26 +0100 (CET)
Date: Sun, 5 Feb 2006 11:24:26 +0100
From: David =?iso-8859-1?Q?H=E4rdeman?= <david@2gen.com>
To: klibc@zytor.com
Message-ID: <20060205102426.GA10190@hardeman.nu>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="3V7upXqbjpZ4EhLz"
Content-Disposition: inline
User-Agent: Mutt/1.5.11+cvs20060126
Content-Transfer-Encoding: 7bit
X-SA-Score: -2.2
X-Virus-Scanned: ClamAV version 0.88, clamav-milter version 0.87 on localhost
X-Virus-Scanned: ClamAV version 0.88, clamav-milter version 0.87 on localhost
X-Virus-Status: Clean
X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 
	autolearn=unavailable version=3.0.4
X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on terminus.zytor.com
Subject: [klibc] Add LUKS support to fstype, second version
X-BeenThere: klibc@zytor.com
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: About Linux klibc and early userspace issues <klibc.zytor.com>
List-Unsubscribe: <http://www.zytor.com/mailman/listinfo/klibc>,
	<mailto:klibc-request@zytor.com?subject=unsubscribe>
List-Archive: <http://www.zytor.com/pipermail/klibc>
List-Post: <mailto:klibc@zytor.com>
List-Help: <mailto:klibc-request@zytor.com?subject=help>
List-Subscribe: <http://www.zytor.com/mailman/listinfo/klibc>,
	<mailto:klibc-request@zytor.com?subject=subscribe>
Sender: klibc-bounces@zytor.com
Errors-To: klibc-bounces@zytor.com
X-UID: 1336
X-Keywords: NonJunk                                                                                           


--3V7upXqbjpZ4EhLz
Content-Type: text/plain; charset=iso-8859-1; format=flowed
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

The attached patch adds support for detecting LUKS partitions (Linux=20
Unified Key Setup - http://luks.endorphin.org/) to fstype. This makes it=20
easier to automatically detect and activate encrypted (root) partitions=20
from an initramfs image.

The patch is now against klibc's git tree instead of klibc-1.2.

Signed-off-by: David H=E4rdeman <david@2gen.com>

--

 fstype.c  |   17 ++++++++++++++++-
 luks_fs.h |   45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 1 deletion(-)


--3V7upXqbjpZ4EhLz
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline; filename=klibc-add-luks-to-fstype-v2

Index: klibc/usr/kinit/fstype/fstype.c
===================================================================
--- klibc.orig/usr/kinit/fstype/fstype.c	2006-02-05 10:53:51.000000000 +0100
+++ klibc/usr/kinit/fstype/fstype.c	2006-02-05 11:09:31.000000000 +0100
@@ -7,7 +7,7 @@
  *  FSSIZE - filesystem size (if known)
  *
  * We currently detect (in order):
- *  gzip, cramfs, romfs, xfs, minix, ext3, ext2, reiserfs, jfs
+ *  gzip, cramfs, romfs, xfs, luks, minix, ext3, ext2, reiserfs, jfs
  *
  * MINIX, ext3 and Reiserfs bits are currently untested.
  */
@@ -29,6 +29,7 @@
 #include "ext2_fs.h"
 #include "ext3_fs.h"
 #include "xfs_sb.h"
+#include "luks_fs.h"
 
 /*
  * Slightly cleaned up version of jfs_superblock to
@@ -168,6 +169,19 @@
 	return 0;
 }
 
+static int luks_image(const unsigned char *buf, unsigned long long *blocks)
+{
+	const struct luks_partition_header *lph =
+		(const struct luks_partition_header *)buf;
+
+	if (!memcmp(lph->magic, LUKS_MAGIC, LUKS_MAGIC_L)) {
+		/* FSSIZE is dictated by the underlying fs, not by LUKS */
+		*blocks = 0;
+		return 1;
+	}
+	return 0;
+}
+
 struct imagetype {
 	off_t		block;
 	const char	name[12];
@@ -179,6 +193,7 @@
 	{ 0,	"cramfs",	cramfs_image	},
 	{ 0,	"romfs",	romfs_image	},
 	{ 0,	"xfs",		xfs_image	},
+	{ 0,	"luks",		luks_image	},
 	{ 1,	"minix",	minix_image	},
 	{ 1,	"ext3",		ext3_image	},
 	{ 1,	"ext2",		ext2_image	},
Index: klibc/usr/kinit/fstype/luks_fs.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ klibc/usr/kinit/fstype/luks_fs.h	2006-02-05 10:57:52.000000000 +0100
@@ -0,0 +1,45 @@
+#ifndef __LINUX_LUKS_FS_H
+#define __LINUX_LUKS_FS_H
+
+/* The basic structures of the luks partition header */
+#define LUKS_MAGIC_L		6
+#define LUKS_CIPHERNAME_L	32
+#define LUKS_CIPHERMODE_L	32
+#define LUKS_HASHSPEC_L		32
+#define LUKS_UUID_STRING_L	40
+
+#define LUKS_MAGIC		"LUKS\xBA\xBE"
+#define LUKS_DIGESTSIZE		20
+#define LUKS_SALTSIZE		32
+#define LUKS_NUMKEYS		8
+#define LUKS_MKD_ITER		10
+#define LUKS_KEY_DISABLED	0x0000DEAD
+#define LUKS_KEY_ENABLED	0x00AC71F3
+#define LUKS_STRIPES		4000
+
+
+/* On-disk "super block" */
+struct luks_partition_header {
+	char	magic[LUKS_MAGIC_L];
+	__be16	version;
+	char	cipherName[LUKS_CIPHERNAME_L];
+	char	cipherMode[LUKS_CIPHERMODE_L];
+	char	hashSpec[LUKS_HASHSPEC_L];
+	__be32	payloadOffset;
+	__be32  keyBytes;
+	char	mkDigest[LUKS_DIGESTSIZE];
+	char	mkDigestSalt[LUKS_SALTSIZE];
+	__be32	mkDigestIterations;
+	char	uuid[LUKS_UUID_STRING_L];
+
+	struct {
+		__be32	active;
+		/* Parameters for PBKDF2 processing */
+		__be32	passwordIterations;
+		char	passwordSalt[LUKS_SALTSIZE];
+		__be32	keyMaterialOffset;
+		__be32	stripes;
+	} keyblock[LUKS_NUMKEYS];
+};
+
+#endif

--3V7upXqbjpZ4EhLz
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
klibc mailing list
klibc@zytor.com
http://www.zytor.com/mailman/listinfo/klibc

--3V7upXqbjpZ4EhLz--
