]> www.infradead.org Git - mtd-utils.git/commitdiff
mkfs.ubifs: Replace constant values with parameters in init_fscrypt_context
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 18 Oct 2018 14:36:58 +0000 (16:36 +0200)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 1 Nov 2018 11:40:08 +0000 (12:40 +0100)
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Signed-off-by: Richard Weinberger <richard@nod.at>
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c

index ae1d26726deb3b7267cd8c04ae380d92618c0134..8be84ca1e99cce38784bc89eea401c9ff726af71 100644 (file)
@@ -581,16 +581,20 @@ static void print_fscrypt_master_key_descriptor(struct fscrypt_context *fctx)
        normsg("");
 }
 
-static struct fscrypt_context *init_fscrypt_context(void)
+static struct fscrypt_context *init_fscrypt_context(unsigned int flags,
+                                               void *master_key_descriptor,
+                                               void *nonce)
 {
        struct fscrypt_context *new_fctx = xmalloc(sizeof(*new_fctx));
 
        new_fctx->format = FS_ENCRYPTION_CONTEXT_FORMAT_V1;
        new_fctx->contents_encryption_mode = FS_ENCRYPTION_MODE_AES_128_CBC;
        new_fctx->filenames_encryption_mode = FS_ENCRYPTION_MODE_AES_128_CTS;
-       new_fctx->flags = FS_POLICY_FLAGS_PAD_4;
-       RAND_bytes((void *)&new_fctx->nonce, FS_KEY_DERIVATION_NONCE_SIZE);
+       new_fctx->flags = flags;
 
+       memcpy(&new_fctx->nonce, nonce, FS_KEY_DERIVATION_NONCE_SIZE);
+       memcpy(&new_fctx->master_key_descriptor, master_key_descriptor,
+               FS_KEY_DESCRIPTOR_SIZE);
        return new_fctx;
 }
 
@@ -2779,6 +2783,8 @@ static int close_target(void)
  */
 static int init(void)
 {
+       __u8 master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
+       __u8 nonce[FS_KEY_DERIVATION_NONCE_SIZE];
        int err, i, main_lebs, big_lpt = 0, sz;
 
        c->highest_inum = UBIFS_FIRST_INO;
@@ -2821,7 +2827,11 @@ static int init(void)
        hash_table = xzalloc(sz);
 
        //TODO make this a parameter
-       root_fctx = init_fscrypt_context();
+       RAND_bytes((void *)master_key_descriptor, FS_KEY_DESCRIPTOR_SIZE);
+       RAND_bytes((void *)nonce, FS_KEY_DERIVATION_NONCE_SIZE);
+
+       root_fctx = init_fscrypt_context(FS_POLICY_FLAGS_PAD_4,
+                                       master_key_descriptor, nonce);
        print_fscrypt_master_key_descriptor(root_fctx);
        c->double_hash = 1;
        c->encrypted = 1;