aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilan Broz <mbroz@redhat.com>2011-01-13 14:59:49 -0500
committerAlasdair G Kergon <agk@redhat.com>2011-01-13 14:59:49 -0500
commit69a8cfcda21017364df1c21b720daf304b5598a6 (patch)
treec727770359b9295154194f0d8459ba7be3898b94
parent4a1aeb98297e17f4e0a8cdda919e63bf528b2e5d (diff)
dm crypt: set key size early
Simplify key size verification (hexadecimal string) and set key size early in constructor. (Patch required by later changes.) Signed-off-by: Milan Broz <mbroz@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
-rw-r--r--drivers/md/dm-crypt.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index d5b0e4c0e702..4c4408a2602f 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -973,15 +973,15 @@ static void crypt_encode_key(char *hex, u8 *key, unsigned int size)
973 973
974static int crypt_set_key(struct crypt_config *cc, char *key) 974static int crypt_set_key(struct crypt_config *cc, char *key)
975{ 975{
976 unsigned key_size = strlen(key) >> 1; 976 /* The key size may not be changed. */
977 977 if (cc->key_size != (strlen(key) >> 1))
978 if (cc->key_size && cc->key_size != key_size)
979 return -EINVAL; 978 return -EINVAL;
980 979
981 cc->key_size = key_size; /* initial settings */ 980 /* Hyphen (which gives a key_size of zero) means there is no key. */
981 if (!cc->key_size && strcmp(key, "-"))
982 return -EINVAL;
982 983
983 if ((!key_size && strcmp(key, "-")) || 984 if (cc->key_size && crypt_decode_key(cc->key, key, cc->key_size) < 0)
984 (key_size && crypt_decode_key(cc->key, key, key_size) < 0))
985 return -EINVAL; 985 return -EINVAL;
986 986
987 set_bit(DM_CRYPT_KEY_VALID, &cc->flags); 987 set_bit(DM_CRYPT_KEY_VALID, &cc->flags);
@@ -1194,6 +1194,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1194 ti->error = "Cannot allocate encryption context"; 1194 ti->error = "Cannot allocate encryption context";
1195 return -ENOMEM; 1195 return -ENOMEM;
1196 } 1196 }
1197 cc->key_size = key_size;
1197 1198
1198 ti->private = cc; 1199 ti->private = cc;
1199 ret = crypt_ctr_cipher(ti, argv[0], argv[1]); 1200 ret = crypt_ctr_cipher(ti, argv[0], argv[1]);