From: David Oberhollenzer <david.oberhollenzer@xxxxxxxxxxxxx> Signed-off-by: David Oberhollenzer <david.oberhollenzer@xxxxxxxxxxxxx> Signed-off-by: Richard Weinberger <richard@xxxxxx> --- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 55 ++++++++--------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c index 49a895ae3682..ae1d26726deb 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); -- 2.19.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/