summaryrefslogtreecommitdiff
path: root/ubifs-utils/mkfs.ubifs/crypto.c
diff options
context:
space:
mode:
authorRichard Weinberger <richard@nod.at>2018-10-18 16:37:12 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2018-11-01 12:42:01 +0100
commit9c8caf5aca7527235afcbbb813e9bf490a239dee (patch)
treec5dbafb842920201295ae9572084f66467799d33 /ubifs-utils/mkfs.ubifs/crypto.c
parent922a6e998538a1ea57682d0d3373cb4d19e9dc02 (diff)
mkfs.ubifs: Compute encryption key descriptor automatically
...if none is given. To be compatible with fscryptctl. Signed-off-by: Richard Weinberger <richard@nod.at> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'ubifs-utils/mkfs.ubifs/crypto.c')
-rw-r--r--ubifs-utils/mkfs.ubifs/crypto.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/ubifs-utils/mkfs.ubifs/crypto.c b/ubifs-utils/mkfs.ubifs/crypto.c
index d0f24e1..50a09b5 100644
--- a/ubifs-utils/mkfs.ubifs/crypto.c
+++ b/ubifs-utils/mkfs.ubifs/crypto.c
@@ -26,7 +26,7 @@
#include "fscrypt.h"
#include "common.h"
-static int do_sha256(const unsigned char *in, size_t len, unsigned char *out)
+static int do_hash(const EVP_MD *md, const unsigned char *in, size_t len, unsigned char *out)
{
unsigned int out_len;
EVP_MD_CTX *mdctx = EVP_MD_CTX_create();
@@ -34,7 +34,7 @@ static int do_sha256(const unsigned char *in, size_t len, unsigned char *out)
if (!mdctx)
return -1;
- if (EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL) != 1)
+ if (EVP_DigestInit_ex(mdctx, md, NULL) != 1)
return -1;
if(EVP_DigestUpdate(mdctx, in, len) != 1)
@@ -121,7 +121,7 @@ static size_t gen_essiv_salt(const void *iv, size_t iv_len, const void *key, siz
return -1;
}
- if (do_sha256(key, key_len, sha256) != 0) {
+ if (do_hash(EVP_sha256(), key, key_len, sha256) != 0) {
errmsg("sha256 failed");
return -1;
}
@@ -288,6 +288,27 @@ ssize_t derive_key_aes(const void *deriving_key, const void *source_key,
aes_key_len, NULL, 0, derived_key);
}
+int derive_key_descriptor(const void *source_key, void *descriptor)
+{
+ int ret = -1;
+ void *hash1 = xzalloc(EVP_MD_size(EVP_sha512()));
+ void *hash2 = xzalloc(EVP_MD_size(EVP_sha512()));
+
+ if (do_hash(EVP_sha512(), source_key, FS_MAX_KEY_SIZE, hash1) != 0)
+ goto out;
+
+ if (do_hash(EVP_sha512(), hash1, EVP_MD_size(EVP_sha512()), hash2) != 0)
+ goto out;
+
+ memcpy(descriptor, hash2, FS_KEY_DESCRIPTOR_SIZE);
+
+ ret = 0;
+out:
+ free(hash1);
+ free(hash2);
+ return ret;
+}
+
static struct cipher ciphers[] = {
{
.name = "AES-128-CBC",