TCRYPT: add dump command
[platform/upstream/cryptsetup.git] / lib / tcrypt / tcrypt.c
index 2dfdb88..fdd3ce4 100644 (file)
@@ -737,3 +737,52 @@ 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;
+}
+
+int TCRYPT_dump(struct crypt_device *cd,
+               struct tcrypt_phdr *hdr,
+               struct crypt_params_tcrypt *params)
+{
+       log_std(cd, "TCRYPT header information for %s\n",
+               device_path(crypt_metadata_device(cd)));
+       if (hdr->d.version) {
+               log_std(cd, "Version:       \t%d\n", hdr->d.version);
+               log_std(cd, "Driver req.:\t%d\n", hdr->d.version_tc);
+
+               log_std(cd, "Sector size:\t%" PRIu32 "\n", hdr->d.sector_size);
+               log_std(cd, "MK offset:\t%" PRIu64 "\n", hdr->d.mk_offset);
+               log_std(cd, "PBKDF2 hash:\t%s\n", params->hash_name);
+       }
+       log_std(cd, "Cipher chain:\t%s\n", params->cipher);
+       log_std(cd, "Cipher mode:\t%s\n", params->mode);
+       log_std(cd, "MK bits:       \t%d\n", params->key_size * 8);
+       return 0;
+}