Skip to main content

rpdfium_parser/crypto/
mod.rs

1//! Low-level cryptographic primitives for PDF encryption.
2//!
3//! Split into three submodules mirroring the upstream `core/fdrm/` source layout:
4//! - [`fx_crypt`] — MD5, SHA-1, RC4, and [`CryptoError`]
5//! - [`fx_crypt_sha`] — SHA-256, SHA-384, SHA-512
6//! - [`fx_crypt_aes`] — AES-128/192/256-CBC and AES-256-ECB
7//!
8//! # RC4 manual implementation
9//!
10//! RC4 is implemented manually rather than using the `rc4` crate because that
11//! crate requires a compile-time fixed key length via a type parameter
12//! (`Rc4<U5>`, `Rc4<U16>`, etc.), which is incompatible with PDF encryption's
13//! variable-length keys (5-16 bytes for R2-R4, determined at runtime from
14//! the encryption dictionary).
15//!
16//! # SHA-1
17//!
18//! SHA-1 is used for digital signature verification (PKCS#7/CMS with
19//! `sha1WithRSAEncryption`) and some legacy PDF encryption extensions.
20//! Delegated to the RustCrypto `sha1` crate, matching the same delegation
21//! pattern as [`sha2`] for SHA-256/384/512.
22
23pub mod fx_crypt;
24pub mod fx_crypt_aes;
25pub mod fx_crypt_sha;
26
27pub use fx_crypt::{CryptoError, md5, rc4_crypt, sha1};
28pub use fx_crypt_aes::{
29    aes128_cbc_decrypt, aes128_cbc_encrypt, aes128_cbc_encrypt_no_padding, aes192_cbc_decrypt,
30    aes192_cbc_encrypt, aes256_cbc_decrypt, aes256_cbc_decrypt_no_padding, aes256_cbc_encrypt,
31    aes256_cbc_encrypt_no_padding, aes256_ecb_decrypt_block,
32};
33pub use fx_crypt_sha::{sha256, sha384, sha512};