Skip to content

Re-architect fused AEAD subsystem into an open cipher-kernel framework#142

Merged
Xor-el merged 4 commits into
masterfrom
refactor/accelerated-framework
Jul 10, 2026
Merged

Re-architect fused AEAD subsystem into an open cipher-kernel framework#142
Xor-el merged 4 commits into
masterfrom
refactor/accelerated-framework

Conversation

@Xor-el

@Xor-el Xor-el commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

This PR replaces the closed fused-kernel registry with an extensible cipher-kernel framework: a single priority-ordered registry where in-tree SIMD kernels and external plug-ins register through the same API.
Framework re-architecture

  • Relocate Crypto/Modes/FusedCrypto/CipherKernels (block AEADs are not "modes"); shared SIMD asm include depth is unchanged
  • Replace the monolithic ClpFusedKernelRegistry with TCipherKernelRegistry, TCipherKernelGate, and TCipherKernelFactoryBase
  • Open registry: one Supports-filtered, priority-sorted factory list; external consumers register ICipherKernelFactory implementations with zero framework edits
  • Priority ladder: Fallback < Baseline < Preferred < UserOverride (equal priorities keep registration order)
  • TCipherKernelGate.ForceDisabled kill-switch routes all modes through scalar fallbacks for dual-path parity testing
    Contracts and naming
  • Per-mode contracts drop the long prefix: IGcmKernel, IOcbKernel, ICcmKernel, IEaxKernel, IGcmSivKernel, ICtrKernel, ICbcKernel
  • Hub interface: ICipherKernelFactory (shared registration/discovery surface)
  • Genuinely fused implementation artifacts keep their names (ClpAesFusedAeadSimd, ClpAesNiFusedX86Backend, fused asm includes)
    Compact public API
  • Delete 16 redundant per-mode Register* / Unregister* wrappers; in-tree init and tests call generic Register / Unregister (same API external plug-ins use)
  • Collapse 8 GetRegistered*Providers into one GetRegisteredProviders(const AFactoryIID: TGUID)
  • Keep 8 typed TryAcquire* methods (signatures genuinely diverge: AHPowers for GCM/GCM-SIV, IStreamCipher for ChaCha20-Poly1305)
    Mode integration
  • Wire block modes through the new registry: CBC, CCM, CTR (SIC), EAX, GCM, GCM-SIV, OCB
  • Add inert stream seam: IChaCha20Poly1305Kernel + TryAcquireChaCha20Poly1305; TChaCha20Poly1305 resolves at init (nil today → two-pass, byte-identical)
    Tests
  • Rename FusedKernelToggleCipherKernelToggle; RunWithFusedToggleRunWithCipherKernelToggle
  • Rename FusedExternalRegistrationTestsCipherKernelExternalRegistrationTests (4 registration contract tests)
  • Update AEAD suites (CCM, EAX, GCM, GCM-SIV, OCB) to use the new toggle helper

Xor-el added 4 commits July 10, 2026 05:39
…mework

Rename the "fused kernel" framework to "accelerated kernel" so the contract
names the capability, not the mechanism (fusion) - a non-fused-but-accelerated
kernel can now register without lying. Genuinely-fused impl artifacts keep
"Fused" (the SIMD asm, ClpAesFusedAeadSimd, backend).

- Relocate Crypto/Modes/Fused -> Crypto/Accelerated (block AEADs aren't
  "modes"); kernels stay at their original include depth so shared SIMD asm
  {$I} includes are untouched.
- Open registry: one Supports-filtered list + public GetSnapshot; per-mode
  TryAcquireX wrappers; no enum - external consumers register their own
  IAccelerated<X>KernelFactory with zero framework edits.
- Contracts IFused<Mode>Kernel -> IAccelerated<Mode>Kernel.
  TAcceleratedKernelFactoryBase.ProviderName is abstract; Priority defaults to
  Baseline. Priority ladder: Fallback < Baseline < Preferred < UserOverride.
- Inert stream seam: IAcceleratedChaCha20Poly1305Kernel + registry hook +
  resolve-at-Init in ClpChaCha20Poly1305 (nil today -> two-pass, byte-identical).
- Tests: RunWithFusedToggle -> RunWithAcceleratedToggle; FusedExternalRegistration
  Tests -> AcceleratedExternalRegistrationTests.
The 16 Register*/Unregister*Factory wrappers were one-line pass-throughs to
the generic Register/Unregister - redundant, since every IAccelerated<Mode>
KernelFactory already descends IAcceleratedKernelFactory and upcasts to the
base-typed parameter. 7 of 8 Unregister wrappers and 7 of 8 GetRegistered*
Providers had no callers at all.

- Delete the 16 Register*/Unregister*Factory wrappers; in-tree initialization
  blocks and the contract test now call the generic Register/Unregister - the
  same public API an external plugin uses (dogfoods the extensibility path).
- Collapse the 8 GetRegistered*Providers into one
  GetRegisteredProviders(const AFactoryIID: TGUID); pass a factory interface,
  e.g. GetRegisteredProviders(IAcceleratedGcmKernelFactory) - the same
  interface-to-GUID substitution the TryAcquire* Supports() calls already use.
- Keep the 8 typed TryAcquire* (their TryCreate signatures genuinely diverge:
  AHPowers for GCM/GCM-SIV, IStreamCipher for ChaCha20-Poly1305).
The framework hosts only cipher (AEAD + mode) kernels, but "Accelerated"
didn't say so and the per-mode names were long. Put the domain word on the
shared hub and let the concrete contracts be bare - the cipher scope reads
through the inheritance without repeating it.

- Hub: TAcceleratedKernel{Registry,Gate,Priority,Direction,FactoryBase} and
  IAcceleratedKernelFactory -> TCipherKernel* / ICipherKernelFactory.
- Per-mode: IAccelerated<Mode>Kernel(Factory) -> I<Mode>Kernel(Factory), e.g.
  IGcmKernel, IChaCha20Poly1305Kernel. Each descends ICipherKernelFactory, so
  "a GCM kernel, which is a cipher-kernel" needs no prefix (and it's shorter:
  IChaCha20Poly1305Kernel is 23 chars vs 34).
- Folder Crypto/Accelerated -> Crypto/CipherKernels (same depth, so the shared
  SIMD nested-include constraint is untouched).
- Tests: RunWithAcceleratedToggle -> RunWithCipherKernelToggle;
  AcceleratedExternalRegistrationTests -> CipherKernelExternalRegistrationTests.

Genuinely-fused impl artifacts keep their names (ClpAesFusedAeadSimd,
ClpAesNiFusedX86Backend, the *Fused* asm). Prose "accelerated" was rebranded
only where it named the framework; nature descriptions (hardware-accelerated
engine, SIMD-accelerated bulk path) stay.
@Xor-el Xor-el merged commit 15956b4 into master Jul 10, 2026
24 checks passed
@Xor-el Xor-el deleted the refactor/accelerated-framework branch July 10, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant