diff options
author | Milan Broz <mbroz@redhat.com> | 2011-01-13 19:59:49 +0000 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2011-01-13 19:59:49 +0000 |
commit | 69a8cfcda21017364df1c21b720daf304b5598a6 (patch) | |
tree | c727770359b9295154194f0d8459ba7be3898b94 /drivers/md/dm-crypt.c | |
parent | 4a1aeb98297e17f4e0a8cdda919e63bf528b2e5d (diff) | |
download | linux-3.10-69a8cfcda21017364df1c21b720daf304b5598a6.tar.gz linux-3.10-69a8cfcda21017364df1c21b720daf304b5598a6.tar.bz2 linux-3.10-69a8cfcda21017364df1c21b720daf304b5598a6.zip |
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>
Diffstat (limited to 'drivers/md/dm-crypt.c')
-rw-r--r-- | drivers/md/dm-crypt.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index d5b0e4c0e70..4c4408a2602 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) static int crypt_set_key(struct crypt_config *cc, char *key) { - unsigned key_size = strlen(key) >> 1; - - if (cc->key_size && cc->key_size != key_size) + /* The key size may not be changed. */ + if (cc->key_size != (strlen(key) >> 1)) return -EINVAL; - cc->key_size = key_size; /* initial settings */ + /* Hyphen (which gives a key_size of zero) means there is no key. */ + if (!cc->key_size && strcmp(key, "-")) + return -EINVAL; - if ((!key_size && strcmp(key, "-")) || - (key_size && crypt_decode_key(cc->key, key, key_size) < 0)) + if (cc->key_size && crypt_decode_key(cc->key, key, cc->key_size) < 0) return -EINVAL; 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) ti->error = "Cannot allocate encryption context"; return -ENOMEM; } + cc->key_size = key_size; ti->private = cc; ret = crypt_ctr_cipher(ti, argv[0], argv[1]); |