PDFium Delphi Component Docs

FPdfSha3 unit

Unit: FPdfSha3
Dependency-free SHA3-256, SHA3-384, SHA3-512, and SHAKE256 with incremental absorption, one-shot helpers, and continuous XOF output

Syntax

TSha3Algorithm = (s3aSha3_256, s3aSha3_384, s3aSha3_512, s3aShake256);
TSha3Digest256 = array[0..31] of Byte;
TSha3Digest384 = array[0..47] of Byte;
TSha3Digest512 = array[0..63] of Byte;

TSha3Context = record
  State: array[0..24] of UInt64;
  Buffer: array[0..135] of Byte;
  BufferLength: Integer;
  Rate: Integer;
  SqueezeOffset: Integer;
  Algorithm: TSha3Algorithm;
  Finalized: Boolean;
end;

procedure Sha3_256Init(out Ctx: TSha3Context);
procedure Sha3_384Init(out Ctx: TSha3Context);
procedure Sha3_512Init(out Ctx: TSha3Context);
procedure Shake256Init(out Ctx: TSha3Context);
procedure Sha3Update(var Ctx: TSha3Context; const Data; DataLength: Integer);
procedure Sha3_256Final(var Ctx: TSha3Context; out Digest: TSha3Digest256);
procedure Sha3_384Final(var Ctx: TSha3Context; out Digest: TSha3Digest384);
procedure Sha3_512Final(var Ctx: TSha3Context; out Digest: TSha3Digest512);
procedure Shake256Final(var Ctx: TSha3Context);
procedure Shake256Squeeze(var Ctx: TSha3Context; out Output; OutputLength: Integer);
function Shake256Bytes(const Data: TBytes; OutputLength: Integer): TBytes;

Description

FPdfSha3 implements the FIPS 202 SHA-3 family needed by ISO/TS 32001 and related PDF 2.x cryptographic extensions without requiring an operating-system crypto provider

Fixed-output hashes share one context type and algorithm-checked finalizers, while SHAKE256 separates final absorption from output so callers can request any length across one or more Shake256Squeeze calls

Functions

FunctionDescription
Sha3_256Init, Sha3_384Init, Sha3_512InitInitialize a fixed-output SHA-3 context
Shake256InitInitializes a SHAKE256 extendable-output context
Sha3UpdateAbsorbs an untyped input buffer into any initialized context
Sha3_256Final, Sha3_384Final, Sha3_512FinalFinalize a matching context and return its fixed-length digest
Shake256FinalFinalizes SHAKE256 absorption without consuming output
Shake256SqueezeContinues SHAKE256 output from the current offset across repeated calls
Sha3_256Bytes, Sha3_384Bytes, Sha3_512BytesHash a byte array in one call
Shake256BytesReturns a caller-selected number of SHAKE256 output bytes
Sha3_256Hex, Sha3_384Hex, Sha3_512HexConvert a fixed digest to lowercase hexadecimal text

Types

TypeDescription
TSha3AlgorithmSelects the algorithm configured into a context: s3aSha3_256, s3aSha3_384, and s3aSha3_512 choose a fixed-output SHA-3 hash with its digest size, while s3aShake256 chooses the extendable-output function
TSha3Digest256, TSha3Digest384, TSha3Digest512Fixed-size digest buffers
TSha3ContextIncremental sponge state, rate buffer, algorithm, and squeeze offset
ESha3ErrorReports invalid lengths, lifecycle misuse, or mismatched finalizers

TSha3Context fields

FieldDescription
StateThe 1600-bit Keccak-f[1600] sponge state as 25 64-bit lanes; absorbed bytes are XORed into the leading lanes and squeezed output bytes are read back out of them
BufferStaging area for input bytes that have not yet filled a complete rate block; 136 entries cover the largest supported rate
BufferLengthNumber of input bytes currently staged in Buffer
RateSponge rate in bytes, fixed by the initializer: 136 for s3aSha3_256 and s3aShake256, 104 for s3aSha3_384, and 72 for s3aSha3_512
SqueezeOffsetRead position inside the current squeeze block; once it reaches Rate the next Keccak-f[1600] permutation produces a fresh output block
AlgorithmThe TSha3Algorithm value the context was configured with; finalizers verify it matches before emitting output
FinalizedSet once domain padding has been absorbed; further Sha3Update calls on a finalized context raise ESha3Error

Remarks

See Also

FPdfSha256 | FPdfSha512