PDFium Delphi Component Docs

FPdfSha256 unit

Unit: FPdfSha256
Pure-Pascal SHA-256 implementation with incremental init/update/final context and one-shot helpers, provided because Free Pascal ships no SHA-2 unit

Syntax

TSHA256Digest = array[0..31] of Byte;

TSHA256Context = record
  State: array[0..7] of Cardinal;
  Buffer: array[0..63] of Byte;
  BufCnt: Cardinal;
  Length: UInt64;
end;

procedure SHA256Init(out Ctx: TSHA256Context);
procedure SHA256Update(var Ctx: TSHA256Context; const Buf; BufLen: Cardinal);
procedure SHA256Final(var Ctx: TSHA256Context; out Digest: TSHA256Digest);
function SHA256Bytes(const B: TBytes): TSHA256Digest;
function SHA256Of(const Buf; BufLen: Cardinal): TSHA256Digest;
function SHA256Hex(const Digest: TSHA256Digest): string;

Description

FPdfSha256 is the SHA-256 hash implementation used throughout the PDFium Delphi Component signing and encryption stack. It is required because Free Pascal does not ship a SHA-2 unit, and bundling it keeps the library dependency-free on all supported compilers

The incremental SHA256Init / SHA256Update / SHA256Final API hashes data larger than memory or streamed in chunks. SHA256Bytes and SHA256Of are one-shot helpers over a byte array or an untyped buffer, and SHA256Hex formats a digest as a lowercase 64-character hex string

The TSHA256Digest type is consumed by FPdfCms, FPdfTsa, and FPdfCryptoWin as the digest shape for signed-attribute hashing

Functions

FunctionDescription
SHA256InitInitialises a hashing context
SHA256UpdateFeeds an untyped buffer into an open context
SHA256FinalFinalises the context and returns the 32-byte digest
SHA256BytesOne-shot hash of a byte array
SHA256OfOne-shot hash of an untyped buffer of a given length
SHA256HexFormats a digest as a lowercase hex string

Types

TypeDescription
TSHA256Digest32-byte SHA-256 digest consumed by the CMS, TSA, and crypto units
TSHA256ContextIncremental hashing context holding the working state, message block buffer, byte count, and total length

TSHA256Context fields

FieldDescription
StateEight 32-bit working words that accumulate the hash; SHA256Init loads the FIPS 180-4 initial values, every absorbed 64-byte block updates them, and SHA256Final emits them big-endian as the digest
BufferStaging area holding the bytes of the current incomplete 64-byte message block between SHA256Update calls
BufCntNumber of message bytes currently staged in Buffer, ranging from 0 to 63
LengthTotal number of message bytes absorbed so far; SHA256Final converts it to a bit count for the 64-bit big-endian length trailer

See Also

FPdfSha512, FPdfCms, FPdfEncrypt