- patches.suse/slab-handle-memoryless-nodes-v2a.patch: Refresh.
[linux-flexiantxendom0-3.2.10.git] / drivers / md / dm-crypt.c
index 959d6d1..a936372 100644 (file)
@@ -158,6 +158,9 @@ static void kcryptd_queue_crypt(struct dm_crypt_io *io);
  * plain: the initial vector is the 32-bit little-endian version of the sector
  *        number, padded with zeros if necessary.
  *
+ * plain64: the initial vector is the 64-bit little-endian version of the sector
+ *        number, padded with zeros if necessary.
+ *
  * essiv: "encrypted sector|salt initial vector", the sector number is
  *        encrypted with the bulk cipher using a salt as key. The salt
  *        should be derived from the bulk cipher's key via hashing.
@@ -180,6 +183,15 @@ static int crypt_iv_plain_gen(struct crypt_config *cc, u8 *iv, sector_t sector)
        return 0;
 }
 
+static int crypt_iv_plain64_gen(struct crypt_config *cc, u8 *iv,
+                               sector_t sector)
+{
+       memset(iv, 0, cc->iv_size);
+       *(u64 *)iv = cpu_to_le64(sector);
+
+       return 0;
+}
+
 /* Initialise ESSIV - compute salt but no local memory allocations */
 static int crypt_iv_essiv_init(struct crypt_config *cc)
 {
@@ -342,6 +354,10 @@ static struct crypt_iv_operations crypt_iv_plain_ops = {
        .generator = crypt_iv_plain_gen
 };
 
+static struct crypt_iv_operations crypt_iv_plain64_ops = {
+       .generator = crypt_iv_plain64_gen
+};
+
 static struct crypt_iv_operations crypt_iv_essiv_ops = {
        .ctr       = crypt_iv_essiv_ctr,
        .dtr       = crypt_iv_essiv_dtr,
@@ -973,14 +989,14 @@ static int crypt_set_key(struct crypt_config *cc, char *key)
 
        set_bit(DM_CRYPT_KEY_VALID, &cc->flags);
 
-       return 0;
+       return crypto_ablkcipher_setkey(cc->tfm, cc->key, cc->key_size);
 }
 
 static int crypt_wipe_key(struct crypt_config *cc)
 {
        clear_bit(DM_CRYPT_KEY_VALID, &cc->flags);
        memset(&cc->key, 0, cc->key_size * sizeof(u8));
-       return 0;
+       return crypto_ablkcipher_setkey(cc->tfm, cc->key, cc->key_size);
 }
 
 /*
@@ -1022,12 +1038,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
                return -ENOMEM;
        }
 
-       if (crypt_set_key(cc, argv[1])) {
-               ti->error = "Error decoding key";
-               goto bad_cipher;
-       }
-
-       /* Compatiblity mode for old dm-crypt cipher strings */
+       /* Compatibility mode for old dm-crypt cipher strings */
        if (!chainmode || (strcmp(chainmode, "plain") == 0 && !ivmode)) {
                chainmode = "cbc";
                ivmode = "plain";
@@ -1054,6 +1065,11 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
        strcpy(cc->chainmode, chainmode);
        cc->tfm = tfm;
 
+       if (crypt_set_key(cc, argv[1]) < 0) {
+               ti->error = "Error decoding and setting key";
+               goto bad_ivmode;
+       }
+
        /*
         * Choose ivmode. Valid modes: "plain", "essiv:<esshash>", "benbi".
         * See comments at iv code
@@ -1063,6 +1079,8 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
                cc->iv_gen_ops = NULL;
        else if (strcmp(ivmode, "plain") == 0)
                cc->iv_gen_ops = &crypt_iv_plain_ops;
+       else if (strcmp(ivmode, "plain64") == 0)
+               cc->iv_gen_ops = &crypt_iv_plain64_ops;
        else if (strcmp(ivmode, "essiv") == 0)
                cc->iv_gen_ops = &crypt_iv_essiv_ops;
        else if (strcmp(ivmode, "benbi") == 0)
@@ -1130,11 +1148,6 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
                goto bad_bs;
        }
 
-       if (crypto_ablkcipher_setkey(tfm, cc->key, key_size) < 0) {
-               ti->error = "Error setting key";
-               goto bad_device;
-       }
-
        if (sscanf(argv[2], "%llu", &tmpll) != 1) {
                ti->error = "Invalid iv_offset sector";
                goto bad_device;