Support limitation for "plain" hash (no hash).

This can be used for mapping problematic cryptosystems which
wipes some key (losetup sometimes set last byte to zero).
This commit is contained in:
Milan Broz
2013-11-10 19:31:02 +01:00
parent db56125708
commit 09c229fe6c
2 changed files with 16 additions and 1 deletions

View File

@@ -99,7 +99,16 @@ int crypt_plain_hash(struct crypt_device *ctx __attribute__((unused)),
pad_size = 0;
}
r = hash(hash_name_buf, hash_size, key, passphrase_size, passphrase);
/* No hash, copy passphrase directly */
if (!strcmp(hash_name_buf, "plain")) {
if (passphrase_size < hash_size) {
log_dbg("Too short plain passphrase.");
return -EINVAL;
}
memcpy(key, passphrase, hash_size);
r = 0;
} else
r = hash(hash_name_buf, hash_size, key, passphrase_size, passphrase);
if (r == 0 && pad_size)
memset(key + hash_size, 0, pad_size);