aboutsummaryrefslogtreecommitdiff
path: root/ubifs-utils
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2018-10-18 16:36:57 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2018-11-01 12:40:04 +0100
commit9f2479ed3cc56ccba5d07e08399a8016edb87901 (patch)
tree3f3e0411838a9b67cb0986d30168aed5fb2693f4 /ubifs-utils
parent0d862c5b7a787829eb43b4a9163358d3b727c0dd (diff)
mkfs.ubifs: Cleanup add_dent_node, user path encryption helper
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at> Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'ubifs-utils')
-rw-r--r--ubifs-utils/mkfs.ubifs/mkfs.ubifs.c55
1 files changed, 15 insertions, 40 deletions
diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
index 49a895a..ae1d267 100644
--- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
+++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
@@ -1703,53 +1703,28 @@ static int add_dent_node(ino_t dir_inum, const char *name, ino_t inum,
set_dent_cookie(dent);
if (!fctx) {
- dent_key_init(c, &key, dir_inum, dname.name, dname.len);
- dent->nlen = cpu_to_le16(dname.len);
- memcpy(dent->name, dname.name, dname.len);
- dent->name[dname.len] = '\0';
- len = UBIFS_DENT_NODE_SZ + dname.len + 1;
-
kname_len = dname.len;
kname = strdup(name);
if (!kname)
return err_msg("cannot allocate memory");
} else {
- void *inbuf, *outbuf, *crypt_key;
unsigned int max_namelen = type == UBIFS_ITYPE_LNK ? UBIFS_MAX_INO_DATA : UBIFS_MAX_NLEN;
- unsigned int padding = 4 << (fctx->flags & FS_POLICY_FLAGS_PAD_MASK);
- unsigned int cryptlen;
-
- cryptlen = max_t(unsigned int, dname.len, FS_CRYPTO_BLOCK_SIZE);
- cryptlen = round_up(cryptlen, padding);
- cryptlen = min(cryptlen, max_namelen);
-
- inbuf = xmalloc(cryptlen);
- /* CTS mode needs a block size aligned buffer */
- outbuf = xmalloc(round_up(cryptlen, FS_CRYPTO_BLOCK_SIZE));
-
- memset(inbuf, 0, cryptlen);
- memcpy(inbuf, dname.name, dname.len);
-
- crypt_key = calc_fscrypt_subkey(fctx);
- if (!crypt_key)
- return err_msg("could not compute subkey");
- if (encrypt_aes128_cbc_cts(inbuf, cryptlen, crypt_key, outbuf) < 0)
- return err_msg("could not encrypt filename");
-
- dent->nlen = cpu_to_le16(cryptlen);
- memcpy(dent->name, outbuf, cryptlen);
- dent->name[cryptlen] = '\0';
- len = UBIFS_DENT_NODE_SZ + cryptlen + 1;
-
- dent_key_init(c, &key, dir_inum, outbuf, cryptlen);
-
- kname_len = cryptlen;
- kname = xmalloc(cryptlen);
- memcpy(kname, outbuf, cryptlen);
- free(crypt_key);
- free(inbuf);
- free(outbuf);
+ int ret;
+
+ ret = encrypt_path((void **)&kname, dname.name, dname.len,
+ max_namelen, fctx);
+ if (ret < 0)
+ return ret;
+
+ kname_len = ret;
}
+
+ dent_key_init(c, &key, dir_inum, kname, kname_len);
+ dent->nlen = cpu_to_le16(kname_len);
+ memcpy(dent->name, kname, kname_len);
+ dent->name[kname_len] = '\0';
+ len = UBIFS_DENT_NODE_SZ + kname_len + 1;
+
key_write(&key, dent->key);
return add_node(&key, kname, kname_len, dent, len);