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);

View File

@@ -135,6 +135,12 @@ crypt_key sha256 512 file $KEY_FILE $KEY_FILE_HEX
crypt_key plain 128 cat /dev/zero 00000000000000000000000000000000 16
crypt_key plain 128 cat /dev/zero 00000000000000000000000000000000 17
crypt_key plain 128 cat $KEY_FILE ${KEY_FILE_HEX:0:28}0000 14
# limiting plain (no hash)
crypt_key plain 256 pwd "xxxxxxxx" 7878787878787878000000000000000000000000000000000000000000000000
crypt_key plain:2 256 pwd "xxxxxxxx" 7878000000000000000000000000000000000000000000000000000000000000
crypt_key plain:9 256 failpwd "xxxxxxxx" x
crypt_key sha256 128 cat $KEY_FILE a82c9227cc54c7475620ce85ba1fca1e 14
crypt_key sha256:14 128 cat $KEY_FILE a82c9227cc54c7475620ce85ba1f0000 14