Skip to contentSkip to conversation

Cryptoapi on 2.4.17 (2 patches)

PATCH Zygo Blaxell 2 participants 2 messages Dec 26, 2001 Block layer

lore
Share & tools
lore
#0 lore raw

I have two patches, one for cryptoAPI (current CVS) and one for the Linux kernel (2.4.17).

The cryptoapi patch fixes a silly symbol name bug. The patch for the Linux kernel changes the default lo_iv_mode to LO_IV_MODE_SECTOR--otherwise, the patch is just a straightforward port of the patch in cryptoapi/doc in cryptoavi CVS.

I noticed that there doesn't seem to be a way to set lo_iv_mode from user-space, not even with a module or kernel command-line parameter. Is this just one of those features that isn't implemented yet, or did I miss something?

The patches seem to work: I can swap on an rc6 encrypted partition using the patches, and I can create an ext2 filesystem on an rc6 loopback file, copy some data to it, unmount, losetup -d, losetup -e, mount it again, and _still access the data afterwards_. Whee!

This still doesn't completely work for encrypted swap because somebody (who shall remain nameless, but whose name rhymes with socks) seems to have "lost" the kreclaimd kernel thread. I thought I would try to get someone else to look at this before tackling that problem...

? tests/.deps
? tests/Makefile
? tests/Makefile.in
Index: api/cryptoloop.c
===================================================================
RCS file: /cvsroot/cryptoapi/cryptoapi/api/cryptoloop.c,v retrieving revision 1.4

cryptoloop.c +5 -5
diff -u -r1.4 cryptoloop.c
@@ -44,7 +44,7 @@
 # error you need at least kernel 2.4.3 -- unless you know exacty what you are doing
 #endif
 
-#if !defined(LOOP_IV_SECTOR_SIZE)
+#if !defined(LO_IV_SECTOR_SIZE)
 # error you need to to patch your loop.c driver
 #endif
 
@@ -85,10 +85,10 @@
   struct cipher_context *cx;
 
   /* encryption breaks for non sector aligned offsets */
-  if (info->lo_offset % LOOP_IV_SECTOR_SIZE) 
+  if (info->lo_offset % LO_IV_SECTOR_SIZE) 
     goto out;
 
-  lx->blocksize = LOOP_IV_SECTOR_SIZE;
+  lx->blocksize = LO_IV_SECTOR_SIZE;
   lx->debug = 0;
 
   strncpy(cipher, info->lo_name, LO_NAME_SIZE);
@@ -163,7 +163,7 @@
     out = raw_buf;
   }
 
-  IV /= blocksize / LOOP_IV_SECTOR_SIZE;
+  IV /= blocksize / LO_IV_SECTOR_SIZE;
 
 #if defined(CRYPTOLOOP_DEBUG)
   if (lx->debug)
@@ -203,7 +203,7 @@
   switch (cmd) {
   case CRYPTOLOOP_SET_BLKSIZE:
     printk (KERN_DEBUG "cryptoloop: switch to blocksize %d requested\n", *arg_int);
-    if (*arg_int >= 0 && (*arg_int % LOOP_IV_SECTOR_SIZE == 0))
+    if (*arg_int >= 0 && (*arg_int % LO_IV_SECTOR_SIZE == 0))
       {
         lx->blocksize = *arg_int;
         err = 0;
block/loop.c renamed from home/zblaxell/linux/p3-laptop/kernel-source-2.4.17-zb-p3-laptop-zb2001122605/drivers/block/loop.c +46 -28

110 lines not on this page · raw message

#1 lore raw

hello!

Quoted 2 lines · Zygo Blaxell

I have two patches, one for cryptoAPI (current CVS) and one for the Linux kernel (2.4.17).

first of all, thanks for getting involved! :-)

Quoted 1 line

The cryptoapi patch fixes a silly symbol name bug. The

well, that's due to the WIP state of the CVS... I was in the midst of back-porting the development I did for the new int. patches at
http://www.kernel.org/pub/linux/kernel/people/hvr/testing/
when this time-consuming christmas event started becoming unignorable... C;-)

Quoted 9 lines

patch for the Linux kernel changes the default lo_iv_mode to LO_IV_MODE_SECTOR--otherwise, the patch is just a straightforward port of the patch in cryptoapi/doc in cryptoavi CVS.

I noticed that there doesn't seem to be a way to set lo_iv_mode from user-space, not even with a module or kernel command-line parameter. Is this just one of those features that isn't implemented yet, or did I miss something?

the 'unimplemented'-choice applies;
but there's more... I'm glad you picked up the issue again, since it was again starting to fall into oblivion... :-/

there are two different approaches, the first one I tried, was the one seen in the cryptoapi-packaging, i.e. backward compatible; un-aware loop-filters would get the old (broken) iv metric, while aware filters could aktivate the 512-byte metric...
this approach was deemed an ugly 'toothpaste-back-to-tube' approach, but it tried not to break old filters...
a few weeks ago, I retried to bring the issue on, in order to get the patches somehow included into the mainstream-kernel; all parties agreed that we could as well break the old iv-mode, and just default to the better 'new' one... that way old filters may break the on-disk format, but they will automatically become iv-safe; and if one really cares, you can calculate the old iv from the new iv (just see the new int.patch and cryptoloop_cfg below...)... BUT... as of now (2.4.17), the kernel still uses the old IV scheme... it seems I'm not very good at being annoying enough in order to get patches into the kernel... ;-)

well, if you take a look at the above mentioned testing-directory, you'll find a cryptoloop_cfg.c which is some kind of user-space tool for controlling the iv metric somewhat... it's more or less a hack, which only works (if at all) when used in conjunction with the loop-hvr patch (and the latest patch-int in that directory) the tool's provided for converting your old non-512-iv metric encrypted volumes to more flexible 'atomar-sector-sized'-iv encrypted ones by doing something like (untested --> make backups before trying it at home... or keep both pieces...)

# losetup -e ...  /dev/loop0 /dev/blockdev
# cryptoloop_cfg /dev/loop0 --set-blksize 0
    if you happen to know the previously used iv size, then use that one
    instead of '0' which uses the transfer chunks' size as iv size...
    also verify /dev/loop0 contains a properly decrypted content!
    mounting it would be a good idea, because the soft blocksize is set
    by the filesystem code -- this is needed when using '0' as
    --set-blksize arg!!!...]
# losetup -e ... /dev/loop1 /dev/blockdev
    that's for the new encrypted data, you can use the chance to change
    encryption parameters as well... i.e. another cipher or
    passphrase...
    and now for the important step: (make sure the filesystem isn't
    mounted anymore)
# dd if=/dev/loop0 of=/dev/loop1
    this will take some time... it will decrypt the data per /dev/loop0
    and encrypt it through /dev/loop1 back to /dev/blockdev
    on-the-fly... (you could use also different /dev/blockdev's if you
    don't trust this procedure...)
# losetup -d /dev/loop0
    unloop /dev/loop0...
    ...now you should have completed the conversion... /dev/loop1 should
    contain your unencrypted data... and /dev/blockdev the new encrypted
    view of it...
Quoted 4 lines

The patches seem to work: I can swap on an rc6 encrypted partition using the patches, and I can create an ext2 filesystem on an rc6 loopback file, copy some data to it, unmount, losetup -d, losetup -e, mount it again, and _still access the data afterwards_. Whee!

...well, if it wasn't so, you'd have implemented some kind of data shredder... *g*

regards,

Signature · 4 lines
Herbert Valerio Riedel       /    Phone: (EUROPE) +43-1-58801-18840
Email: [email protected]       /    Finger [email protected] for GnuPG Public Key
GnuPG Key Fingerprint: 7BB9 2D6C D485 CE64 4748  5F65 4981 E064 883F
4142