encryptionBlockAad.php
Table of Contents
Functions
- encryptionBlockAad() : string
- Builds the associated data that binds one V3 block to its file, its position and the end of the stream.
Functions
encryptionBlockAad()
Builds the associated data that binds one V3 block to its file, its position and the end of the stream.
encryptionBlockAad(string $header, int $index, bool $isFinal) : string
AAD(i) = header (31 bytes) ‖ pack('N', i) (4 bytes) ‖ chr( isFinal ? 1 : 0 ) (1 byte)
This function is the integrity of the format. A GCM tag proves that a block was sealed with the key — nothing more. Seal each block with no associated data and every frame authenticates on its own, which leaves four rewrites of a file undetectable, all of them trivial to perform with no key at all:
| Attack | What stops it |
|---|---|
| Cut the file short | the final flag: the reader computes final from the cursor, so the new last frame was sealed as non-final and fails |
| Swap two frames | the block index |
| Drop a frame from the middle | the block index of every frame after it |
| Splice two files from the same passphrase | the header, whose salt and nonce prefix are per-file |
The flag is one byte rather than a bit of the index because it has to be decided on the read side, from the cursor position against the file size, before the block is opened. Writer and reader must agree on it, and that agreement is what a truncation breaks.
Parameters
- $header : string
-
The file's V3 header, exactly EncryptionFormat::V3_HEADER_LENGTH bytes.
- $index : int
-
The zero-based block index.
- $isFinal : bool
-
Whether this block is the last of the file.
Tags
Return values
string —The associated data to pass to openssl_encrypt() / openssl_decrypt().