diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 033c0cdb7..72f23b9fb 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -88,6 +88,13 @@ static int parse_one_option(const char *option) { return 0; } + if (opt_key_size % 8) { + log_error("size= not a multiple of 8, ignoring."); + return 0; + } + + opt_key_size /= 8; + } else if (startswith(option, "key-slot=")) { opt_type = CRYPT_LUKS1; @@ -407,7 +414,7 @@ static int attach_luks_or_plain(struct crypt_device *cd, /* for CRYPT_PLAIN limit reads * from keyfile to key length, and * ignore keyfile-size */ - opt_keyfile_size = opt_key_size / 8; + opt_keyfile_size = opt_key_size; /* In contrast to what the name * crypt_setup() might suggest this @@ -570,7 +577,7 @@ int main(int argc, char *argv[]) { else until = 0; - opt_key_size = (opt_key_size > 0 ? opt_key_size : 256); + opt_key_size = (opt_key_size > 0 ? opt_key_size : (256 / 8)); if (key_file) { struct stat st;