Skip to main content

Module crypto

Module crypto 

Source
Expand description

The standard security handler, revisions 2–6 (§7.6).

What is read, and which algorithms carry it:

/V/RCipherKey derivationPassword check
12RC4, 40 bitAlgorithm 2 (MD5)Algorithm 4
23RC4, 40–128 bitAlgorithm 2, 50 roundsAlgorithm 5
44RC4 (/V2) or AES-128 (/AESV2)as /R 3Algorithm 5
56AES-256 (/AESV3)Algorithm 2.BAlgorithm 2.A

Two structures differ between the generations and are worth stating:

  • Revisions 2–4 derive a per-object key from the file key, the object number and its generation (Algorithm 1), which is why a string or stream from those revisions cannot be decrypted without knowing which object it came from. Revisions 5 and 6 use the file key directly.
  • Revision 6 verification is Algorithm 2.B — a 64-round minimum key stretch over SHA-256/384/512 and AES-128-CBC — implemented in hash_r6, while revisions 2–4 use MD5, implemented here rather than pulled in as a dependency: it is 100 lines, needs no std, and its only use is key derivation for files that predate PDF 2.0.

/R 5 is refused: it is the deprecated draft of revision 6 and no file in the corpus uses it.

Structs§

Encryption
The standard security handler for one document.

Constants§

KEY_LENGTH
Length of the file key, and of the AES key, for /V 5.

Functions§

hash_r6
Algorithm 2.B: the revision 6 password hash.