How can I get dm-crypt to support large-block-cipher algorithm?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, all,

I am using a hardware adapter to accelerating encrypting a dm-crypted logic volume. I encapsulated the API provided by the adapter as loadable module and registered into the kernel. The block size of cipher algorithm provided the adapter is 16 bytes, and the encryption is a 3 stage mode, i.e. "<initial()>-[update()]-<final()>" mode, where stage(s) in "<>" are compulsive and stage(s) in"[]" are optional and "update()" for block size aligned buffer and "final()" for un-aligned buffer. 

The problem is the "update()" or "final()" performed very bad (about 3Mbps) when data is fed less then 512 bytes. We have affirmed that it is caused by the adapter itself. I am using the kernel 2.6.18. It only support block cipher with 8B or 16B block size. So, I modified the crypto/cipher.c and set the cipher block size in my modules as 512B. Now I can call the "update()" or "final()" with 512 bytes data as input and it works fairly well so far and hit the speed about 80Mbps. 

But I still do not satisfied by this result because the adapter is performed best when the input buffer is as large as more than 2048 bytes. So I tried to set the cipher block size in my modules as 1024B. Now I can cryptsetup create an crypt lv. But when I tried to mkfs.ext3 on the lv, it reports errors. I searched on the internet and found a topic relate to my problem. The link is:
http://markmail.org/message/mpkkzczthrdhghui
But I found the patch for md/dm-crypt.c in this page seemed not suit for me. So rewrite the patch and apply to my kernel. But it does not works but broken down when I make file system on a lv. The patches are attached as follows.

How can I get the dm-crypt to support large-block-cipher algorithm (bigger than 512B) ?
Are there any problem in my patches?

Any helps or discussions are appreciated!

Mersenne Yang
2009-1-7

--- crypto/cipher.c	2006-09-20 11:42:06.000000000 +0800
+++ newcrypt/cipher.c	2009-01-06 17:04:50.933694600 +0800
@@ -11,6 +11,9 @@
  * Software Foundation; either version 2 of the License, or (at your option) 
  * any later version.
  *
+ * kernel 2.6.18 (centos 5.2). Added wide block cipher support.
+ * Copyright (c) 2009 Muxiang Yang<yangmuxiang@xxxxxxxxxxx>
+ *
  */
 #include <linux/compiler.h>
 #include <linux/kernel.h>
@@ -37,6 +40,34 @@
 	((u32 *)a)[3] ^= ((u32 *)b)[3];
 }
 
+static inline void xor_256(u8 *a, const u8 *b)
+{
+	int i;
+	for(i = 0; i < (256/8)/4; i++ )
+	        ((u32 *)a)[i] ^= ((u32 *)b)[i];
+}
+
+static inline void xor_4096(u8 *a, const u8 *b)
+{
+	int i;
+	for(i = 0; i < (4096/8)/4; i++ )
+	        ((u32 *)a)[i] ^= ((u32 *)b)[i];
+}
+
+static inline void xor_8192(u8 *a, const u8 *b)
+{
+	int i;
+	for(i = 0; i < (8192/8)/4; i++ )
+	        ((u32 *)a)[i] ^= ((u32 *)b)[i];
+}
+
+static inline void xor_16384(u8 *a, const u8 *b)
+{
+	int i;
+	for(i = 0; i < (16384/8)/4; i++ )
+	        ((u32 *)a)[i] ^= ((u32 *)b)[i];
+}
+
 static unsigned int crypt_slow(const struct cipher_desc *desc,
 			       struct scatter_walk *in,
 			       struct scatter_walk *out, unsigned int bsize)
@@ -439,6 +470,23 @@
 	    		ops->cit_xor_block = xor_128;
 	    		break;
 	    		
+		/*yangmx: 32~2048, Special for WST module.*/
+	    	case 32:
+	    		ops->cit_xor_block = xor_256;
+       			break;
+
+		case 512:
+	                ops->cit_xor_block = xor_4096; 
+			break;
+
+		case 1024:
+			ops->cit_xor_block = xor_8192; 
+	                break;
+
+		case 2048:
+			ops->cit_xor_block = xor_16384; 
+	                break;
+
 	    	default:
 	    		printk(KERN_WARNING "%s: block size %u not supported\n",
 	    		       crypto_tfm_alg_name(tfm),


--- md/dm-crypt.c	2009-01-03 14:38:30.000000000 +0800
+++ newmd/dm-crypt.c	2009-01-05 16:34:41.000000000 +0800
@@ -72,6 +72,7 @@
 	unsigned int iv_size;
 	unsigned int key_size;
 	u8 key[0];
+	int extra_shift;
 };
 
 #define MIN_IOS        16
@@ -100,8 +101,8 @@
 static int crypt_iv_plain(struct crypt_config *cc, u8 *iv, sector_t sector)
 {
 	memset(iv, 0, cc->iv_size);
-	*(u32 *)iv = cpu_to_le32(sector & 0xffffffff);
 
+	*(u32*)iv = cpu_to_le32(sector >> cc->extra_shift & 0xffffffff) ;
 	return 0;
 }
 
@@ -162,12 +163,12 @@
 		struct scatterlist sg_in = {
 			.page = bv_in->bv_page,
 			.offset = bv_in->bv_offset + ctx->offset_in,
-			.length = 1 << SECTOR_SHIFT
+			.length = (1 << SECTOR_SHIFT) << cc->extra_shift
 		};
 		struct scatterlist sg_out = {
 			.page = bv_out->bv_page,
 			.offset = bv_out->bv_offset + ctx->offset_out,
-			.length = 1 << SECTOR_SHIFT
+			.length = (1 << SECTOR_SHIFT) << cc->extra_shift
 		};
 
 		ctx->offset_in += sg_in.length;
@@ -428,6 +429,8 @@
 	char *mode;
 	unsigned int crypto_flags;
 	unsigned int key_size;
+	unsigned int tmp_shift;
+	unsigned int cia_blk_size;
 
 	if (argc != 5) {
 		ti->error = PFX "Not enough arguments";
@@ -529,6 +532,26 @@
 		goto bad4;
 	}
 
+	tmp_shift = 0;
+	cia_blk_size = crypto_tfm_alg_blocksize(cc->tfm) ;
+	while ( cia_blk_size > (1 << SECTOR_SHIFT) ){ 
+		cia_blk_size >>= 1;
+		tmp_shift++;
+	}
+	cc->extra_shift = tmp_shift;
+
+	if (cc->extra_shift) { 
+	/* update hardsector_size */ 
+		if (ti->limits.hardsect_size%(1 << SECTOR_SHIFT)) { 
+			ti->error = "Weird sector size, too small or " 
+				"not a power of 2";
+			goto bad4;
+		} 
+		while (ti->limits.hardsect_size < 
+			(1 << SECTOR_SHIFT) << cc->extra_shift) 
+			ti->limits.hardsect_size <<= 1;
+	} 
+
 	if (dm_get_device(ti, argv[3], cc->start, ti->len,
 	                  dm_table_get_mode(ti->table), &cc->dev)) {
 		ti->error = PFX "Device lookup failed";


Powered by MessageSoft SMG 
SPAM, virus-free and secure email


---------------------------------------------------------------------
dm-crypt mailing list - http://www.saout.de/misc/dm-crypt/
To unsubscribe, e-mail: dm-crypt-unsubscribe@xxxxxxxx
For additional commands, e-mail: dm-crypt-help@xxxxxxxx



[Index of Archives]     [Device Mapper Devel]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux