@@ -38,7 +38,10 @@ multitape_metaindex_fragname(const uint8_t namehash[32], uint32_t fragnum,
3838{
3939 uint8_t fragnum_le [4 ];
4040
41+ /* Use a platform-agnostic format for fragnum. */
4142 le32enc (fragnum_le , fragnum );
43+
44+ /* SHA256(namehash || fragnum). */
4245 if (crypto_hash_data_2 (CRYPTO_KEY_HMAC_SHA256 , namehash , 32 ,
4346 fragnum_le , 4 , fraghash )) {
4447 warn0 ("Programmer error: "
@@ -90,19 +93,21 @@ multitape_metaindex_put(STORAGE_W * S, CHUNKS_W * C,
9093 if ((p = buf = malloc (buflen )) == NULL )
9194 goto err0 ;
9295
93- /* Copy values into buffer. */
96+ /* Copy the header index into the buffer. */
9497 le32enc (p , (uint32_t )mind -> hindexlen );
9598 p += 4 ;
9699 if (mind -> hindexlen > 0 )
97100 memcpy (p , mind -> hindex , mind -> hindexlen );
98101 p += mind -> hindexlen ;
99102
103+ /* Copy the chunk index into the buffer. */
100104 le32enc (p , (uint32_t )mind -> cindexlen );
101105 p += 4 ;
102106 if (mind -> cindexlen > 0 )
103107 memcpy (p , mind -> cindex , mind -> cindexlen );
104108 p += mind -> cindexlen ;
105109
110+ /* Copy the trailer index into the buffer. */
106111 le32enc (p , (uint32_t )mind -> tindexlen );
107112 p += 4 ;
108113 if (mind -> tindexlen > 0 )
@@ -231,8 +236,11 @@ multitape_metaindex_get(STORAGE_R * S, CHUNKS_S * C,
231236 buf += 4 ;
232237 buflen -= 4 ;
233238
239+ /* Sanity check. */
234240 if (buflen < mind -> hindexlen )
235241 goto corrupt0 ;
242+
243+ /* Copy the header index into a new buffer. */
236244 if (((mind -> hindex = malloc (mind -> hindexlen )) == NULL ) &&
237245 (mind -> hindexlen > 0 ))
238246 goto err1 ;
@@ -248,8 +256,11 @@ multitape_metaindex_get(STORAGE_R * S, CHUNKS_S * C,
248256 buf += 4 ;
249257 buflen -= 4 ;
250258
259+ /* Sanity check. */
251260 if (buflen < mind -> cindexlen )
252261 goto corrupt1 ;
262+
263+ /* Copy the chunk index into a new buffer. */
253264 if (((mind -> cindex = malloc (mind -> cindexlen )) == NULL ) &&
254265 (mind -> cindexlen > 0 ))
255266 goto err2 ;
@@ -265,8 +276,11 @@ multitape_metaindex_get(STORAGE_R * S, CHUNKS_S * C,
265276 buf += 4 ;
266277 buflen -= 4 ;
267278
279+ /* Sanity check. */
268280 if (buflen < mind -> tindexlen )
269281 goto corrupt2 ;
282+
283+ /* Copy the trailer index into a new buffer. */
270284 if (((mind -> tindex = malloc (mind -> tindexlen )) == NULL ) &&
271285 (mind -> tindexlen > 0 ))
272286 goto err3 ;
@@ -275,6 +289,7 @@ multitape_metaindex_get(STORAGE_R * S, CHUNKS_S * C,
275289 buf += mind -> tindexlen ;
276290 buflen -= mind -> tindexlen ;
277291
292+ /* Sanity check. */
278293 if (buflen != 0 )
279294 goto corrupt3 ;
280295
@@ -331,6 +346,7 @@ multitape_metaindex_free(struct tapemetaindex * mind)
331346 if (mind == NULL )
332347 return ;
333348
349+ /* Clean up. */
334350 free (mind -> tindex );
335351 free (mind -> cindex );
336352 free (mind -> hindex );
@@ -351,6 +367,7 @@ multitape_metaindex_delete(STORAGE_D * S, CHUNKS_D * C,
351367 size_t fraglen ;
352368 uint8_t fraghash [32 ];
353369
370+ /* Compute the hash of the tape name. */
354371 if (crypto_hash_data (CRYPTO_KEY_HMAC_NAME ,
355372 (uint8_t * )mdat -> name , strlen (mdat -> name ), hbuf ))
356373 goto err0 ;
0 commit comments