@@ -87,6 +87,7 @@ static int create_default_filesystem(struct ubifs_info *c)
87
87
__le64 tmp_le64 ;
88
88
__le32 tmp_le32 ;
89
89
struct timespec64 ts ;
90
+ u8 hash [UBIFS_HASH_ARR_SZ ];
90
91
u8 hash_lpt [UBIFS_HASH_ARR_SZ ];
91
92
92
93
/* Some functions called from here depend on the @c->key_len filed */
@@ -177,6 +178,16 @@ static int create_default_filesystem(struct ubifs_info *c)
177
178
sup_flags |= UBIFS_FLG_BIGLPT ;
178
179
sup_flags |= UBIFS_FLG_DOUBLE_HASH ;
179
180
181
+ if (ubifs_authenticated (c )) {
182
+ sup_flags |= UBIFS_FLG_AUTHENTICATION ;
183
+ sup -> hash_algo = cpu_to_le16 (c -> auth_hash_algo );
184
+ err = ubifs_hmac_wkm (c , sup -> hmac_wkm );
185
+ if (err )
186
+ goto out ;
187
+ } else {
188
+ sup -> hash_algo = 0xffff ;
189
+ }
190
+
180
191
sup -> ch .node_type = UBIFS_SB_NODE ;
181
192
sup -> key_hash = UBIFS_KEY_HASH_R5 ;
182
193
sup -> flags = cpu_to_le32 (sup_flags );
@@ -235,6 +246,7 @@ static int create_default_filesystem(struct ubifs_info *c)
235
246
mst -> empty_lebs = cpu_to_le32 (main_lebs - 2 );
236
247
mst -> idx_lebs = cpu_to_le32 (1 );
237
248
mst -> leb_cnt = cpu_to_le32 (c -> leb_cnt );
249
+ ubifs_copy_hash (c , hash_lpt , mst -> hash_lpt );
238
250
239
251
/* Calculate lprops statistics */
240
252
tmp64 = main_bytes ;
@@ -307,25 +319,33 @@ static int create_default_filesystem(struct ubifs_info *c)
307
319
308
320
cs -> ch .node_type = UBIFS_CS_NODE ;
309
321
310
- err = ubifs_write_node (c , sup , UBIFS_SB_NODE_SZ , 0 , 0 );
322
+ err = ubifs_write_node_hmac (c , sup , UBIFS_SB_NODE_SZ , 0 , 0 ,
323
+ offsetof(struct ubifs_sb_node , hmac ));
311
324
if (err )
312
325
goto out ;
313
326
314
- err = ubifs_write_node (c , mst , UBIFS_MST_NODE_SZ , UBIFS_MST_LNUM , 0 );
327
+ err = ubifs_write_node (c , ino , UBIFS_INO_NODE_SZ ,
328
+ main_first + DEFAULT_DATA_LEB , 0 );
315
329
if (err )
316
330
goto out ;
317
331
318
- err = ubifs_write_node (c , mst , UBIFS_MST_NODE_SZ , UBIFS_MST_LNUM + 1 ,
319
- 0 );
332
+ ubifs_node_calc_hash (c , ino , hash );
333
+ ubifs_copy_hash (c , hash , ubifs_branch_hash (c , br ));
334
+
335
+ err = ubifs_write_node (c , idx , idx_node_size , main_first + DEFAULT_IDX_LEB , 0 );
320
336
if (err )
321
337
goto out ;
322
338
323
- err = ubifs_write_node (c , idx , idx_node_size , main_first + DEFAULT_IDX_LEB , 0 );
339
+ ubifs_node_calc_hash (c , idx , hash );
340
+ ubifs_copy_hash (c , hash , mst -> hash_root_idx );
341
+
342
+ err = ubifs_write_node_hmac (c , mst , UBIFS_MST_NODE_SZ , UBIFS_MST_LNUM , 0 ,
343
+ offsetof(struct ubifs_mst_node , hmac ));
324
344
if (err )
325
345
goto out ;
326
346
327
- err = ubifs_write_node (c , ino , UBIFS_INO_NODE_SZ ,
328
- main_first + DEFAULT_DATA_LEB , 0 );
347
+ err = ubifs_write_node_hmac (c , mst , UBIFS_MST_NODE_SZ , UBIFS_MST_LNUM + 1 ,
348
+ 0 , offsetof( struct ubifs_mst_node , hmac ) );
329
349
if (err )
330
350
goto out ;
331
351
0 commit comments