summaryrefslogtreecommitdiff
path: root/ubifs-utils/mkfs.ubifs/fscrypt.c
diff options
context:
space:
mode:
Diffstat (limited to 'ubifs-utils/mkfs.ubifs/fscrypt.c')
-rw-r--r--ubifs-utils/mkfs.ubifs/fscrypt.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/ubifs-utils/mkfs.ubifs/fscrypt.c b/ubifs-utils/mkfs.ubifs/fscrypt.c
index 68001e1..6d1fa4b 100644
--- a/ubifs-utils/mkfs.ubifs/fscrypt.c
+++ b/ubifs-utils/mkfs.ubifs/fscrypt.c
@@ -188,7 +188,7 @@ static int parse_key_descriptor(const char *desc, __u8 *dst)
return 0;
}
-static int load_master_key(const char *key_file)
+static int load_master_key(const char *key_file, struct cipher *fsc)
{
int kf;
ssize_t keysize;
@@ -208,6 +208,11 @@ static int load_master_key(const char *key_file)
err_msg("loading key from '%s': file is empty", key_file);
goto fail;
}
+ if (keysize < fsc->key_length) {
+ err_msg("key '%s' is too short (at least %u bytes required)",
+ key_file, fsc->key_length);
+ goto fail;
+ }
close(kf);
return 0;
@@ -237,7 +242,7 @@ struct fscrypt_context *init_fscrypt_context(const char *cipher_name,
if (parse_key_descriptor(key_descriptor, master_key_descriptor))
return NULL;
- if (load_master_key(key_file))
+ if (load_master_key(key_file, fscrypt_cipher))
return NULL;
RAND_bytes((void *)nonce, FS_KEY_DERIVATION_NONCE_SIZE);