Skip to content

The footer

Worked example: footer revision 4 file

The footer is the last 96 bytes of the file, at offsets 0x1FA0 to 0x2000. It is a sealed region: 64 bytes of ciphertext followed by the 32-byte seal trailer. The AAD is "stc" ‖ 0x03 ‖ file_id u64 ‖ 0u32, 16 bytes in all.

The last 32 bytes:

tag : 16 bytes ending ... 2e 78 8c 7c 07 4a
nonce : 01 00 00 00 | 05 00 00 00 00 00 00 00 epoch 1, counter 5
key id: 01 00 00 00 data key 1

The first 64 bytes of the footer are ciphertext, beginning 95 ed 26 e5 ac 33 aa 0d .... A reader looks up data key 1 in the keyring, decrypts, and checks the tag.

Footer plaintext, 64 bytes
  1. magic4 B"STC1"
  2. version2 B4
  3. layer1 B1 hot/row
  4. flags1 B0x07
  5. file_id8 B1
  6. bloom_off8 B3872
  7. bloom_len4 B684
  8. index_off8 B4611
  9. index_len4 B89
  10. entries8 B1000
  11. min_ts8 B7
  12. max_ts8 B7
53 54 43 31 04 00 01 07 "STC1", version 4, layer 1, flags 0x07 (STATS|SKIP|RANGES)
01 00 00 00 00 00 00 00 file_id 1
20 0f 00 00 00 00 00 00 bloom_off 3872
ac 02 00 00 bloom_len 684
03 12 00 00 00 00 00 00 index_off 4611
59 00 00 00 index_len 89
e8 03 00 00 00 00 00 00 entries 1000
07 00 00 00 00 00 00 00 min_ts 7
07 00 00 00 00 00 00 00 max_ts 7

Footer revision 4 with SKIP and RANGES set and COUNTS clear is legal: this file predates footer revision 5. See Footer revision 4 and Footer flags.

Check Arithmetic
file_id equals the id in the name 1 and 0000000000000001.stc
Bloom inside the file 3872 + 684 = 4556, at most 8192 - 96 = 8096
Index inside the file 4611 + 89 = 4700, at most 8096
Index after bloom 4611 >= 3872
Stats frame, when STATS is set [3872 + 684, 4611) = [4556, 4611), 55 bytes

Zero padding from 4700 to 8096 (3396 bytes) makes the file 8192 bytes, a multiple of 4096.