From 8d69e19ac1e43310e8eb034ec685bb5131ec321b Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Fri, 23 Nov 2012 15:20:46 +0100 Subject: [PATCH] TCRYPT: support crypt_volume_key_get --- lib/setup.c | 3 ++- lib/tcrypt/tcrypt.c | 29 +++++++++++++++++++++++++++++ lib/tcrypt/tcrypt.h | 6 ++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/setup.c b/lib/setup.c index 82f8a24..63ad8b1 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -2137,7 +2137,8 @@ int crypt_volume_key_get(struct crypt_device *cd, } else if (isLUKS(cd->type)) { r = LUKS_open_key_with_hdr(keyslot, passphrase, passphrase_size, &cd->hdr, &vk, cd); - + } else if (isTCRYPT(cd->type)) { + r = TCRYPT_get_volume_key(cd, &cd->tcrypt_hdr, &cd->tcrypt_params, &vk); } else log_err(cd, _("This operation is not supported for %s crypt device.\n"), cd->type ?: "(none)"); diff --git a/lib/tcrypt/tcrypt.c b/lib/tcrypt/tcrypt.c index 2dfdb88..2f68d9c 100644 --- a/lib/tcrypt/tcrypt.c +++ b/lib/tcrypt/tcrypt.c @@ -737,3 +737,32 @@ uint64_t TCRYPT_get_iv_offset(struct tcrypt_phdr *hdr) return 0; return (hdr->d.mk_offset / hdr->d.sector_size); } + +int TCRYPT_get_volume_key(struct crypt_device *cd, + struct tcrypt_phdr *hdr, + struct crypt_params_tcrypt *params, + struct volume_key **vk) +{ + int i, num_keys = 1, key_size; + const char *c; + + if (!hdr->d.version) { + log_dbg("TCRYPT: this function is not supported without encrypted header load."); + return -ENOTSUP; + } + + *vk = crypt_alloc_volume_key(params->key_size, NULL); + if (!*vk) + return -ENOMEM; + + for (num_keys = 0, c = params->cipher; c ; num_keys++) + c = strchr(++c, '-'); + + key_size = params->key_size / num_keys; + + for (i = 0; i < num_keys; i++) + copy_key(&(*vk)->key[key_size * i], hdr->d.keys, num_keys - 1, + key_size, i, params->mode); + + return 0; +} diff --git a/lib/tcrypt/tcrypt.h b/lib/tcrypt/tcrypt.h index d35b1e6..61afa7d 100644 --- a/lib/tcrypt/tcrypt.h +++ b/lib/tcrypt/tcrypt.h @@ -65,6 +65,7 @@ struct tcrypt_phdr { } __attribute__((__packed__)); struct crypt_dm_active_device; +struct volume_key; struct device; int TCRYPT_read_phdr(struct crypt_device *cd, @@ -89,4 +90,9 @@ int TCRYPT_deactivate(struct crypt_device *cd, uint64_t TCRYPT_get_data_offset(struct tcrypt_phdr *hdr); uint64_t TCRYPT_get_iv_offset(struct tcrypt_phdr *hdr); +int TCRYPT_get_volume_key(struct crypt_device *cd, + struct tcrypt_phdr *hdr, + struct crypt_params_tcrypt *params, + struct volume_key **vk); + #endif -- 2.7.4