Allow empty cipher (cipher_null).
authorMilan Broz <gmazyland@gmail.com>
Sun, 20 May 2012 19:38:23 +0000 (21:38 +0200)
committerMilan Broz <gmazyland@gmail.com>
Sun, 20 May 2012 19:38:23 +0000 (21:38 +0200)
ChangeLog
lib/libdevmapper.c
lib/utils_crypt.c
tests/mode-test

index 15d383a..805257b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2012-05-09  Milan Broz  <gmazyland@gmail.com>
        * Fix keyslot removal (wipe keyslot) for device with 4k hw block (1.4.0).
+       * Allow empty cipher (cipher_null) for testing.
 
 2012-05-02  Milan Broz  <gmazyland@gmail.com>
        * Fix loop mapping on readonly file.
index 23c55fe..7510dec 100644 (file)
@@ -243,7 +243,7 @@ static void hex_key(char *hexkey, size_t key_size, const char *key)
 
 static char *get_params(struct crypt_dm_active_device *dmd)
 {
-       int r, max_size;
+       int r, max_size, null_cipher = 0;
        char *params, *hexkey;
        const char *features = "";
 
@@ -255,11 +255,17 @@ static char *get_params(struct crypt_dm_active_device *dmd)
                        log_dbg("Discard/TRIM is not supported by the kernel.");
        }
 
-       hexkey = crypt_safe_alloc(dmd->vk->keylength * 2 + 1);
+       if (!strncmp(dmd->cipher, "cipher_null-", 12))
+               null_cipher = 1;
+
+       hexkey = crypt_safe_alloc(null_cipher ? 2 : (dmd->vk->keylength * 2 + 1));
        if (!hexkey)
                return NULL;
 
-       hex_key(hexkey, dmd->vk->keylength, dmd->vk->key);
+       if (null_cipher)
+               strncpy(hexkey, "-", 2);
+       else
+               hex_key(hexkey, dmd->vk->keylength, dmd->vk->key);
 
        max_size = strlen(hexkey) + strlen(dmd->cipher) +
                   strlen(dmd->device) + strlen(features) + 64;
index 11937d3..8b12167 100644 (file)
@@ -58,6 +58,15 @@ int crypt_parse_name_and_mode(const char *s, char *cipher, int *key_nums,
                return 0;
        }
 
+       /* Short version for "empty" cipher */
+       if (!strcmp(s, "null")) {
+               strncpy(cipher, "cipher_null", MAX_CIPHER_LEN);
+               strncpy(cipher_mode, "ecb-null", 9);
+               if (key_nums)
+                       *key_nums = 0;
+               return 0;
+       }
+
        if (sscanf(s, "%" MAX_CIPHER_LEN_STR "[^-]", cipher) == 1) {
                strncpy(cipher_mode, "cbc-plain", 10);
                if (key_nums)
index 9a2ad8b..13d70d7 100755 (executable)
@@ -60,7 +60,7 @@ dmcrypt_check() # device outstring
                fail
        fi
 
-       X=$($CRYPTSETUP status $1 | grep cipher | sed s/\.\*cipher:\\s*//)
+       X=$($CRYPTSETUP status $1 | grep cipher: | sed s/\.\*cipher:\\s*//)
        if [ $X = $2 ] ; then
                echo -n "[status OK]"
        else
@@ -133,6 +133,11 @@ add_device
 dmcrypt aes aes-cbc-plain
 dmcrypt aes-plain aes-cbc-plain
 
+# empty cipher
+dmcrypt null cipher_null-ecb-null
+dmcrypt cipher_null cipher_null-cbc-plain
+dmcrypt cipher_null-ecb-null
+
 # codebook doesn't support IV at all
 for cipher in $CIPHERS ; do
        dmcrypt "$cipher-ecb"