Commit 69a8cfcd authored by Milan Broz's avatar Milan Broz Committed by Alasdair G Kergon

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: default avatarMilan Broz <mbroz@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 4a1aeb98
...@@ -973,15 +973,15 @@ static void crypt_encode_key(char *hex, u8 *key, unsigned int size) ...@@ -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) static int crypt_set_key(struct crypt_config *cc, char *key)
{ {
unsigned key_size = strlen(key) >> 1; /* The key size may not be changed. */
if (cc->key_size != (strlen(key) >> 1))
if (cc->key_size && cc->key_size != key_size)
return -EINVAL; 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, "-")) || if (cc->key_size && crypt_decode_key(cc->key, key, cc->key_size) < 0)
(key_size && crypt_decode_key(cc->key, key, key_size) < 0))
return -EINVAL; return -EINVAL;
set_bit(DM_CRYPT_KEY_VALID, &cc->flags); 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,6 +1194,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
ti->error = "Cannot allocate encryption context"; ti->error = "Cannot allocate encryption context";
return -ENOMEM; return -ENOMEM;
} }
cc->key_size = key_size;
ti->private = cc; ti->private = cc;
ret = crypt_ctr_cipher(ti, argv[0], argv[1]); ret = crypt_ctr_cipher(ti, argv[0], argv[1]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment