PDFium Delphi Component Docs

FPdfMac unit

Unit: FPdfMac
Builds and verifies CMS AuthenticatedData tokens for standalone and signature-attached ISO/TS 32004 PDF authentication codes

Syntax

function BuildStandalonePdfMacToken(const FileEncryptionKey, KdfSalt,
  DataDigest: TBytes): TBytes;
function VerifyStandalonePdfMacToken(const Token, FileEncryptionKey,
  KdfSalt, ExpectedDataDigest: TBytes;
  out ErrorText: string): Boolean;
function BuildAttachedPdfMacToken(const FileEncryptionKey, KdfSalt,
  DataDigest, SignatureDigest: TBytes; SignatureObjectNumber,
  SignatureGeneration: Integer): TBytes;
function VerifyAttachedPdfMacToken(const Token, FileEncryptionKey, KdfSalt,
  ExpectedDataDigest, ExpectedSignatureDigest: TBytes;
  SignatureObjectNumber, SignatureGeneration: Integer;
  out ErrorText: string): Boolean;

Description

The builder derives an AES-256 key-encryption key from the 32-byte file encryption key and /KDFSalt with HKDF-SHA256 and the UTF-8 info value PDFMAC

A random 256-bit MAC key is wrapped with RFC 3394 AES-256 Key Wrap and emitted in the single PasswordRecipientInfo required by ISO/TS 32004

The token embeds a version-zero PdfMacIntegrityInfo, the required authenticated attributes, CMSAlgorithmProtection, and an HMAC-SHA256 value over the canonical DER SET encoding of the attributes

The caller owns PDF serialisation and supplies the SHA-256 digest of the exact /ByteRange segments; application code normally uses TPdfEncryptOptions.EnableIntegrityProtection and TPdf.ValidatePdfMac

Attached tokens bind the data digest to a signature digest and the signature object number and generation before building or verifying the same authenticated token format

Functions

FunctionDescription
BuildStandalonePdfMacTokenBuilds a standalone AuthenticatedData token from 32-byte file-encryption key, KDF salt, and data digest values
VerifyStandalonePdfMacTokenValidates canonical DER, algorithms, attributes, wrapped key, expected data digest, and HMAC in constant time where secret values are compared
BuildAttachedPdfMacTokenBuilds an attached token by hashing the data digest, signature digest, signature object number, and signature generation into the bound integrity digest
VerifyAttachedPdfMacTokenRebuilds the attached binding digest from the expected signature context and verifies the resulting token

Current scope

The implementation supports standalone and signature-attached authentication codes, SHA-256 data and signature digests, HMAC-SHA256, AES-256 Key Wrap, and 32-byte Standard Security Handler file keys

Public-key security handlers and alternative digest algorithms are not generated

See Also

FPdfHmac, FPdfAes, FPdfEncrypt, TPdf.ValidatePdfMac