diff --git a/CryptoLib.Benchmark/Delphi/CryptoLib.BenchmarkConsole.dpr b/CryptoLib.Benchmark/Delphi/CryptoLib.BenchmarkConsole.dpr index ad1ad510..e975cc22 100644 --- a/CryptoLib.Benchmark/Delphi/CryptoLib.BenchmarkConsole.dpr +++ b/CryptoLib.Benchmark/Delphi/CryptoLib.BenchmarkConsole.dpr @@ -686,26 +686,31 @@ uses ClpEaxBlockCipher in '..\..\CryptoLib\src\Crypto\Modes\ClpEaxBlockCipher.pas', ClpOcbBlockCipher in '..\..\CryptoLib\src\Crypto\Modes\ClpOcbBlockCipher.pas', ClpGcmSivUtilities in '..\..\CryptoLib\src\Crypto\Modes\Gcm\ClpGcmSivUtilities.pas', - ClpFusedKernelTypes in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpFusedKernelTypes.pas', - ClpIFusedGcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedGcmKernel.pas', - ClpIFusedOcbKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedOcbKernel.pas', - ClpIFusedCcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedCcmKernel.pas', - ClpIFusedEaxKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedEaxKernel.pas', - ClpIFusedGcmSivKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedGcmSivKernel.pas', - ClpIFusedCtrKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedCtrKernel.pas', - ClpIFusedCbcKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedCbcKernel.pas', - ClpFusedKernelRegistry in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpFusedKernelRegistry.pas', - ClpAesFusedAeadSimd in '..\..\CryptoLib\src\Crypto\Modes\Fused\Internal\ClpAesFusedAeadSimd.pas', - ClpAesNiFusedX86Backend in '..\..\CryptoLib\src\Crypto\Modes\Fused\Internal\ClpAesNiFusedX86Backend.pas', + ClpCipherKernelTypes in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelTypes.pas', + ClpICipherKernelFactory in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\ClpICipherKernelFactory.pas', + + ClpIChaCha20Poly1305Kernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Stream\ClpIChaCha20Poly1305Kernel.pas', + ClpIGcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIGcmKernel.pas', + ClpIOcbKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIOcbKernel.pas', + ClpICcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpICcmKernel.pas', + ClpIEaxKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIEaxKernel.pas', + ClpIGcmSivKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIGcmSivKernel.pas', + ClpICtrKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpICtrKernel.pas', + ClpICbcKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpICbcKernel.pas', + ClpCipherKernelRegistry in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelRegistry.pas', + + ClpCipherKernelFactoryBase in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelFactoryBase.pas', + ClpAesFusedAeadSimd in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\Internal\ClpAesFusedAeadSimd.pas', + ClpAesNiFusedX86Backend in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\Internal\ClpAesNiFusedX86Backend.pas', ClpBinPolySimd in '..\..\CryptoLib\src\Math\BinPoly\ClpBinPolySimd.pas', - ClpAesNiOcbKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiOcbKernel.pas', - ClpAesNiCcmKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiCcmKernel.pas', - ClpAesNiEaxKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiEaxKernel.pas', - ClpAesNiGcmKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiGcmKernel.pas', - ClpAesNiCtrKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiCtrKernel.pas', - ClpAesNiCbcKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiCbcKernel.pas', - ClpPclmulGcmSivKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpPclmulGcmSivKernel.pas', - ClpFusedKernelDefaults in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpFusedKernelDefaults.pas', + ClpAesNiOcbKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiOcbKernel.pas', + ClpAesNiCcmKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiCcmKernel.pas', + ClpAesNiEaxKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiEaxKernel.pas', + ClpAesNiGcmKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiGcmKernel.pas', + ClpAesNiCtrKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiCtrKernel.pas', + ClpAesNiCbcKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiCbcKernel.pas', + ClpPclmulGcmSivKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpPclmulGcmSivKernel.pas', + ClpCipherKernelDefaults in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelDefaults.pas', ClpAeadParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpAeadParameters.pas', ClpBufferedAeadCipher in '..\..\CryptoLib\src\Crypto\ClpBufferedAeadCipher.pas', ClpBufferedAeadBlockCipher in '..\..\CryptoLib\src\Crypto\ClpBufferedAeadBlockCipher.pas', diff --git a/CryptoLib.Examples/Delphi.Examples/CryptoLib.Examples.dpr b/CryptoLib.Examples/Delphi.Examples/CryptoLib.Examples.dpr index a0be813e..cefdab5f 100644 --- a/CryptoLib.Examples/Delphi.Examples/CryptoLib.Examples.dpr +++ b/CryptoLib.Examples/Delphi.Examples/CryptoLib.Examples.dpr @@ -702,26 +702,31 @@ uses ClpEaxBlockCipher in '..\..\CryptoLib\src\Crypto\Modes\ClpEaxBlockCipher.pas', ClpOcbBlockCipher in '..\..\CryptoLib\src\Crypto\Modes\ClpOcbBlockCipher.pas', ClpGcmSivUtilities in '..\..\CryptoLib\src\Crypto\Modes\Gcm\ClpGcmSivUtilities.pas', - ClpFusedKernelTypes in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpFusedKernelTypes.pas', - ClpIFusedGcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedGcmKernel.pas', - ClpIFusedOcbKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedOcbKernel.pas', - ClpIFusedCcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedCcmKernel.pas', - ClpIFusedEaxKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedEaxKernel.pas', - ClpIFusedGcmSivKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedGcmSivKernel.pas', - ClpIFusedCtrKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedCtrKernel.pas', - ClpIFusedCbcKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedCbcKernel.pas', - ClpFusedKernelRegistry in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpFusedKernelRegistry.pas', - ClpAesFusedAeadSimd in '..\..\CryptoLib\src\Crypto\Modes\Fused\Internal\ClpAesFusedAeadSimd.pas', - ClpAesNiFusedX86Backend in '..\..\CryptoLib\src\Crypto\Modes\Fused\Internal\ClpAesNiFusedX86Backend.pas', + ClpCipherKernelTypes in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelTypes.pas', + ClpICipherKernelFactory in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\ClpICipherKernelFactory.pas', + + ClpIChaCha20Poly1305Kernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Stream\ClpIChaCha20Poly1305Kernel.pas', + ClpIGcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIGcmKernel.pas', + ClpIOcbKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIOcbKernel.pas', + ClpICcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpICcmKernel.pas', + ClpIEaxKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIEaxKernel.pas', + ClpIGcmSivKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIGcmSivKernel.pas', + ClpICtrKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpICtrKernel.pas', + ClpICbcKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpICbcKernel.pas', + ClpCipherKernelRegistry in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelRegistry.pas', + + ClpCipherKernelFactoryBase in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelFactoryBase.pas', + ClpAesFusedAeadSimd in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\Internal\ClpAesFusedAeadSimd.pas', + ClpAesNiFusedX86Backend in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\Internal\ClpAesNiFusedX86Backend.pas', ClpBinPolySimd in '..\..\CryptoLib\src\Math\BinPoly\ClpBinPolySimd.pas', - ClpAesNiOcbKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiOcbKernel.pas', - ClpAesNiCcmKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiCcmKernel.pas', - ClpAesNiEaxKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiEaxKernel.pas', - ClpAesNiGcmKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiGcmKernel.pas', - ClpAesNiCtrKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiCtrKernel.pas', - ClpAesNiCbcKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiCbcKernel.pas', - ClpPclmulGcmSivKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpPclmulGcmSivKernel.pas', - ClpFusedKernelDefaults in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpFusedKernelDefaults.pas', + ClpAesNiOcbKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiOcbKernel.pas', + ClpAesNiCcmKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiCcmKernel.pas', + ClpAesNiEaxKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiEaxKernel.pas', + ClpAesNiGcmKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiGcmKernel.pas', + ClpAesNiCtrKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiCtrKernel.pas', + ClpAesNiCbcKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiCbcKernel.pas', + ClpPclmulGcmSivKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpPclmulGcmSivKernel.pas', + ClpCipherKernelDefaults in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelDefaults.pas', ClpAeadParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpAeadParameters.pas', ClpBufferedAeadCipher in '..\..\CryptoLib\src\Crypto\ClpBufferedAeadCipher.pas', ClpBufferedAeadBlockCipher in '..\..\CryptoLib\src\Crypto\ClpBufferedAeadBlockCipher.pas', diff --git a/CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.Mobile.dpr b/CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.Mobile.dpr index 35178dd1..950972fb 100644 --- a/CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.Mobile.dpr +++ b/CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.Mobile.dpr @@ -683,26 +683,29 @@ uses ClpEaxBlockCipher in '..\..\CryptoLib\src\Crypto\Modes\ClpEaxBlockCipher.pas', ClpOcbBlockCipher in '..\..\CryptoLib\src\Crypto\Modes\ClpOcbBlockCipher.pas', ClpGcmSivUtilities in '..\..\CryptoLib\src\Crypto\Modes\Gcm\ClpGcmSivUtilities.pas', - ClpFusedKernelTypes in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpFusedKernelTypes.pas', - ClpIFusedGcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedGcmKernel.pas', - ClpIFusedOcbKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedOcbKernel.pas', - ClpIFusedCcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedCcmKernel.pas', - ClpIFusedEaxKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedEaxKernel.pas', - ClpIFusedGcmSivKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedGcmSivKernel.pas', - ClpIFusedCtrKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedCtrKernel.pas', - ClpIFusedCbcKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedCbcKernel.pas', - ClpFusedKernelRegistry in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpFusedKernelRegistry.pas', - ClpAesFusedAeadSimd in '..\..\CryptoLib\src\Crypto\Modes\Fused\Internal\ClpAesFusedAeadSimd.pas', - ClpAesNiFusedX86Backend in '..\..\CryptoLib\src\Crypto\Modes\Fused\Internal\ClpAesNiFusedX86Backend.pas', + ClpCipherKernelTypes in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelTypes.pas', + ClpICipherKernelFactory in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\ClpICipherKernelFactory.pas', + ClpIChaCha20Poly1305Kernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Stream\ClpIChaCha20Poly1305Kernel.pas', + ClpIGcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIGcmKernel.pas', + ClpIOcbKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIOcbKernel.pas', + ClpICcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpICcmKernel.pas', + ClpIEaxKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIEaxKernel.pas', + ClpIGcmSivKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIGcmSivKernel.pas', + ClpICtrKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpICtrKernel.pas', + ClpICbcKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpICbcKernel.pas', + ClpCipherKernelRegistry in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelRegistry.pas', + ClpCipherKernelFactoryBase in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelFactoryBase.pas', + ClpAesFusedAeadSimd in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\Internal\ClpAesFusedAeadSimd.pas', + ClpAesNiFusedX86Backend in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\Internal\ClpAesNiFusedX86Backend.pas', ClpBinPolySimd in '..\..\CryptoLib\src\Math\BinPoly\ClpBinPolySimd.pas', - ClpAesNiOcbKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiOcbKernel.pas', - ClpAesNiCcmKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiCcmKernel.pas', - ClpAesNiEaxKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiEaxKernel.pas', - ClpAesNiGcmKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiGcmKernel.pas', - ClpAesNiCtrKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiCtrKernel.pas', - ClpAesNiCbcKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiCbcKernel.pas', - ClpPclmulGcmSivKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpPclmulGcmSivKernel.pas', - ClpFusedKernelDefaults in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpFusedKernelDefaults.pas', + ClpAesNiOcbKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiOcbKernel.pas', + ClpAesNiCcmKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiCcmKernel.pas', + ClpAesNiEaxKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiEaxKernel.pas', + ClpAesNiGcmKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiGcmKernel.pas', + ClpAesNiCtrKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiCtrKernel.pas', + ClpAesNiCbcKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiCbcKernel.pas', + ClpPclmulGcmSivKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpPclmulGcmSivKernel.pas', + ClpCipherKernelDefaults in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelDefaults.pas', ClpAeadParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpAeadParameters.pas', ClpBufferedAeadCipher in '..\..\CryptoLib\src\Crypto\ClpBufferedAeadCipher.pas', ClpBufferedAeadBlockCipher in '..\..\CryptoLib\src\Crypto\ClpBufferedAeadBlockCipher.pas', @@ -814,7 +817,7 @@ uses AeadTestUtilities in '..\src\Crypto\AeadTestUtilities.pas', CertTestUtilities in '..\src\Utils\CertTestUtilities.pas', CryptoTestKeys in '..\src\Utils\CryptoTestKeys.pas', - FusedKernelToggle in '..\src\Utils\FusedKernelToggle.pas', + CipherKernelToggle in '..\src\Utils\CipherKernelToggle.pas', BlowfishTests in '..\src\Crypto\BlowfishTests.pas', RijndaelTests in '..\src\Crypto\RijndaelTests.pas', Asn1IntegerTests in '..\src\Asn1\Asn1IntegerTests.pas', @@ -869,7 +872,7 @@ uses BlockCipherTestBase in '..\src\Crypto\BlockCipherTestBase.pas', AesBlockCipherTestBase in '..\src\Crypto\AesBlockCipherTestBase.pas', AesLightTests in '..\src\Crypto\AesLightTests.pas', - FusedExternalRegistrationTests in '..\src\Crypto\FusedExternalRegistrationTests.pas', + CipherKernelExternalRegistrationTests in '..\src\Crypto\CipherKernelExternalRegistrationTests.pas', AesHardwareEngineTests in '..\src\Crypto\AesHardwareEngineTests.pas', IESCipherTests in '..\src\Math\IESCipherTests.pas', AESSICTests in '..\src\Crypto\AESSICTests.pas', diff --git a/CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.Mobile.dproj b/CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.Mobile.dproj index 9c815f7a..e6c8abd1 100644 --- a/CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.Mobile.dproj +++ b/CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.Mobile.dproj @@ -1026,26 +1026,29 @@ - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + @@ -1157,7 +1160,7 @@ - + @@ -1208,7 +1211,7 @@ - + diff --git a/CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.dpr b/CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.dpr index c7e20866..240ba637 100644 --- a/CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.dpr +++ b/CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.dpr @@ -702,26 +702,31 @@ uses ClpEaxBlockCipher in '..\..\CryptoLib\src\Crypto\Modes\ClpEaxBlockCipher.pas', ClpOcbBlockCipher in '..\..\CryptoLib\src\Crypto\Modes\ClpOcbBlockCipher.pas', ClpGcmSivUtilities in '..\..\CryptoLib\src\Crypto\Modes\Gcm\ClpGcmSivUtilities.pas', - ClpFusedKernelTypes in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpFusedKernelTypes.pas', - ClpIFusedGcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedGcmKernel.pas', - ClpIFusedOcbKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedOcbKernel.pas', - ClpIFusedCcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedCcmKernel.pas', - ClpIFusedEaxKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedEaxKernel.pas', - ClpIFusedGcmSivKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedGcmSivKernel.pas', - ClpIFusedCtrKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedCtrKernel.pas', - ClpIFusedCbcKernel in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\Fused\ClpIFusedCbcKernel.pas', - ClpFusedKernelRegistry in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpFusedKernelRegistry.pas', - ClpAesFusedAeadSimd in '..\..\CryptoLib\src\Crypto\Modes\Fused\Internal\ClpAesFusedAeadSimd.pas', - ClpAesNiFusedX86Backend in '..\..\CryptoLib\src\Crypto\Modes\Fused\Internal\ClpAesNiFusedX86Backend.pas', + ClpCipherKernelTypes in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelTypes.pas', + ClpICipherKernelFactory in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\ClpICipherKernelFactory.pas', + + ClpIChaCha20Poly1305Kernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Stream\ClpIChaCha20Poly1305Kernel.pas', + ClpIGcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIGcmKernel.pas', + ClpIOcbKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIOcbKernel.pas', + ClpICcmKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpICcmKernel.pas', + ClpIEaxKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIEaxKernel.pas', + ClpIGcmSivKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpIGcmSivKernel.pas', + ClpICtrKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpICtrKernel.pas', + ClpICbcKernel in '..\..\CryptoLib\src\Interfaces\Crypto\CipherKernels\Block\ClpICbcKernel.pas', + ClpCipherKernelRegistry in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelRegistry.pas', + + ClpCipherKernelFactoryBase in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelFactoryBase.pas', + ClpAesFusedAeadSimd in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\Internal\ClpAesFusedAeadSimd.pas', + ClpAesNiFusedX86Backend in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\Internal\ClpAesNiFusedX86Backend.pas', ClpBinPolySimd in '..\..\CryptoLib\src\Math\BinPoly\ClpBinPolySimd.pas', - ClpAesNiOcbKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiOcbKernel.pas', - ClpAesNiCcmKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiCcmKernel.pas', - ClpAesNiEaxKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiEaxKernel.pas', - ClpAesNiGcmKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiGcmKernel.pas', - ClpAesNiCtrKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiCtrKernel.pas', - ClpAesNiCbcKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpAesNiCbcKernel.pas', - ClpPclmulGcmSivKernel in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpPclmulGcmSivKernel.pas', - ClpFusedKernelDefaults in '..\..\CryptoLib\src\Crypto\Modes\Fused\ClpFusedKernelDefaults.pas', + ClpAesNiOcbKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiOcbKernel.pas', + ClpAesNiCcmKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiCcmKernel.pas', + ClpAesNiEaxKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiEaxKernel.pas', + ClpAesNiGcmKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiGcmKernel.pas', + ClpAesNiCtrKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiCtrKernel.pas', + ClpAesNiCbcKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpAesNiCbcKernel.pas', + ClpPclmulGcmSivKernel in '..\..\CryptoLib\src\Crypto\CipherKernels\Block\ClpPclmulGcmSivKernel.pas', + ClpCipherKernelDefaults in '..\..\CryptoLib\src\Crypto\CipherKernels\ClpCipherKernelDefaults.pas', ClpAeadParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpAeadParameters.pas', ClpBufferedAeadCipher in '..\..\CryptoLib\src\Crypto\ClpBufferedAeadCipher.pas', ClpBufferedAeadBlockCipher in '..\..\CryptoLib\src\Crypto\ClpBufferedAeadBlockCipher.pas', @@ -833,7 +838,7 @@ uses AeadTestUtilities in '..\src\Crypto\AeadTestUtilities.pas', CertTestUtilities in '..\src\Utils\CertTestUtilities.pas', CryptoTestKeys in '..\src\Utils\CryptoTestKeys.pas', - FusedKernelToggle in '..\src\Utils\FusedKernelToggle.pas', + CipherKernelToggle in '..\src\Utils\CipherKernelToggle.pas', BlowfishTests in '..\src\Crypto\BlowfishTests.pas', RijndaelTests in '..\src\Crypto\RijndaelTests.pas', Asn1IntegerTests in '..\src\Asn1\Asn1IntegerTests.pas', @@ -888,7 +893,7 @@ uses BlockCipherTestBase in '..\src\Crypto\BlockCipherTestBase.pas', AesBlockCipherTestBase in '..\src\Crypto\AesBlockCipherTestBase.pas', AesLightTests in '..\src\Crypto\AesLightTests.pas', - FusedExternalRegistrationTests in '..\src\Crypto\FusedExternalRegistrationTests.pas', + CipherKernelExternalRegistrationTests in '..\src\Crypto\CipherKernelExternalRegistrationTests.pas', AesHardwareEngineTests in '..\src\Crypto\AesHardwareEngineTests.pas', IESCipherTests in '..\src\Math\IESCipherTests.pas', AESSICTests in '..\src\Crypto\AESSICTests.pas', diff --git a/CryptoLib.Tests/FreePascal.Tests/CryptoLib.Tests.lpi b/CryptoLib.Tests/FreePascal.Tests/CryptoLib.Tests.lpi index abd65594..2487bfb5 100644 --- a/CryptoLib.Tests/FreePascal.Tests/CryptoLib.Tests.lpi +++ b/CryptoLib.Tests/FreePascal.Tests/CryptoLib.Tests.lpi @@ -610,11 +610,11 @@ - + - + diff --git a/CryptoLib.Tests/FreePascal.Tests/CryptoLib.lpr b/CryptoLib.Tests/FreePascal.Tests/CryptoLib.lpr index 16ccb173..3001f6db 100644 --- a/CryptoLib.Tests/FreePascal.Tests/CryptoLib.lpr +++ b/CryptoLib.Tests/FreePascal.Tests/CryptoLib.lpr @@ -11,7 +11,7 @@ SecP256R1FieldTests, SecP384R1FieldTests, ECDsa5Tests, ECTests, NamedCurveTests, SignerUtilitiesTests, SecureRandomTests, DigestRandomNumberTests, FixedPointTests, AESTests, AesLightTests, - FusedExternalRegistrationTests, AesHardwareEngineTests, AESSICTests, + CipherKernelExternalRegistrationTests, AesHardwareEngineTests, AESSICTests, SicBulkParityTests, EcbBulkParityTests, CbcBulkParityTests, GcmSivBulkParityTests, BlockCipherTestBase, SpeckBlockCipherTestBase, SpeckLegacyTests, SpeckTests, @@ -47,7 +47,7 @@ BinaryPrimitivesTests, PkcsEncryptedPrivateKeyInfoTests, Pkcs12StoreTests, OpenSslReaderTests, OpenSslWriterTests, X509CertGenTests, X509CertificatePairTests, X509UtilitiesTests, FixedSecureRandom, - ShortenedDigest, CertTestUtilities, FusedKernelToggle, + ShortenedDigest, CertTestUtilities, CipherKernelToggle, CryptoLibTestResourceLoader, CryptoTestKeys, NistSecureRandom, PqcTestSampler, CsvVectorParser, JsonVectorParser, RspTxtVectorParser, RspTxtVectorParserTests, Bip327Vectors, Bip340Vectors, HmacVectors, diff --git a/CryptoLib.Tests/FreePascal.Tests/CryptoLibConsole.lpi b/CryptoLib.Tests/FreePascal.Tests/CryptoLibConsole.lpi index a7f291f4..e5e43c52 100644 --- a/CryptoLib.Tests/FreePascal.Tests/CryptoLibConsole.lpi +++ b/CryptoLib.Tests/FreePascal.Tests/CryptoLibConsole.lpi @@ -569,11 +569,11 @@ - + - + diff --git a/CryptoLib.Tests/FreePascal.Tests/CryptoLibConsole.lpr b/CryptoLib.Tests/FreePascal.Tests/CryptoLibConsole.lpr index 35b33c6c..0e47d9ba 100644 --- a/CryptoLib.Tests/FreePascal.Tests/CryptoLibConsole.lpr +++ b/CryptoLib.Tests/FreePascal.Tests/CryptoLibConsole.lpr @@ -12,7 +12,7 @@ SecP256R1FieldTests, SecP384R1FieldTests, ECDsa5Tests, ECTests, NamedCurveTests, SignerUtilitiesTests, SecureRandomTests, DigestRandomNumberTests, FixedPointTests, AESTests, AesLightTests, - FusedExternalRegistrationTests, AesHardwareEngineTests, AESSICTests, + CipherKernelExternalRegistrationTests, AesHardwareEngineTests, AESSICTests, SicBulkParityTests, EcbBulkParityTests, CbcBulkParityTests, GcmSivBulkParityTests, BlockCipherTestBase, SpeckBlockCipherTestBase, SpeckLegacyTests, SpeckTests, @@ -48,7 +48,7 @@ BinaryPrimitivesTests, PkcsEncryptedPrivateKeyInfoTests, Pkcs12StoreTests, OpenSslReaderTests, OpenSslWriterTests, X509CertGenTests, X509CertificatePairTests, X509UtilitiesTests, FixedSecureRandom, - ShortenedDigest, CertTestUtilities, CryptoTestKeys, FusedKernelToggle, + ShortenedDigest, CertTestUtilities, CryptoTestKeys, CipherKernelToggle, CryptoLibTestResourceLoader, NistSecureRandom, CsvVectorParser, JsonVectorParser, RspTxtVectorParser, RspTxtVectorParserTests, Bip327Vectors, Bip340Vectors, HmacVectors, AsymmetricTestVectors, SymmetricBlockVectors, diff --git a/CryptoLib.Tests/src/Crypto/CcmTests.pas b/CryptoLib.Tests/src/Crypto/CcmTests.pas index 678e2776..3bf91d66 100644 --- a/CryptoLib.Tests/src/Crypto/CcmTests.pas +++ b/CryptoLib.Tests/src/Crypto/CcmTests.pas @@ -49,7 +49,7 @@ interface ClpCryptoLibTypes, ClpIAeadCipher, AeadTestUtilities, - FusedKernelToggle, + CipherKernelToggle, CryptoLibTestBase; type @@ -81,7 +81,7 @@ TTestCcm = class(TCryptoLibAlgorithmTestCase) procedure SetUp; override; procedure TearDown; override; - // Workers run twice via RunWithFusedToggle (fused on / off). + // Workers run twice via RunWithCipherKernelToggle (cipher kernel on / off). procedure DoTestNistVectorsAndLongData; procedure DoTestCcmIvParameters; procedure DoTestOffsets; @@ -505,22 +505,22 @@ procedure TTestCcm.DoTestRandomised; procedure TTestCcm.TestNistVectorsAndLongData; begin - RunWithFusedToggle(DoTestNistVectorsAndLongData); + RunWithCipherKernelToggle(DoTestNistVectorsAndLongData); end; procedure TTestCcm.TestCcmIvParameters; begin - RunWithFusedToggle(DoTestCcmIvParameters); + RunWithCipherKernelToggle(DoTestCcmIvParameters); end; procedure TTestCcm.TestOffsets; begin - RunWithFusedToggle(DoTestOffsets); + RunWithCipherKernelToggle(DoTestOffsets); end; procedure TTestCcm.TestRandomised; begin - RunWithFusedToggle(DoTestRandomised); + RunWithCipherKernelToggle(DoTestRandomised); end; procedure TTestCcm.TestExceptions; @@ -679,7 +679,7 @@ procedure TTestCcm.DoTestNoUnverifiedPlaintextOnFailure; procedure TTestCcm.TestNoUnverifiedPlaintextOnFailure; begin - RunWithFusedToggle(DoTestNoUnverifiedPlaintextOnFailure); + RunWithCipherKernelToggle(DoTestNoUnverifiedPlaintextOnFailure); end; procedure TTestCcm.DoTestInvalidTagLength; @@ -751,12 +751,12 @@ procedure TTestCcm.DoTestValidTagLength; procedure TTestCcm.TestInvalidTagLength; begin - RunWithFusedToggle(DoTestInvalidTagLength); + RunWithCipherKernelToggle(DoTestInvalidTagLength); end; procedure TTestCcm.TestValidTagLength; begin - RunWithFusedToggle(DoTestValidTagLength); + RunWithCipherKernelToggle(DoTestValidTagLength); end; initialization diff --git a/CryptoLib.Tests/src/Crypto/FusedExternalRegistrationTests.pas b/CryptoLib.Tests/src/Crypto/CipherKernelExternalRegistrationTests.pas similarity index 67% rename from CryptoLib.Tests/src/Crypto/FusedExternalRegistrationTests.pas rename to CryptoLib.Tests/src/Crypto/CipherKernelExternalRegistrationTests.pas index 38dad6be..e54ce598 100644 --- a/CryptoLib.Tests/src/Crypto/FusedExternalRegistrationTests.pas +++ b/CryptoLib.Tests/src/Crypto/CipherKernelExternalRegistrationTests.pas @@ -14,7 +14,7 @@ (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) -unit FusedExternalRegistrationTests; +unit CipherKernelExternalRegistrationTests; interface @@ -31,9 +31,9 @@ interface TestFramework, {$ENDIF FPC} ClpIBlockCipher, - ClpFusedKernelTypes, - ClpIFusedGcmKernel, - ClpFusedKernelRegistry, + ClpCipherKernelTypes, + ClpIGcmKernel, + ClpCipherKernelRegistry, ClpCryptoLibTypes; type @@ -41,17 +41,17 @@ interface /// No-op third-party GCM kernel factory used by the external /// registration pin tests. TryCreate always returns False so no /// code path (production or test) actually acquires this factory - /// as a fused kernel; its only observable effect is its presence + /// as a cipher kernel; its only observable effect is its presence /// in the registry's public diagnostic lists. /// TMockExternalGcmKernelFactory = class sealed(TInterfacedObject, - IFusedGcmKernelFactory) + IGcmKernelFactory) public function ProviderName: String; - function Priority: TFusedKernelPriority; + function Priority: TCipherKernelPriority; function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; AHPowers: Pointer; - out AKernel: IFusedGcmKernel): Boolean; + ADirection: TCipherKernelDirection; AHPowers: Pointer; + out AKernel: IGcmKernel): Boolean; end; /// @@ -59,17 +59,17 @@ TMockExternalGcmKernelFactory = class sealed(TInterfacedObject, /// CryptoLib" contract. A mock third-party factory is registered /// from test code exactly the way a consumer's own unit would /// register from its initialization block. The tests assert that: - /// * after RegisterGcmFactory, GetRegisteredGcmProviders + /// * after Register, GetRegisteredProviders(IGcmKernelFactory) /// reflects the mock; /// * registration is strictly additive -- every provider that /// was already present is still present afterwards (defaults /// coexist); - /// * UnregisterGcmFactory returns the provider list to its + /// * Unregister returns the provider list to its /// prior state. /// Any future change that silently regresses this external /// registration contract will trip a red test here. /// - TTestFusedExternalRegistration = class(TTestCase) + TTestCipherKernelExternalRegistration = class(TTestCase) strict private class function ProvidersContain(const AList: TCryptoLibStringArray; const AName: String): Boolean; static; @@ -88,21 +88,21 @@ implementation resourcestring SMockMustBePresent = 'Mock external GCM factory must appear in ' + - 'GetRegisteredGcmProviders after RegisterGcmFactory.'; + 'GetRegisteredProviders(IGcmKernelFactory) after Register.'; SMockMustBeAbsent = 'Mock external GCM factory must be absent from ' + - 'GetRegisteredGcmProviders after UnregisterGcmFactory.'; + 'GetRegisteredProviders(IGcmKernelFactory) after Unregister.'; SCountMustGrowByOne = - 'External RegisterGcmFactory must grow the provider count by ' + + 'External Register must grow the provider count by ' + 'exactly one (non-duplicate factory).'; SCountMustRestoreBaseline = - 'External UnregisterGcmFactory must restore the provider count ' + + 'External Unregister must restore the provider count ' + 'to its pre-registration baseline.'; SDefaultsMustSurvive = 'Every provider present before external registration must still ' + 'be reported afterwards (registration is strictly additive).'; SDuplicateMustBeIgnored = - 'RegisterGcmFactory MUST silently ignore duplicate registrations ' + + 'Register MUST silently ignore duplicate registrations ' + '(same interface identity).'; { TMockExternalGcmKernelFactory } @@ -112,26 +112,26 @@ function TMockExternalGcmKernelFactory.ProviderName: String; Result := CMockExternalProviderName; end; -function TMockExternalGcmKernelFactory.Priority: TFusedKernelPriority; +function TMockExternalGcmKernelFactory.Priority: TCipherKernelPriority; begin // Fallback is the lowest rank so this mock never intercepts real // GCM acquires on any platform where a genuine in-tree factory is // also registered. The mock's entire purpose is to appear in the // diagnostic list, not to be picked up by TryAcquireGcm. - Result := TFusedKernelPriority.Fallback; + Result := TCipherKernelPriority.Fallback; end; function TMockExternalGcmKernelFactory.TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; AHPowers: Pointer; - out AKernel: IFusedGcmKernel): Boolean; + ADirection: TCipherKernelDirection; AHPowers: Pointer; + out AKernel: IGcmKernel): Boolean; begin AKernel := nil; Result := False; end; -{ TTestFusedExternalRegistration } +{ TTestCipherKernelExternalRegistration } -class function TTestFusedExternalRegistration.ProvidersContain( +class function TTestCipherKernelExternalRegistration.ProvidersContain( const AList: TCryptoLibStringArray; const AName: String): Boolean; var LIndex: Int32; @@ -145,33 +145,33 @@ class function TTestFusedExternalRegistration.ProvidersContain( end; end; -procedure TTestFusedExternalRegistration.TestExternalRegistrationAddsProvider; +procedure TTestCipherKernelExternalRegistration.TestExternalRegistrationAddsProvider; var - LFactory: IFusedGcmKernelFactory; + LFactory: IGcmKernelFactory; LProviders: TCryptoLibStringArray; begin LFactory := TMockExternalGcmKernelFactory.Create(); - TFusedKernelRegistry.RegisterGcmFactory(LFactory); + TCipherKernelRegistry.Register(LFactory); try - LProviders := TFusedKernelRegistry.GetRegisteredGcmProviders; + LProviders := TCipherKernelRegistry.GetRegisteredProviders(IGcmKernelFactory); CheckTrue(ProvidersContain(LProviders, CMockExternalProviderName), SMockMustBePresent); finally - TFusedKernelRegistry.UnregisterGcmFactory(LFactory); + TCipherKernelRegistry.Unregister(LFactory); end; end; -procedure TTestFusedExternalRegistration.TestExternalRegistrationIsStrictlyAdditive; +procedure TTestCipherKernelExternalRegistration.TestExternalRegistrationIsStrictlyAdditive; var - LFactory: IFusedGcmKernelFactory; + LFactory: IGcmKernelFactory; LBaseline, LAfter: TCryptoLibStringArray; LIndex: Int32; begin - LBaseline := TFusedKernelRegistry.GetRegisteredGcmProviders; + LBaseline := TCipherKernelRegistry.GetRegisteredProviders(IGcmKernelFactory); LFactory := TMockExternalGcmKernelFactory.Create(); - TFusedKernelRegistry.RegisterGcmFactory(LFactory); + TCipherKernelRegistry.Register(LFactory); try - LAfter := TFusedKernelRegistry.GetRegisteredGcmProviders; + LAfter := TCipherKernelRegistry.GetRegisteredProviders(IGcmKernelFactory); CheckEquals(System.Length(LBaseline) + 1, System.Length(LAfter), SCountMustGrowByOne); // Every baseline name must survive the registration. @@ -179,22 +179,22 @@ procedure TTestFusedExternalRegistration.TestExternalRegistrationIsStrictlyAddit CheckTrue(ProvidersContain(LAfter, LBaseline[LIndex]), SDefaultsMustSurvive); finally - TFusedKernelRegistry.UnregisterGcmFactory(LFactory); + TCipherKernelRegistry.Unregister(LFactory); end; end; -procedure TTestFusedExternalRegistration.TestExternalUnregistrationRestoresPriorList; +procedure TTestCipherKernelExternalRegistration.TestExternalUnregistrationRestoresPriorList; var - LFactory: IFusedGcmKernelFactory; + LFactory: IGcmKernelFactory; LBaseline, LAfterUnregister: TCryptoLibStringArray; LIndex: Int32; begin - LBaseline := TFusedKernelRegistry.GetRegisteredGcmProviders; + LBaseline := TCipherKernelRegistry.GetRegisteredProviders(IGcmKernelFactory); LFactory := TMockExternalGcmKernelFactory.Create(); - TFusedKernelRegistry.RegisterGcmFactory(LFactory); - TFusedKernelRegistry.UnregisterGcmFactory(LFactory); + TCipherKernelRegistry.Register(LFactory); + TCipherKernelRegistry.Unregister(LFactory); - LAfterUnregister := TFusedKernelRegistry.GetRegisteredGcmProviders; + LAfterUnregister := TCipherKernelRegistry.GetRegisteredProviders(IGcmKernelFactory); CheckEquals(System.Length(LBaseline), System.Length(LAfterUnregister), SCountMustRestoreBaseline); CheckFalse(ProvidersContain(LAfterUnregister, CMockExternalProviderName), @@ -204,30 +204,30 @@ procedure TTestFusedExternalRegistration.TestExternalUnregistrationRestoresPrior SDefaultsMustSurvive); end; -procedure TTestFusedExternalRegistration.TestDuplicateExternalRegistrationIsIgnored; +procedure TTestCipherKernelExternalRegistration.TestDuplicateExternalRegistrationIsIgnored; var - LFactory: IFusedGcmKernelFactory; + LFactory: IGcmKernelFactory; LBaseline, LAfter: TCryptoLibStringArray; begin - LBaseline := TFusedKernelRegistry.GetRegisteredGcmProviders; + LBaseline := TCipherKernelRegistry.GetRegisteredProviders(IGcmKernelFactory); LFactory := TMockExternalGcmKernelFactory.Create(); - TFusedKernelRegistry.RegisterGcmFactory(LFactory); + TCipherKernelRegistry.Register(LFactory); try - TFusedKernelRegistry.RegisterGcmFactory(LFactory); - LAfter := TFusedKernelRegistry.GetRegisteredGcmProviders; + TCipherKernelRegistry.Register(LFactory); + LAfter := TCipherKernelRegistry.GetRegisteredProviders(IGcmKernelFactory); CheckEquals(System.Length(LBaseline) + 1, System.Length(LAfter), SDuplicateMustBeIgnored); finally - TFusedKernelRegistry.UnregisterGcmFactory(LFactory); + TCipherKernelRegistry.Unregister(LFactory); end; end; initialization {$IFDEF FPC} - RegisterTest(TTestFusedExternalRegistration); + RegisterTest(TTestCipherKernelExternalRegistration); {$ELSE} - RegisterTest(TTestFusedExternalRegistration.Suite); + RegisterTest(TTestCipherKernelExternalRegistration.Suite); {$ENDIF FPC} end. diff --git a/CryptoLib.Tests/src/Crypto/EaxTests.pas b/CryptoLib.Tests/src/Crypto/EaxTests.pas index 7bdcd2b3..3115ad94 100644 --- a/CryptoLib.Tests/src/Crypto/EaxTests.pas +++ b/CryptoLib.Tests/src/Crypto/EaxTests.pas @@ -48,7 +48,7 @@ interface ClpConverters, ClpIAeadCipher, AeadTestUtilities, - FusedKernelToggle, + CipherKernelToggle, CryptoLibTestBase; type @@ -91,7 +91,7 @@ TTestEax = class(TCryptoLibAlgorithmTestCase) procedure SetUp; override; procedure TearDown; override; - // Workers run twice via RunWithFusedToggle (fused on / off). + // Workers run twice via RunWithCipherKernelToggle (cipher kernel on / off). procedure DoTestVectors; procedure DoTestIvParameters; procedure DoTestExceptionsAndRandomised; @@ -566,27 +566,27 @@ procedure TTestEax.DoTestValidTagLength; procedure TTestEax.TestVectors; begin - RunWithFusedToggle(DoTestVectors); + RunWithCipherKernelToggle(DoTestVectors); end; procedure TTestEax.TestIvParameters; begin - RunWithFusedToggle(DoTestIvParameters); + RunWithCipherKernelToggle(DoTestIvParameters); end; procedure TTestEax.TestExceptionsAndRandomised; begin - RunWithFusedToggle(DoTestExceptionsAndRandomised); + RunWithCipherKernelToggle(DoTestExceptionsAndRandomised); end; procedure TTestEax.TestInvalidTagLength; begin - RunWithFusedToggle(DoTestInvalidTagLength); + RunWithCipherKernelToggle(DoTestInvalidTagLength); end; procedure TTestEax.TestValidTagLength; begin - RunWithFusedToggle(DoTestValidTagLength); + RunWithCipherKernelToggle(DoTestValidTagLength); end; initialization diff --git a/CryptoLib.Tests/src/Crypto/GCMTests.pas b/CryptoLib.Tests/src/Crypto/GCMTests.pas index 1c023c6a..bdf75b67 100644 --- a/CryptoLib.Tests/src/Crypto/GCMTests.pas +++ b/CryptoLib.Tests/src/Crypto/GCMTests.pas @@ -51,7 +51,7 @@ interface ClpDateTimeUtilities, ClpConverters, ClpCryptoLibTypes, - FusedKernelToggle, + CipherKernelToggle, AeadTestUtilities, CryptoLibTestBase, SymmetricBlockVectors; @@ -81,7 +81,7 @@ TTestGcm = class(TCryptoLibAlgorithmTestCase) procedure DoTestExceptions; function NextInt32(const ARandom: ISecureRandom; AN: Int32): Int32; - // Workers run twice via RunWithFusedToggle (fused on / off). + // Workers run twice via RunWithCipherKernelToggle (cipher kernel on / off). procedure DoTestRfcVectors; procedure DoTestRandomised; procedure DoTestOutputSizes; @@ -577,32 +577,32 @@ procedure TTestGcm.DoTestExceptions; procedure TTestGcm.TestRfcVectors; begin - RunWithFusedToggle(DoTestRfcVectors); + RunWithCipherKernelToggle(DoTestRfcVectors); end; procedure TTestGcm.TestRandomised; begin - RunWithFusedToggle(DoTestRandomised); + RunWithCipherKernelToggle(DoTestRandomised); end; procedure TTestGcm.TestOutputSizes; begin - RunWithFusedToggle(DoTestOutputSizes); + RunWithCipherKernelToggle(DoTestOutputSizes); end; procedure TTestGcm.TestExceptions; begin - RunWithFusedToggle(DoTestExceptionsWrapper); + RunWithCipherKernelToggle(DoTestExceptionsWrapper); end; procedure TTestGcm.TestFourBlockFusedGcmPath; begin - RunWithFusedToggle(DoTestFourBlockFusedGcmPath); + RunWithCipherKernelToggle(DoTestFourBlockFusedGcmPath); end; procedure TTestGcm.TestEightBlockFusedGcmPath; begin - RunWithFusedToggle(DoTestEightBlockFusedGcmPath); + RunWithCipherKernelToggle(DoTestEightBlockFusedGcmPath); end; procedure TTestGcm.DoTestRfcVectors; diff --git a/CryptoLib.Tests/src/Crypto/GcmSivBulkParityTests.pas b/CryptoLib.Tests/src/Crypto/GcmSivBulkParityTests.pas index 06536473..3a57ed0c 100644 --- a/CryptoLib.Tests/src/Crypto/GcmSivBulkParityTests.pas +++ b/CryptoLib.Tests/src/Crypto/GcmSivBulkParityTests.pas @@ -34,7 +34,7 @@ interface ClpKeyParameter, ClpIKeyParameter, ClpICipherParameters, - ClpFusedKernelRegistry, + ClpCipherKernelRegistry, ClpSecureRandom, ClpISecureRandom, ClpConverters, @@ -72,10 +72,10 @@ function TTestGcmSivBulkParity.GcmSivEncrypt(const AKey, ANonce, AAad, LSaved: Boolean; LLen: Int32; begin - LSaved := TFusedKernelGate.ForceDisabled; + LSaved := TCipherKernelGate.ForceDisabled; // The fused POLYVAL kernel is resolved during Init (DeriveKeys); the gate must // therefore be set BEFORE Init to select the fused or scalar path. - TFusedKernelGate.ForceDisabled := not AUseFused; + TCipherKernelGate.ForceDisabled := not AUseFused; try LCipher := TGcmSivBlockCipher.Create() as IGcmSivBlockCipher; LCipher.Init(True, TAeadParameters.Create(TKeyParameter.Create(AKey) @@ -86,7 +86,7 @@ function TTestGcmSivBulkParity.GcmSivEncrypt(const AKey, ANonce, AAad, if LLen <> System.Length(Result) then System.SetLength(Result, LLen); finally - TFusedKernelGate.ForceDisabled := LSaved; + TCipherKernelGate.ForceDisabled := LSaved; end; end; @@ -97,8 +97,8 @@ function TTestGcmSivBulkParity.GcmSivDecrypt(const AKey, ANonce, AAad, LSaved: Boolean; LLen: Int32; begin - LSaved := TFusedKernelGate.ForceDisabled; - TFusedKernelGate.ForceDisabled := not AUseFused; + LSaved := TCipherKernelGate.ForceDisabled; + TCipherKernelGate.ForceDisabled := not AUseFused; try LCipher := TGcmSivBlockCipher.Create() as IGcmSivBlockCipher; LCipher.Init(False, TAeadParameters.Create(TKeyParameter.Create(AKey) @@ -109,7 +109,7 @@ function TTestGcmSivBulkParity.GcmSivDecrypt(const AKey, ANonce, AAad, if LLen <> System.Length(Result) then System.SetLength(Result, LLen); finally - TFusedKernelGate.ForceDisabled := LSaved; + TCipherKernelGate.ForceDisabled := LSaved; end; end; diff --git a/CryptoLib.Tests/src/Crypto/GcmSivTests.pas b/CryptoLib.Tests/src/Crypto/GcmSivTests.pas index 86253985..60393398 100644 --- a/CryptoLib.Tests/src/Crypto/GcmSivTests.pas +++ b/CryptoLib.Tests/src/Crypto/GcmSivTests.pas @@ -41,7 +41,7 @@ interface ClpSecureRandom, ClpISecureRandom, ClpCryptoLibTypes, - FusedKernelToggle, + CipherKernelToggle, CryptoLibTestBase, SymmetricBlockVectors; @@ -295,42 +295,42 @@ procedure TTestGcmSiv.DoTestRandomised; procedure TTestGcmSiv.TestAesGcmSiv128Set1; begin - RunWithFusedToggle(DoTestAesGcmSiv128Set1); + RunWithCipherKernelToggle(DoTestAesGcmSiv128Set1); end; procedure TTestGcmSiv.TestAesGcmSiv128Set2; begin - RunWithFusedToggle(DoTestAesGcmSiv128Set2); + RunWithCipherKernelToggle(DoTestAesGcmSiv128Set2); end; procedure TTestGcmSiv.TestAesGcmSiv128Set3; begin - RunWithFusedToggle(DoTestAesGcmSiv128Set3); + RunWithCipherKernelToggle(DoTestAesGcmSiv128Set3); end; procedure TTestGcmSiv.TestAesGcmSiv256Set1; begin - RunWithFusedToggle(DoTestAesGcmSiv256Set1); + RunWithCipherKernelToggle(DoTestAesGcmSiv256Set1); end; procedure TTestGcmSiv.TestAesGcmSiv256Set2; begin - RunWithFusedToggle(DoTestAesGcmSiv256Set2); + RunWithCipherKernelToggle(DoTestAesGcmSiv256Set2); end; procedure TTestGcmSiv.TestAesGcmSiv256Set3; begin - RunWithFusedToggle(DoTestAesGcmSiv256Set3); + RunWithCipherKernelToggle(DoTestAesGcmSiv256Set3); end; procedure TTestGcmSiv.TestAesGcmSiv256Set4; begin - RunWithFusedToggle(DoTestAesGcmSiv256Set4); + RunWithCipherKernelToggle(DoTestAesGcmSiv256Set4); end; procedure TTestGcmSiv.TestRandomised; begin - RunWithFusedToggle(DoTestRandomised); + RunWithCipherKernelToggle(DoTestRandomised); end; initialization diff --git a/CryptoLib.Tests/src/Crypto/OcbTests.pas b/CryptoLib.Tests/src/Crypto/OcbTests.pas index ea97b285..59906e2d 100644 --- a/CryptoLib.Tests/src/Crypto/OcbTests.pas +++ b/CryptoLib.Tests/src/Crypto/OcbTests.pas @@ -44,7 +44,7 @@ interface ClpCryptoLibTypes, ClpAesUtilities, ClpOcbBlockCipher, - FusedKernelToggle, + CipherKernelToggle, CryptoLibTestBase, AeadTestUtilities; @@ -92,7 +92,7 @@ TTestOcb = class(TCryptoLibAlgorithmTestCase) procedure SetUp; override; procedure TearDown; override; - // Workers run twice via RunWithFusedToggle (fused on / off) so any + // Workers run twice via RunWithCipherKernelToggle (cipher kernel on / off) so any // drift between the two code paths surfaces as a test failure. procedure DoTestRfcVectors128; procedure DoTestRfcVectors96; @@ -581,22 +581,22 @@ procedure TTestOcb.TearDown; procedure TTestOcb.TestRfcVectors128; begin - RunWithFusedToggle(DoTestRfcVectors128); + RunWithCipherKernelToggle(DoTestRfcVectors128); end; procedure TTestOcb.TestRfcVectors96; begin - RunWithFusedToggle(DoTestRfcVectors96); + RunWithCipherKernelToggle(DoTestRfcVectors96); end; procedure TTestOcb.TestOcbLongForm; begin - RunWithFusedToggle(DoTestOcbLongForm); + RunWithCipherKernelToggle(DoTestOcbLongForm); end; procedure TTestOcb.TestRandomised; begin - RunWithFusedToggle(DoTestRandomised); + RunWithCipherKernelToggle(DoTestRandomised); end; procedure TTestOcb.DoTestRfcVectors128; diff --git a/CryptoLib.Tests/src/Utils/FusedKernelToggle.pas b/CryptoLib.Tests/src/Utils/CipherKernelToggle.pas similarity index 78% rename from CryptoLib.Tests/src/Utils/FusedKernelToggle.pas rename to CryptoLib.Tests/src/Utils/CipherKernelToggle.pas index ce7b5152..37290fb1 100644 --- a/CryptoLib.Tests/src/Utils/FusedKernelToggle.pas +++ b/CryptoLib.Tests/src/Utils/CipherKernelToggle.pas @@ -14,7 +14,7 @@ (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) -unit FusedKernelToggle; +unit CipherKernelToggle; interface @@ -24,36 +24,36 @@ interface uses SysUtils, - ClpFusedKernelRegistry; + ClpCipherKernelRegistry; type - TFusedToggleTestProc = procedure of object; + TCipherKernelToggleProc = procedure of object; /// -/// Runs AProc twice: once with fused kernels enabled (production +/// Runs AProc twice: once with cipher kernels enabled (production /// default) and once with them forcibly disabled so the scalar / /// generic-bulk fallbacks are exercised. Both passes must produce /// byte-identical outputs. The previous kill-switch state is saved /// and restored on return (including on exceptions). /// -procedure RunWithFusedToggle(AProc: TFusedToggleTestProc); +procedure RunWithCipherKernelToggle(AProc: TCipherKernelToggleProc); implementation -procedure RunWithFusedToggle(AProc: TFusedToggleTestProc); +procedure RunWithCipherKernelToggle(AProc: TCipherKernelToggleProc); var LSaved: Boolean; begin if not Assigned(AProc) then Exit; - LSaved := TFusedKernelGate.ForceDisabled; + LSaved := TCipherKernelGate.ForceDisabled; try - TFusedKernelGate.ForceDisabled := False; + TCipherKernelGate.ForceDisabled := False; AProc(); - TFusedKernelGate.ForceDisabled := True; + TCipherKernelGate.ForceDisabled := True; AProc(); finally - TFusedKernelGate.ForceDisabled := LSaved; + TCipherKernelGate.ForceDisabled := LSaved; end; end; diff --git a/CryptoLib/src/Crypto/Modes/Fused/ClpAesNiCbcKernel.pas b/CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiCbcKernel.pas similarity index 88% rename from CryptoLib/src/Crypto/Modes/Fused/ClpAesNiCbcKernel.pas rename to CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiCbcKernel.pas index fb341932..ada78f49 100644 --- a/CryptoLib/src/Crypto/Modes/Fused/ClpAesNiCbcKernel.pas +++ b/CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiCbcKernel.pas @@ -24,14 +24,15 @@ interface SysUtils, ClpIBlockCipher, ClpIAesEngineX86, - ClpFusedKernelTypes, - ClpIFusedCbcKernel, - ClpFusedKernelRegistry, + ClpCipherKernelTypes, + ClpICbcKernel, + ClpCipherKernelFactoryBase, + ClpCipherKernelRegistry, ClpAesNiFusedX86Backend; type /// - /// AES-NI implementation of IFusedCbcKernel: the serial CBC-encrypt chain + /// AES-NI implementation of ICbcKernel: the serial CBC-encrypt chain /// C_i = E_K(P_i xor C_{i-1}) applied over a whole run in one call, with the /// chaining value held in a register between blocks (kernel body in /// Include\Simd\Aes\Cbc). Reuses the shared 1-wide AES round chain @@ -40,7 +41,7 @@ interface /// unavailable the factory returns nil and TCbcBlockCipher keeps its existing /// per-block bulk path. /// - TAesNiCbcKernel = class sealed(TInterfacedObject, IFusedCbcKernel) + TAesNiCbcKernel = class sealed(TInterfacedObject, ICbcKernel) strict private // FEngine is retained so the round-key buffer FKeys points into stays alive // for the kernel's lifetime. @@ -54,13 +55,12 @@ TAesNiCbcKernel = class sealed(TInterfacedObject, IFusedCbcKernel) ABlockCount: NativeInt); end; - TAesNiCbcKernelFactory = class sealed(TInterfacedObject, IFusedCbcKernelFactory) + TAesNiCbcKernelFactory = class sealed(TCipherKernelFactoryBase, ICbcKernelFactory) public - function ProviderName: String; - function Priority: TFusedKernelPriority; + function ProviderName: String; override; function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedCbcKernel): Boolean; + ADirection: TCipherKernelDirection; + out AKernel: ICbcKernel): Boolean; end; implementation @@ -167,13 +167,8 @@ function TAesNiCbcKernelFactory.ProviderName: String; Result := 'AES-NI'; end; -function TAesNiCbcKernelFactory.Priority: TFusedKernelPriority; -begin - Result := TFusedKernelPriority.Baseline; -end; - function TAesNiCbcKernelFactory.TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; out AKernel: IFusedCbcKernel): Boolean; + ADirection: TCipherKernelDirection; out AKernel: ICbcKernel): Boolean; var LEngine: IAesEngineX86; LKeys: PByte; @@ -181,7 +176,7 @@ function TAesNiCbcKernelFactory.TryCreate(const ACipher: IBlockCipher; begin AKernel := nil; Result := False; - if ADirection <> TFusedModeDirection.Encrypt then + if ADirection <> TCipherKernelDirection.Encrypt then Exit; // only encrypt is implemented; decrypt not yet supported try {$IFDEF CRYPTOLIB_X86_SIMD} @@ -201,7 +196,7 @@ function TAesNiCbcKernelFactory.TryCreate(const ACipher: IBlockCipher; end; initialization - TFusedKernelRegistry.RegisterCbcFactory( - TAesNiCbcKernelFactory.Create() as IFusedCbcKernelFactory); + TCipherKernelRegistry.Register( + TAesNiCbcKernelFactory.Create() as ICbcKernelFactory); end. diff --git a/CryptoLib/src/Crypto/Modes/Fused/ClpAesNiCcmKernel.pas b/CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiCcmKernel.pas similarity index 91% rename from CryptoLib/src/Crypto/Modes/Fused/ClpAesNiCcmKernel.pas rename to CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiCcmKernel.pas index 3cff60f4..8c385fd6 100644 --- a/CryptoLib/src/Crypto/Modes/Fused/ClpAesNiCcmKernel.pas +++ b/CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiCcmKernel.pas @@ -24,15 +24,16 @@ interface SysUtils, ClpIBlockCipher, ClpIAesEngineX86, - ClpFusedKernelTypes, - ClpIFusedCcmKernel, - ClpFusedKernelRegistry, + ClpCipherKernelTypes, + ClpICcmKernel, + ClpCipherKernelFactoryBase, + ClpCipherKernelRegistry, ClpAesFusedAeadSimd, ClpAesNiFusedX86Backend; type /// - /// AES-NI implementation of IFusedCcmKernel. + /// AES-NI implementation of ICcmKernel. /// Available on x86_64 (CRYPTOLIB_X86_64_ASM) and i386 /// (CRYPTOLIB_I386_ASM); both arms gated collectively by /// CRYPTOLIB_X86_SIMD. @@ -42,7 +43,7 @@ interface /// The kernel loops internally over ABlockCount body blocks; the /// mode invokes ProcessBody once per Init cycle. /// - TAesNiCcmKernel = class sealed(TInterfacedObject, IFusedCcmKernel) + TAesNiCcmKernel = class sealed(TInterfacedObject, ICcmKernel) strict private const FUSED_CCM_MIN_BLOCKS = 1; @@ -57,25 +58,24 @@ TAesNiCcmKernel = class sealed(TInterfacedObject, IFusedCcmKernel) // multi-block SIMD loop. FEngine: IAesEngineX86; FRounds: Int32; - FDirection: TFusedModeDirection; + FDirection: TCipherKernelDirection; FMask: Pointer; FIncrement: Pointer; public constructor Create(const AEngine: IAesEngineX86; ARounds: Int32; - ADirection: TFusedModeDirection; AMask, AIncrement: Pointer); + ADirection: TCipherKernelDirection; AMask, AIncrement: Pointer); function MinimumBlockCount: Int32; procedure ProcessBody(AInPtr, AOutPtr, ACtrState, ACbcMacState: Pointer; ABlockCount: Int32); end; - TAesNiCcmKernelFactory = class sealed(TInterfacedObject, - IFusedCcmKernelFactory) + TAesNiCcmKernelFactory = class sealed(TCipherKernelFactoryBase, + ICcmKernelFactory) public - function ProviderName: String; - function Priority: TFusedKernelPriority; + function ProviderName: String; override; function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedCcmKernel): Boolean; + ADirection: TCipherKernelDirection; + out AKernel: ICcmKernel): Boolean; end; implementation @@ -200,7 +200,7 @@ procedure CcmFusedCtrCbcMacDec256(PCtx: Pointer); { TAesNiCcmKernel } constructor TAesNiCcmKernel.Create(const AEngine: IAesEngineX86; - ARounds: Int32; ADirection: TFusedModeDirection; + ARounds: Int32; ADirection: TCipherKernelDirection; AMask, AIncrement: Pointer); begin inherited Create; @@ -245,7 +245,7 @@ procedure TAesNiCcmKernel.ProcessBody(AInPtr, AOutPtr, ACtrState, LCtx.PMask := FMask; LCtx.PIncrement := FIncrement; LCtx.BlockCount := NativeUInt(ABlockCount); - if FDirection = TFusedModeDirection.Encrypt then + if FDirection = TCipherKernelDirection.Encrypt then begin case FRounds of 10: CcmFusedCtrCbcMacEnc128(@LCtx); @@ -273,13 +273,8 @@ function TAesNiCcmKernelFactory.ProviderName: String; Result := 'AES-NI'; end; -function TAesNiCcmKernelFactory.Priority: TFusedKernelPriority; -begin - Result := TFusedKernelPriority.Baseline; -end; - function TAesNiCcmKernelFactory.TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; out AKernel: IFusedCcmKernel): Boolean; + ADirection: TCipherKernelDirection; out AKernel: ICcmKernel): Boolean; var LEngine: IAesEngineX86; LKeys: PByte; @@ -312,7 +307,7 @@ function TAesNiCcmKernelFactory.TryCreate(const ACipher: IBlockCipher; end; initialization - TFusedKernelRegistry.RegisterCcmFactory( - TAesNiCcmKernelFactory.Create() as IFusedCcmKernelFactory); + TCipherKernelRegistry.Register( + TAesNiCcmKernelFactory.Create() as ICcmKernelFactory); end. diff --git a/CryptoLib/src/Crypto/Modes/Fused/ClpAesNiCtrKernel.pas b/CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiCtrKernel.pas similarity index 89% rename from CryptoLib/src/Crypto/Modes/Fused/ClpAesNiCtrKernel.pas rename to CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiCtrKernel.pas index 1321a903..5cccb0ed 100644 --- a/CryptoLib/src/Crypto/Modes/Fused/ClpAesNiCtrKernel.pas +++ b/CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiCtrKernel.pas @@ -24,14 +24,15 @@ interface SysUtils, ClpIBlockCipher, ClpIAesEngineX86, - ClpFusedKernelTypes, - ClpIFusedCtrKernel, - ClpFusedKernelRegistry, + ClpCipherKernelTypes, + ClpICtrKernel, + ClpCipherKernelFactoryBase, + ClpCipherKernelRegistry, ClpAesNiFusedX86Backend; type /// - /// AES-NI implementation of IFusedCtrKernel: the fused counter-mode + /// AES-NI implementation of ICtrKernel: the fused counter-mode /// keystream + XOR body used by TSicBlockCipher's bulk path. The MAC-free /// base of the fused-kernel family; reuses the plain 8-wide AES round chain /// (AesNiEightRoundsOnly) since CTR has no extra per-block state. @@ -39,7 +40,7 @@ interface /// both arms gated collectively by CRYPTOLIB_X86_SIMD. When unavailable the /// factory returns nil and TSicBlockCipher keeps its existing bulk path. /// - TAesNiCtrKernel = class sealed(TInterfacedObject, IFusedCtrKernel) + TAesNiCtrKernel = class sealed(TInterfacedObject, ICtrKernel) strict private const FUSED_CTR_BATCH_BLOCKS = 8; @@ -57,13 +58,12 @@ TAesNiCtrKernel = class sealed(TInterfacedObject, IFusedCtrKernel) ABlockCount: NativeInt); end; - TAesNiCtrKernelFactory = class sealed(TInterfacedObject, IFusedCtrKernelFactory) + TAesNiCtrKernelFactory = class sealed(TCipherKernelFactoryBase, ICtrKernelFactory) public - function ProviderName: String; - function Priority: TFusedKernelPriority; + function ProviderName: String; override; function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedCtrKernel): Boolean; + ADirection: TCipherKernelDirection; + out AKernel: ICtrKernel): Boolean; end; implementation @@ -173,13 +173,8 @@ function TAesNiCtrKernelFactory.ProviderName: String; Result := 'AES-NI'; end; -function TAesNiCtrKernelFactory.Priority: TFusedKernelPriority; -begin - Result := TFusedKernelPriority.Baseline; -end; - function TAesNiCtrKernelFactory.TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; out AKernel: IFusedCtrKernel): Boolean; + ADirection: TCipherKernelDirection; out AKernel: ICtrKernel): Boolean; var LEngine: IAesEngineX86; LKeys: PByte; @@ -205,7 +200,7 @@ function TAesNiCtrKernelFactory.TryCreate(const ACipher: IBlockCipher; end; initialization - TFusedKernelRegistry.RegisterCtrFactory( - TAesNiCtrKernelFactory.Create() as IFusedCtrKernelFactory); + TCipherKernelRegistry.Register( + TAesNiCtrKernelFactory.Create() as ICtrKernelFactory); end. diff --git a/CryptoLib/src/Crypto/Modes/Fused/ClpAesNiEaxKernel.pas b/CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiEaxKernel.pas similarity index 90% rename from CryptoLib/src/Crypto/Modes/Fused/ClpAesNiEaxKernel.pas rename to CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiEaxKernel.pas index 8b2bed9f..de35f412 100644 --- a/CryptoLib/src/Crypto/Modes/Fused/ClpAesNiEaxKernel.pas +++ b/CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiEaxKernel.pas @@ -24,15 +24,16 @@ interface SysUtils, ClpIBlockCipher, ClpIAesEngineX86, - ClpFusedKernelTypes, - ClpIFusedEaxKernel, - ClpFusedKernelRegistry, + ClpCipherKernelTypes, + ClpIEaxKernel, + ClpCipherKernelFactoryBase, + ClpCipherKernelRegistry, ClpAesFusedAeadSimd, ClpAesNiFusedX86Backend; type /// - /// AES-NI implementation of IFusedEaxKernel. + /// AES-NI implementation of IEaxKernel. /// Available on x86_64 (CRYPTOLIB_X86_64_ASM) and i386 /// (CRYPTOLIB_I386_ASM); both arms gated collectively by /// CRYPTOLIB_X86_SIMD. @@ -46,7 +47,7 @@ interface /// ships a fused EAX kernel (OpenSSL, BoringSSL, AWS-LC, Botan all /// scalar). /// - TAesNiEaxKernel = class sealed(TInterfacedObject, IFusedEaxKernel) + TAesNiEaxKernel = class sealed(TInterfacedObject, IEaxKernel) strict private const FUSED_EAX_MIN_BLOCKS = 2; @@ -54,25 +55,24 @@ TAesNiEaxKernel = class sealed(TInterfacedObject, IFusedEaxKernel) FEngine: IAesEngineX86; FKeys: Pointer; FRounds: Int32; - FDirection: TFusedModeDirection; + FDirection: TCipherKernelDirection; FMask: Pointer; FIncrement: Pointer; public constructor Create(const AEngine: IAesEngineX86; AKeys: Pointer; - ARounds: Int32; ADirection: TFusedModeDirection; AMask, AIncrement: Pointer); + ARounds: Int32; ADirection: TCipherKernelDirection; AMask, AIncrement: Pointer); function MinimumBlockCount: Int32; procedure ProcessBody(AInPtr, AOutPtr, ACtrState, AOmacState: Pointer; ABlockCount: Int32); end; - TAesNiEaxKernelFactory = class sealed(TInterfacedObject, - IFusedEaxKernelFactory) + TAesNiEaxKernelFactory = class sealed(TCipherKernelFactoryBase, + IEaxKernelFactory) public - function ProviderName: String; - function Priority: TFusedKernelPriority; + function ProviderName: String; override; function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedEaxKernel): Boolean; + ADirection: TCipherKernelDirection; + out AKernel: IEaxKernel): Boolean; end; implementation @@ -201,7 +201,7 @@ procedure EaxFusedCtrOmacDec256(PCtx: Pointer); { TAesNiEaxKernel } constructor TAesNiEaxKernel.Create(const AEngine: IAesEngineX86; - AKeys: Pointer; ARounds: Int32; ADirection: TFusedModeDirection; + AKeys: Pointer; ARounds: Int32; ADirection: TCipherKernelDirection; AMask, AIncrement: Pointer); begin inherited Create; @@ -236,7 +236,7 @@ procedure TAesNiEaxKernel.ProcessBody(AInPtr, AOutPtr, ACtrState, LCtx.PMask := FMask; LCtx.PIncrement := FIncrement; LCtx.BlockCount := NativeUInt(ABlockCount); - if FDirection = TFusedModeDirection.Encrypt then + if FDirection = TCipherKernelDirection.Encrypt then begin case FRounds of 10: EaxFusedCtrOmacEnc128(@LCtx); @@ -264,13 +264,8 @@ function TAesNiEaxKernelFactory.ProviderName: String; Result := 'AES-NI'; end; -function TAesNiEaxKernelFactory.Priority: TFusedKernelPriority; -begin - Result := TFusedKernelPriority.Baseline; -end; - function TAesNiEaxKernelFactory.TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; out AKernel: IFusedEaxKernel): Boolean; + ADirection: TCipherKernelDirection; out AKernel: IEaxKernel): Boolean; var LEngine: IAesEngineX86; LKeys: PByte; @@ -299,7 +294,7 @@ function TAesNiEaxKernelFactory.TryCreate(const ACipher: IBlockCipher; end; initialization - TFusedKernelRegistry.RegisterEaxFactory( - TAesNiEaxKernelFactory.Create() as IFusedEaxKernelFactory); + TCipherKernelRegistry.Register( + TAesNiEaxKernelFactory.Create() as IEaxKernelFactory); end. diff --git a/CryptoLib/src/Crypto/Modes/Fused/ClpAesNiGcmKernel.pas b/CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiGcmKernel.pas similarity index 90% rename from CryptoLib/src/Crypto/Modes/Fused/ClpAesNiGcmKernel.pas rename to CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiGcmKernel.pas index d2124fd1..56773b1d 100644 --- a/CryptoLib/src/Crypto/Modes/Fused/ClpAesNiGcmKernel.pas +++ b/CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiGcmKernel.pas @@ -24,15 +24,16 @@ interface SysUtils, ClpIBlockCipher, ClpIAesEngineX86, - ClpFusedKernelTypes, - ClpIFusedGcmKernel, - ClpFusedKernelRegistry, + ClpCipherKernelTypes, + ClpIGcmKernel, + ClpCipherKernelFactoryBase, + ClpCipherKernelRegistry, ClpAesFusedAeadSimd, ClpAesNiFusedX86Backend; type /// - /// AES-NI + PCLMULQDQ implementation of IFusedGcmKernel. + /// AES-NI + PCLMULQDQ implementation of IGcmKernel. /// Available on x86_64 (CRYPTOLIB_X86_64_ASM) and i386 /// (CRYPTOLIB_I386_ASM); both arms gated collectively by /// CRYPTOLIB_X86_SIMD. @@ -44,7 +45,7 @@ interface /// pipeline internally; the mode primes the first batch and drains the /// last. /// - TAesNiGcmKernel = class sealed(TInterfacedObject, IFusedGcmKernel) + TAesNiGcmKernel = class sealed(TInterfacedObject, IGcmKernel) strict private const FUSED_GCM_MIN_BLOCKS = 8; @@ -63,14 +64,13 @@ TAesNiGcmKernel = class sealed(TInterfacedObject, IFusedGcmKernel) AForEncrypt: Boolean): UInt32; end; - TAesNiGcmKernelFactory = class sealed(TInterfacedObject, - IFusedGcmKernelFactory) + TAesNiGcmKernelFactory = class sealed(TCipherKernelFactoryBase, + IGcmKernelFactory) public - function ProviderName: String; - function Priority: TFusedKernelPriority; + function ProviderName: String; override; function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; AHPowers: Pointer; - out AKernel: IFusedGcmKernel): Boolean; + ADirection: TCipherKernelDirection; AHPowers: Pointer; + out AKernel: IGcmKernel): Boolean; end; implementation @@ -204,14 +204,9 @@ function TAesNiGcmKernelFactory.ProviderName: String; Result := 'AES-NI'; end; -function TAesNiGcmKernelFactory.Priority: TFusedKernelPriority; -begin - Result := TFusedKernelPriority.Baseline; -end; - function TAesNiGcmKernelFactory.TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; AHPowers: Pointer; - out AKernel: IFusedGcmKernel): Boolean; + ADirection: TCipherKernelDirection; AHPowers: Pointer; + out AKernel: IGcmKernel): Boolean; var LEngine: IAesEngineX86; LKeys: PByte; @@ -242,7 +237,7 @@ function TAesNiGcmKernelFactory.TryCreate(const ACipher: IBlockCipher; end; initialization - TFusedKernelRegistry.RegisterGcmFactory( - TAesNiGcmKernelFactory.Create() as IFusedGcmKernelFactory); + TCipherKernelRegistry.Register( + TAesNiGcmKernelFactory.Create() as IGcmKernelFactory); end. diff --git a/CryptoLib/src/Crypto/Modes/Fused/ClpAesNiOcbKernel.pas b/CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiOcbKernel.pas similarity index 90% rename from CryptoLib/src/Crypto/Modes/Fused/ClpAesNiOcbKernel.pas rename to CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiOcbKernel.pas index e49d2db8..0aa6142f 100644 --- a/CryptoLib/src/Crypto/Modes/Fused/ClpAesNiOcbKernel.pas +++ b/CryptoLib/src/Crypto/CipherKernels/Block/ClpAesNiOcbKernel.pas @@ -24,15 +24,16 @@ interface SysUtils, ClpIBlockCipher, ClpIAesEngineX86, - ClpFusedKernelTypes, - ClpIFusedOcbKernel, - ClpFusedKernelRegistry, + ClpCipherKernelTypes, + ClpIOcbKernel, + ClpCipherKernelFactoryBase, + ClpCipherKernelRegistry, ClpAesFusedAeadSimd, ClpAesNiFusedX86Backend; type /// - /// AES-NI implementation of IFusedOcbKernel. + /// AES-NI implementation of IOcbKernel. /// Available on x86_64 (CRYPTOLIB_X86_64_ASM) and i386 /// (CRYPTOLIB_I386_ASM); both arms gated collectively by /// CRYPTOLIB_X86_SIMD. @@ -44,7 +45,7 @@ interface /// 4 blocks on i386) so the mode layer can amortise call-site /// overhead across large batches. /// - TAesNiOcbKernel = class sealed(TInterfacedObject, IFusedOcbKernel) + TAesNiOcbKernel = class sealed(TInterfacedObject, IOcbKernel) strict private const {$IFDEF CRYPTOLIB_X86_64_ASM} @@ -56,24 +57,23 @@ TAesNiOcbKernel = class sealed(TInterfacedObject, IFusedOcbKernel) FEngine: IAesEngineX86; FKeys: Pointer; FRounds: Int32; - FDirection: TFusedModeDirection; + FDirection: TCipherKernelDirection; public constructor Create(const AEngine: IAesEngineX86; AKeys: Pointer; - ARounds: Int32; ADirection: TFusedModeDirection); + ARounds: Int32; ADirection: TCipherKernelDirection); function MinimumBlockCount: Int32; procedure ProcessBlocks(AInPtr, AOutPtr, AOffsetPtr, AChecksumPtr, ALTablePtr, ABlock0Ptr: Pointer; ABlockCount: Int32; AStartBlockCount: UInt64); end; - TAesNiOcbKernelFactory = class sealed(TInterfacedObject, - IFusedOcbKernelFactory) + TAesNiOcbKernelFactory = class sealed(TCipherKernelFactoryBase, + IOcbKernelFactory) public - function ProviderName: String; - function Priority: TFusedKernelPriority; + function ProviderName: String; override; function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedOcbKernel): Boolean; + ADirection: TCipherKernelDirection; + out AKernel: IOcbKernel): Boolean; end; implementation @@ -196,7 +196,7 @@ procedure OcbFusedDecWide256(PCtx: Pointer); { TAesNiOcbKernel } constructor TAesNiOcbKernel.Create(const AEngine: IAesEngineX86; - AKeys: Pointer; ARounds: Int32; ADirection: TFusedModeDirection); + AKeys: Pointer; ARounds: Int32; ADirection: TCipherKernelDirection); begin inherited Create; FEngine := AEngine; @@ -231,7 +231,7 @@ procedure TAesNiOcbKernel.ProcessBlocks(AInPtr, AOutPtr, AOffsetPtr, LCtx.Block0Ptr := ABlock0Ptr; LCtx.BlockCount := NativeUInt(ABlockCount); LCtx.StartBlockCount := AStartBlockCount; - if FDirection = TFusedModeDirection.Encrypt then + if FDirection = TCipherKernelDirection.Encrypt then begin case FRounds of 10: OcbFusedEncWide128(@LCtx); @@ -259,13 +259,8 @@ function TAesNiOcbKernelFactory.ProviderName: String; Result := 'AES-NI'; end; -function TAesNiOcbKernelFactory.Priority: TFusedKernelPriority; -begin - Result := TFusedKernelPriority.Baseline; -end; - function TAesNiOcbKernelFactory.TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; out AKernel: IFusedOcbKernel): Boolean; + ADirection: TCipherKernelDirection; out AKernel: IOcbKernel): Boolean; var LEngine: IAesEngineX86; LKeys: PByte; @@ -279,7 +274,7 @@ function TAesNiOcbKernelFactory.TryCreate(const ACipher: IBlockCipher; Exit; if not TAesNiFusedX86Backend.TryResolveEngine(ACipher, LEngine) then Exit; - if ADirection = TFusedModeDirection.Encrypt then + if ADirection = TCipherKernelDirection.Encrypt then LHasSchedule := LEngine.TryGetEncKeysPtr(LKeys, LRounds) else LHasSchedule := LEngine.TryGetDecKeysPtr(LKeys, LRounds); @@ -296,7 +291,7 @@ function TAesNiOcbKernelFactory.TryCreate(const ACipher: IBlockCipher; end; initialization - TFusedKernelRegistry.RegisterOcbFactory( - TAesNiOcbKernelFactory.Create() as IFusedOcbKernelFactory); + TCipherKernelRegistry.Register( + TAesNiOcbKernelFactory.Create() as IOcbKernelFactory); end. diff --git a/CryptoLib/src/Crypto/Modes/Fused/ClpPclmulGcmSivKernel.pas b/CryptoLib/src/Crypto/CipherKernels/Block/ClpPclmulGcmSivKernel.pas similarity index 80% rename from CryptoLib/src/Crypto/Modes/Fused/ClpPclmulGcmSivKernel.pas rename to CryptoLib/src/Crypto/CipherKernels/Block/ClpPclmulGcmSivKernel.pas index 5c65e931..c99b1ce1 100644 --- a/CryptoLib/src/Crypto/Modes/Fused/ClpPclmulGcmSivKernel.pas +++ b/CryptoLib/src/Crypto/CipherKernels/Block/ClpPclmulGcmSivKernel.pas @@ -23,20 +23,21 @@ interface uses SysUtils, ClpIBlockCipher, - ClpFusedKernelTypes, - ClpIFusedGcmSivKernel, - ClpFusedKernelRegistry, + ClpCipherKernelTypes, + ClpIGcmSivKernel, + ClpCipherKernelFactoryBase, + ClpCipherKernelRegistry, ClpGcmSivSimd; type /// - /// PCLMULQDQ implementation of IFusedGcmSivKernel. Pure + /// PCLMULQDQ implementation of IGcmSivKernel. Pure /// POLYVAL: the factory ignores ACipher identity and only requires /// a valid pre-computed H-power table from the caller. Ships on /// both x86_64 and i386. /// TPclmulGcmSivKernel = class sealed(TInterfacedObject, - IFusedGcmSivKernel) + IGcmSivKernel) strict private const FUSED_POLYVAL_MIN_BLOCKS = 8; @@ -50,14 +51,13 @@ TPclmulGcmSivKernel = class sealed(TInterfacedObject, ABlockCount: Int32); end; - TPclmulGcmSivKernelFactory = class sealed(TInterfacedObject, - IFusedGcmSivKernelFactory) + TPclmulGcmSivKernelFactory = class sealed(TCipherKernelFactoryBase, + IGcmSivKernelFactory) public - function ProviderName: String; - function Priority: TFusedKernelPriority; + function ProviderName: String; override; function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; AHPowers: Pointer; - out AKernel: IFusedGcmSivKernel): Boolean; + ADirection: TCipherKernelDirection; AHPowers: Pointer; + out AKernel: IGcmSivKernel): Boolean; end; implementation @@ -97,14 +97,9 @@ function TPclmulGcmSivKernelFactory.ProviderName: String; Result := 'PCLMULQDQ'; end; -function TPclmulGcmSivKernelFactory.Priority: TFusedKernelPriority; -begin - Result := TFusedKernelPriority.Baseline; -end; - function TPclmulGcmSivKernelFactory.TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; AHPowers: Pointer; - out AKernel: IFusedGcmSivKernel): Boolean; + ADirection: TCipherKernelDirection; AHPowers: Pointer; + out AKernel: IGcmSivKernel): Boolean; begin AKernel := nil; Result := False; @@ -123,7 +118,7 @@ function TPclmulGcmSivKernelFactory.TryCreate(const ACipher: IBlockCipher; end; initialization - TFusedKernelRegistry.RegisterGcmSivFactory( - TPclmulGcmSivKernelFactory.Create() as IFusedGcmSivKernelFactory); + TCipherKernelRegistry.Register( + TPclmulGcmSivKernelFactory.Create() as IGcmSivKernelFactory); end. diff --git a/CryptoLib/src/Crypto/Modes/Fused/Internal/ClpAesFusedAeadSimd.pas b/CryptoLib/src/Crypto/CipherKernels/Block/Internal/ClpAesFusedAeadSimd.pas similarity index 100% rename from CryptoLib/src/Crypto/Modes/Fused/Internal/ClpAesFusedAeadSimd.pas rename to CryptoLib/src/Crypto/CipherKernels/Block/Internal/ClpAesFusedAeadSimd.pas diff --git a/CryptoLib/src/Crypto/Modes/Fused/Internal/ClpAesNiFusedX86Backend.pas b/CryptoLib/src/Crypto/CipherKernels/Block/Internal/ClpAesNiFusedX86Backend.pas similarity index 100% rename from CryptoLib/src/Crypto/Modes/Fused/Internal/ClpAesNiFusedX86Backend.pas rename to CryptoLib/src/Crypto/CipherKernels/Block/Internal/ClpAesNiFusedX86Backend.pas diff --git a/CryptoLib/src/Crypto/Modes/Fused/ClpFusedKernelDefaults.pas b/CryptoLib/src/Crypto/CipherKernels/ClpCipherKernelDefaults.pas similarity index 93% rename from CryptoLib/src/Crypto/Modes/Fused/ClpFusedKernelDefaults.pas rename to CryptoLib/src/Crypto/CipherKernels/ClpCipherKernelDefaults.pas index 0f2ef3f6..55da86f8 100644 --- a/CryptoLib/src/Crypto/Modes/Fused/ClpFusedKernelDefaults.pas +++ b/CryptoLib/src/Crypto/CipherKernels/ClpCipherKernelDefaults.pas @@ -14,11 +14,11 @@ (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) -unit ClpFusedKernelDefaults; +unit ClpCipherKernelDefaults; -{$I ..\..\..\Include\CryptoLib.inc} +{$I ..\..\Include\CryptoLib.inc} -// Aggregator for CryptoLib's in-tree fused AEAD kernel factories. +// Aggregator for CryptoLib's in-tree cipher kernel factories. // Listed factory units self-gate on their own CPU/arch defines, so // this file is a plain, platform-agnostic list: adding a new in-tree // accelerator is one `uses` line here, mode units are never touched. diff --git a/CryptoLib/src/Crypto/CipherKernels/ClpCipherKernelFactoryBase.pas b/CryptoLib/src/Crypto/CipherKernels/ClpCipherKernelFactoryBase.pas new file mode 100644 index 00000000..2e14bff4 --- /dev/null +++ b/CryptoLib/src/Crypto/CipherKernels/ClpCipherKernelFactoryBase.pas @@ -0,0 +1,51 @@ +{ *********************************************************************************** } +{ * CryptoLib Library * } +{ * Author - Ugochukwu Mmaduekwe * } +{ * Github Repository * } +{ * * } +{ * Distributed under the MIT software license, see the accompanying file LICENSE * } +{ * or visit http://www.opensource.org/licenses/mit-license.php. * } +{ * * } +{ * Acknowledgements: * } +{ * * } +{ * Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring * } +{ * the development of this library * } +{ * ******************************************************************************* * } + +(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) + +unit ClpCipherKernelFactoryBase; + +{$I ..\..\Include\CryptoLib.inc} + +interface + +uses + ClpCipherKernelTypes; + +type + /// + /// Shared base for cipher-kernel factory classes. ProviderName is + /// abstract - each concrete factory must declare its own provider identity + /// (there is no generic default). Priority defaults to Baseline, a neutral + /// value a factory overrides only when it should out- or under-rank peers. + /// The base intentionally declares no interface - each concrete factory + /// lists its own I<Mode>KernelFactory, and these members + /// satisfy the base slice of that contract. + /// + TCipherKernelFactoryBase = class abstract(TInterfacedObject) + public + function ProviderName: String; virtual; abstract; + function Priority: TCipherKernelPriority; virtual; + end; + +implementation + +{ TCipherKernelFactoryBase } + +function TCipherKernelFactoryBase.Priority: TCipherKernelPriority; +begin + Result := TCipherKernelPriority.Baseline; +end; + +end. diff --git a/CryptoLib/src/Crypto/CipherKernels/ClpCipherKernelRegistry.pas b/CryptoLib/src/Crypto/CipherKernels/ClpCipherKernelRegistry.pas new file mode 100644 index 00000000..d3587e2c --- /dev/null +++ b/CryptoLib/src/Crypto/CipherKernels/ClpCipherKernelRegistry.pas @@ -0,0 +1,407 @@ +{ *********************************************************************************** } +{ * CryptoLib Library * } +{ * Author - Ugochukwu Mmaduekwe * } +{ * Github Repository * } +{ * * } +{ * Distributed under the MIT software license, see the accompanying file LICENSE * } +{ * or visit http://www.opensource.org/licenses/mit-license.php. * } +{ * * } +{ * Acknowledgements: * } +{ * * } +{ * Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring * } +{ * the development of this library * } +{ * ******************************************************************************* * } + +(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) + +unit ClpCipherKernelRegistry; + +{$I ..\..\Include\CryptoLib.inc} + +interface + +uses + SysUtils, + SyncObjs, + Generics.Collections, + ClpIBlockCipher, + ClpCryptoLibTypes, + ClpCipherKernelTypes, + ClpICipherKernelFactory, + ClpIGcmKernel, + ClpIOcbKernel, + ClpICcmKernel, + ClpIEaxKernel, + ClpIGcmSivKernel, + ClpICtrKernel, + ClpICbcKernel, + ClpIStreamCipher, + ClpIChaCha20Poly1305Kernel; + +type + /// + /// Process-wide kill switch for every registered cipher kernel. When + /// ForceDisabled is True, every TryAcquireX returns False without walking + /// the factory list, so modes route through their scalar fallbacks. Used by + /// the dual-path test harness to prove both paths agree byte-for-byte. + /// + TCipherKernelGate = class sealed(TObject) + strict private + class var FForceDisabled: Boolean; + public + class property ForceDisabled: Boolean read FForceDisabled write FForceDisabled; + end; + + /// + /// Open, priority-ordered resolver for the whole cipher-kernel family. Every + /// factory - block-cipher AEAD or stream-cipher AEAD alike - is registered + /// through the family-agnostic ICipherKernelFactory into a single + /// priority-sorted list (highest Priority first; equal priorities keep + /// registration order). A per-mode TryAcquireX re-discovers the concrete + /// family with Supports() and calls its typed TryCreate. An external + /// consumer registers its own I<X>KernelFactory and resolves it + /// through the public GetSnapshot + a Supports walk - no framework edit and + /// no central enum. Thread-safe: one TCriticalSection guards mutation and + /// snapshotting; TryAcquireX snapshots under the lock then releases it before + /// invoking factory TryCreate, so factory work never serialises other call + /// sites. + /// + TCipherKernelRegistry = class sealed(TObject) + strict private + class var FLock: TCriticalSection; + class var FFactories: TList; + class function Snapshot: TCryptoLibGenericArray; static; + class constructor Create; + class destructor Destroy; + public + /// Register a factory of any family. Insertion keeps the single + /// list sorted by Ord(Priority) descending; equal priorities retain + /// registration order. Duplicate registrations (same interface identity) + /// are silently ignored. + class procedure Register(const AFactory: ICipherKernelFactory); static; + /// Remove AFactory. No-op if not registered. + class procedure Unregister(const AFactory: ICipherKernelFactory); static; + /// Priority-ordered snapshot of every registered factory. External + /// consumers filter it with Supports() to their own factory interface to + /// resolve a cipher kernel the framework never enumerated. + class function GetSnapshot: TCryptoLibGenericArray; static; + + class function TryAcquireGcm(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; AHPowers: Pointer; + out AKernel: IGcmKernel): Boolean; static; + class function TryAcquireOcb(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; out AKernel: IOcbKernel): Boolean; static; + class function TryAcquireCcm(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; out AKernel: ICcmKernel): Boolean; static; + class function TryAcquireEax(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; out AKernel: IEaxKernel): Boolean; static; + class function TryAcquireGcmSiv(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; AHPowers: Pointer; + out AKernel: IGcmSivKernel): Boolean; static; + class function TryAcquireCtr(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; out AKernel: ICtrKernel): Boolean; static; + class function TryAcquireCbc(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; out AKernel: ICbcKernel): Boolean; static; + class function TryAcquireChaCha20Poly1305(const ACipher: IStreamCipher; + ADirection: TCipherKernelDirection; out AKernel: IChaCha20Poly1305Kernel): Boolean; static; + + /// Provider-name list (priority order) of every registered factory + /// supporting AFactoryIID. Pass a per-mode factory interface, e.g. + /// GetRegisteredProviders(IGcmKernelFactory). Diagnostics/tests. + class function GetRegisteredProviders(const AFactoryIID: TGUID): TCryptoLibStringArray; static; + end; + +implementation + +{ TCipherKernelRegistry } + +class constructor TCipherKernelRegistry.Create; +begin + FLock := TCriticalSection.Create; + FFactories := TList.Create; +end; + +class destructor TCipherKernelRegistry.Destroy; +begin + FFactories.Free; + FLock.Free; +end; + +class procedure TCipherKernelRegistry.Register(const AFactory: ICipherKernelFactory); +var + LI, LPriority: Int32; + LInserted: Boolean; +begin + if AFactory = nil then Exit; + FLock.Enter; + try + if FFactories.IndexOf(AFactory) >= 0 then Exit; + LPriority := Ord(AFactory.Priority); + LInserted := False; + for LI := 0 to FFactories.Count - 1 do + begin + if LPriority > Ord(FFactories[LI].Priority) then + begin + FFactories.Insert(LI, AFactory); + LInserted := True; + Break; + end; + end; + if not LInserted then + FFactories.Add(AFactory); + finally + FLock.Leave; + end; +end; + +class procedure TCipherKernelRegistry.Unregister(const AFactory: ICipherKernelFactory); +var + LIdx: Int32; +begin + if AFactory = nil then Exit; + FLock.Enter; + try + LIdx := FFactories.IndexOf(AFactory); + if LIdx >= 0 then + FFactories.Delete(LIdx); + finally + FLock.Leave; + end; +end; + +class function TCipherKernelRegistry.Snapshot: TCryptoLibGenericArray; +var + LI, LCount: Int32; +begin + FLock.Enter; + try + LCount := FFactories.Count; + System.SetLength(Result, LCount); + for LI := 0 to LCount - 1 do + Result[LI] := FFactories[LI]; + finally + FLock.Leave; + end; +end; + +class function TCipherKernelRegistry.GetSnapshot: TCryptoLibGenericArray; +begin + Result := Snapshot; +end; + +{ ---- TryAcquire ------------------------------------------------------------- } + +class function TCipherKernelRegistry.TryAcquireGcm(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; AHPowers: Pointer; + out AKernel: IGcmKernel): Boolean; +var + LSnap: TCryptoLibGenericArray; + LI: Int32; + LFac: IGcmKernelFactory; +begin + AKernel := nil; + Result := False; + if TCipherKernelGate.ForceDisabled then Exit; + if ACipher = nil then Exit; + if AHPowers = nil then Exit; + LSnap := Snapshot; + for LI := 0 to System.Length(LSnap) - 1 do + begin + if Supports(LSnap[LI], IGcmKernelFactory, LFac) and + LFac.TryCreate(ACipher, ADirection, AHPowers, AKernel) and (AKernel <> nil) then + begin + Result := True; + Exit; + end; + end; + AKernel := nil; +end; + +class function TCipherKernelRegistry.TryAcquireOcb(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; out AKernel: IOcbKernel): Boolean; +var + LSnap: TCryptoLibGenericArray; + LI: Int32; + LFac: IOcbKernelFactory; +begin + AKernel := nil; + Result := False; + if TCipherKernelGate.ForceDisabled then Exit; + if ACipher = nil then Exit; + LSnap := Snapshot; + for LI := 0 to System.Length(LSnap) - 1 do + begin + if Supports(LSnap[LI], IOcbKernelFactory, LFac) and + LFac.TryCreate(ACipher, ADirection, AKernel) and (AKernel <> nil) then + begin + Result := True; + Exit; + end; + end; + AKernel := nil; +end; + +class function TCipherKernelRegistry.TryAcquireCcm(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; out AKernel: ICcmKernel): Boolean; +var + LSnap: TCryptoLibGenericArray; + LI: Int32; + LFac: ICcmKernelFactory; +begin + AKernel := nil; + Result := False; + if TCipherKernelGate.ForceDisabled then Exit; + if ACipher = nil then Exit; + LSnap := Snapshot; + for LI := 0 to System.Length(LSnap) - 1 do + begin + if Supports(LSnap[LI], ICcmKernelFactory, LFac) and + LFac.TryCreate(ACipher, ADirection, AKernel) and (AKernel <> nil) then + begin + Result := True; + Exit; + end; + end; + AKernel := nil; +end; + +class function TCipherKernelRegistry.TryAcquireEax(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; out AKernel: IEaxKernel): Boolean; +var + LSnap: TCryptoLibGenericArray; + LI: Int32; + LFac: IEaxKernelFactory; +begin + AKernel := nil; + Result := False; + if TCipherKernelGate.ForceDisabled then Exit; + if ACipher = nil then Exit; + LSnap := Snapshot; + for LI := 0 to System.Length(LSnap) - 1 do + begin + if Supports(LSnap[LI], IEaxKernelFactory, LFac) and + LFac.TryCreate(ACipher, ADirection, AKernel) and (AKernel <> nil) then + begin + Result := True; + Exit; + end; + end; + AKernel := nil; +end; + +class function TCipherKernelRegistry.TryAcquireGcmSiv(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; AHPowers: Pointer; + out AKernel: IGcmSivKernel): Boolean; +var + LSnap: TCryptoLibGenericArray; + LI: Int32; + LFac: IGcmSivKernelFactory; +begin + AKernel := nil; + Result := False; + if TCipherKernelGate.ForceDisabled then Exit; + if AHPowers = nil then Exit; + LSnap := Snapshot; + for LI := 0 to System.Length(LSnap) - 1 do + begin + if Supports(LSnap[LI], IGcmSivKernelFactory, LFac) and + LFac.TryCreate(ACipher, ADirection, AHPowers, AKernel) and (AKernel <> nil) then + begin + Result := True; + Exit; + end; + end; + AKernel := nil; +end; + +class function TCipherKernelRegistry.TryAcquireCtr(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; out AKernel: ICtrKernel): Boolean; +var + LSnap: TCryptoLibGenericArray; + LI: Int32; + LFac: ICtrKernelFactory; +begin + AKernel := nil; + Result := False; + if TCipherKernelGate.ForceDisabled then Exit; + if ACipher = nil then Exit; + LSnap := Snapshot; + for LI := 0 to System.Length(LSnap) - 1 do + begin + if Supports(LSnap[LI], ICtrKernelFactory, LFac) and + LFac.TryCreate(ACipher, ADirection, AKernel) and (AKernel <> nil) then + begin + Result := True; + Exit; + end; + end; + AKernel := nil; +end; + +class function TCipherKernelRegistry.TryAcquireCbc(const ACipher: IBlockCipher; + ADirection: TCipherKernelDirection; out AKernel: ICbcKernel): Boolean; +var + LSnap: TCryptoLibGenericArray; + LI: Int32; + LFac: ICbcKernelFactory; +begin + AKernel := nil; + Result := False; + if TCipherKernelGate.ForceDisabled then Exit; + if ACipher = nil then Exit; + LSnap := Snapshot; + for LI := 0 to System.Length(LSnap) - 1 do + begin + if Supports(LSnap[LI], ICbcKernelFactory, LFac) and + LFac.TryCreate(ACipher, ADirection, AKernel) and (AKernel <> nil) then + begin + Result := True; + Exit; + end; + end; + AKernel := nil; +end; + +class function TCipherKernelRegistry.TryAcquireChaCha20Poly1305(const ACipher: IStreamCipher; + ADirection: TCipherKernelDirection; out AKernel: IChaCha20Poly1305Kernel): Boolean; +var + LSnap: TCryptoLibGenericArray; + LI: Int32; + LFac: IChaCha20Poly1305KernelFactory; +begin + AKernel := nil; + Result := False; + if TCipherKernelGate.ForceDisabled then Exit; + if ACipher = nil then Exit; + LSnap := Snapshot; + for LI := 0 to System.Length(LSnap) - 1 do + begin + if Supports(LSnap[LI], IChaCha20Poly1305KernelFactory, LFac) and + LFac.TryCreate(ACipher, ADirection, AKernel) and (AKernel <> nil) then + begin + Result := True; + Exit; + end; + end; + AKernel := nil; +end; + +class function TCipherKernelRegistry.GetRegisteredProviders( + const AFactoryIID: TGUID): TCryptoLibStringArray; +var + LSnap: TCryptoLibGenericArray; + LI, LN: Int32; +begin + LSnap := Snapshot; + Result := nil; + LN := 0; + for LI := 0 to System.Length(LSnap) - 1 do + if Supports(LSnap[LI], AFactoryIID) then + begin + System.SetLength(Result, LN + 1); + Result[LN] := LSnap[LI].ProviderName; + Inc(LN); + end; +end; + +end. diff --git a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpFusedKernelTypes.pas b/CryptoLib/src/Crypto/CipherKernels/ClpCipherKernelTypes.pas similarity index 61% rename from CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpFusedKernelTypes.pas rename to CryptoLib/src/Crypto/CipherKernels/ClpCipherKernelTypes.pas index 44381b62..902922ef 100644 --- a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpFusedKernelTypes.pas +++ b/CryptoLib/src/Crypto/CipherKernels/ClpCipherKernelTypes.pas @@ -14,33 +14,37 @@ (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) -unit ClpFusedKernelTypes; +unit ClpCipherKernelTypes; -{$I ..\..\..\..\Include\CryptoLib.inc} +{$I ..\..\Include\CryptoLib.inc} interface type /// - /// Direction a fused AEAD kernel is being constructed for. Modes + /// Direction a cipher kernel is being constructed for. Modes /// whose hot path is direction-agnostic may pass Encrypt for both /// cases. /// - TFusedModeDirection = (Encrypt, Decrypt); + TCipherKernelDirection = (Encrypt, Decrypt); /// - /// Priority class used to order factories in the fused AEAD kernel - /// registry. Higher ordinal wins; equal priorities retain - /// registration order. + /// Priority class used to order factories in the cipher kernel + /// registry. Higher ordinal wins; equal priorities retain registration + /// order (first registered wins), which is why UserOverride sits above + /// Preferred - it keeps the consumer's explicit choice the final word + /// regardless of plug-in load order. /// Fallback - opt-in experimental / diagnostic kernel; loses - /// to anything else. + /// to anything else (never wins over a real kernel). /// Baseline - in-tree built-in accelerators. - /// Accelerated - external plug-in targeting a newer ISA - /// extension than the in-tree baseline. + /// Preferred - a self-registering kernel that should outrank the + /// in-tree baseline when present (e.g. an external + /// plug-in for a newer ISA extension), yet still yield + /// to the consumer's explicit override. /// UserOverride - last-resort explicit override wired in by the - /// consumer (application or test harness). + /// consumer (application or test harness); beats all. /// - TFusedKernelPriority = (Fallback, Baseline, Accelerated, UserOverride); + TCipherKernelPriority = (Fallback, Baseline, Preferred, UserOverride); implementation diff --git a/CryptoLib/src/Crypto/Engines/ClpAesEngineX86.pas b/CryptoLib/src/Crypto/Engines/ClpAesEngineX86.pas index 8461ee63..2c43d4f3 100644 --- a/CryptoLib/src/Crypto/Engines/ClpAesEngineX86.pas +++ b/CryptoLib/src/Crypto/Engines/ClpAesEngineX86.pas @@ -114,15 +114,15 @@ TAesEngineX86 = class sealed(TInterfacedObject, IAesEngineX86, IAesHardwareEng /// /// Internal fast-path accessor for the AES-NI encrypt round-key schedule - /// used by the fused GCM + AES-NI pipeline kernel. Returns True (and sets - /// AKeysPtr to the aligned key-schedule buffer plus ANumRounds to the AES - /// round count) only when the engine is currently initialized for AES - /// encryption in any supported key size (AForEncryption=True; ANumRounds - /// in {10, 12, 14} for AES-128 / AES-192 / AES-256 respectively). Returns - /// False in every other state (including all decrypt-direction inits). - /// Note: GCM always uses AES in encrypt mode for CTR keystream generation, - /// regardless of whether the GCM caller is encrypting or decrypting; this - /// accessor therefore deliberately rejects only AES-side decrypt inits. + /// used by the AES-NI fused cipher kernels. Returns True (and sets AKeysPtr + /// to the aligned key-schedule buffer plus ANumRounds to the AES round + /// count) only when the engine is currently initialized for AES encryption + /// in any supported key size (AForEncryption=True; ANumRounds in {10, 12, + /// 14} for AES-128 / AES-192 / AES-256 respectively). Returns False in every + /// other state (including all decrypt-direction inits). Note: the fused + /// modes built on this accessor drive AES in encrypt mode for keystream + /// generation regardless of the AEAD direction, so it rejects decrypt inits; + /// kernels needing the decrypt schedule use TryGetDecKeysPtr instead. /// Callers MUST NOT retain the pointer beyond the lifetime of the current /// engine init; reinit / free invalidates it. /// @@ -1143,9 +1143,9 @@ function TAesEngineX86.ProcessBlocks(AInput, AOutput: PByte; end; // ===================================================================== -// Key-schedule accessor used by the fused AES-NI + GHASH pipeline in -// TGcmBlockCipher. Returns a pointer to the round-key schedule only when -// the engine is in an AES-encrypt mode with a matching round count. +// Key-schedule accessors used by the AES-NI fused cipher kernels. Return a +// pointer to the round-key schedule only when the engine is in the requested +// direction with a matching round count. // ===================================================================== function TAesEngineX86.TryGetEncKeysPtr(out AKeysPtr: PByte; out ANumRounds: Int32): Boolean; diff --git a/CryptoLib/src/Crypto/Modes/ClpCbcBlockCipher.pas b/CryptoLib/src/Crypto/Modes/ClpCbcBlockCipher.pas index 172a3703..f9f674c9 100644 --- a/CryptoLib/src/Crypto/Modes/ClpCbcBlockCipher.pas +++ b/CryptoLib/src/Crypto/Modes/ClpCbcBlockCipher.pas @@ -30,9 +30,9 @@ interface ClpICipherParameters, ClpIParametersWithIV, ClpBlockCipherBulkUtilities, - ClpFusedKernelTypes, - ClpIFusedCbcKernel, - ClpFusedKernelRegistry, + ClpCipherKernelTypes, + ClpICbcKernel, + ClpCipherKernelRegistry, ClpArrayUtilities, ClpByteUtilities, ClpCryptoLibTypes; @@ -76,7 +76,7 @@ TCbcBlockCipher = class sealed(TInterfacedObject, ICbcBlockCipher, // C[i] = E(P[i] xor C[i-1]) in one call with the chaining value held in a // register, replacing the per-block dispatch loop. nil otherwise -- // CbcEncryptBulk keeps its per-block path. - FCbcKernel: IFusedCbcKernel; + FCbcKernel: ICbcKernel; function EncryptBlock(const AInput: TCryptoLibByteArray; AInOff: Int32; const AOutBytes: TCryptoLibByteArray; AOutOff: Int32): Int32; @@ -347,7 +347,7 @@ procedure TCbcBlockCipher.Init(AForEncryption: Boolean; // provider claims FCipher. Encrypt-only: CBC decrypt is parallel and already // served by the bulk engine's 8-wide path. if FEncrypting then - TFusedKernelRegistry.TryAcquireCbc(FCipher, TFusedModeDirection.Encrypt, + TCipherKernelRegistry.TryAcquireCbc(FCipher, TCipherKernelDirection.Encrypt, FCbcKernel) else FCbcKernel := nil; diff --git a/CryptoLib/src/Crypto/Modes/ClpCcmBlockCipher.pas b/CryptoLib/src/Crypto/Modes/ClpCcmBlockCipher.pas index 6ee3767f..3def6d53 100644 --- a/CryptoLib/src/Crypto/Modes/ClpCcmBlockCipher.pas +++ b/CryptoLib/src/Crypto/Modes/ClpCcmBlockCipher.pas @@ -33,10 +33,10 @@ interface ClpISicBlockCipher, ClpIBulkBlockCipherMode, ClpBlockCipherBulkUtilities, - ClpFusedKernelTypes, - ClpIFusedCcmKernel, - ClpFusedKernelRegistry, - ClpFusedKernelDefaults, // registers in-tree fused AEAD kernel factories + ClpCipherKernelTypes, + ClpICcmKernel, + ClpCipherKernelRegistry, + ClpCipherKernelDefaults, // registers in-tree fused AEAD kernel factories ClpCipherModeParameterUtilities, ClpIKeyParameter, ClpCbcBlockCipherMac, @@ -118,7 +118,7 @@ TCcmBlockCipher = class(TInterfacedObject, ICcmBlockCipher, FPlainScratch: TCryptoLibByteArray; // Cached once per Init; non-nil when the registry resolved a fused // CCM kernel for the underlying cipher and current direction. - FCcmKernel: IFusedCcmKernel; + FCcmKernel: ICcmKernel; class function GetMacSize(ARequestedMacBits: Int32): Int32; static; procedure CheckNonceReuse(AForEncryption: Boolean; @@ -232,7 +232,7 @@ procedure TCcmBlockCipher.Init(AForEncryption: Boolean; var LChoice: TCipherAeadChoice; LRequestedMacSizeBits: Int32; - LDirection: TFusedModeDirection; + LDirection: TCipherKernelDirection; begin FForEncryption := AForEncryption; @@ -272,10 +272,10 @@ procedure TCcmBlockCipher.Init(AForEncryption: Boolean; // schedule contents are identical across those re-keys. FCipher.Init(True, FKeyParam); if AForEncryption then - LDirection := TFusedModeDirection.Encrypt + LDirection := TCipherKernelDirection.Encrypt else - LDirection := TFusedModeDirection.Decrypt; - TFusedKernelRegistry.TryAcquireCcm(FCipher, LDirection, FCcmKernel); + LDirection := TCipherKernelDirection.Decrypt; + TCipherKernelRegistry.TryAcquireCcm(FCipher, LDirection, FCcmKernel); end; Reset(); diff --git a/CryptoLib/src/Crypto/Modes/ClpChaCha20Poly1305.pas b/CryptoLib/src/Crypto/Modes/ClpChaCha20Poly1305.pas index 7beb4cdf..4193c979 100644 --- a/CryptoLib/src/Crypto/Modes/ClpChaCha20Poly1305.pas +++ b/CryptoLib/src/Crypto/Modes/ClpChaCha20Poly1305.pas @@ -31,6 +31,9 @@ interface ClpIBulkStreamCipher, ClpIChaCha7539Engine, ClpChaCha7539Engine, + ClpCipherKernelTypes, + ClpCipherKernelRegistry, + ClpIChaCha20Poly1305Kernel, ClpPoly1305, ClpIMac, ClpKeyParameter, @@ -111,6 +114,9 @@ TChaCha20Poly1305 = class(TInterfacedObject, IChaCha20Poly1305, IAeadCipher) // The cipher engine's bulk stream interface when it exposes one (resolved once); // enables the 512B/8-way tier. nil => the narrower per-tier path is used. FBulkChaCha: IBulkStreamCipher; + // A registered ChaCha20-Poly1305 kernel, resolved once at Init. + // the two-pass cipher-then-MAC path runs. + FChaChaKernel: IChaCha20Poly1305Kernel; FNonceBytes: Int32; FPoly1305: IMac; @@ -283,6 +289,13 @@ procedure TChaCha20Poly1305.Init(AForEncryption: Boolean; FChaCha20.Init(True, LChaCha20Params); + if AForEncryption then + TCipherKernelRegistry.TryAcquireChaCha20Poly1305(FChaCha20, + TCipherKernelDirection.Encrypt, FChaChaKernel) + else + TCipherKernelRegistry.TryAcquireChaCha20Poly1305(FChaCha20, + TCipherKernelDirection.Decrypt, FChaChaKernel); + if AForEncryption then FState := TState.EncInit else diff --git a/CryptoLib/src/Crypto/Modes/ClpEaxBlockCipher.pas b/CryptoLib/src/Crypto/Modes/ClpEaxBlockCipher.pas index fb4971c4..d9f2a0e1 100644 --- a/CryptoLib/src/Crypto/Modes/ClpEaxBlockCipher.pas +++ b/CryptoLib/src/Crypto/Modes/ClpEaxBlockCipher.pas @@ -33,10 +33,10 @@ interface ClpISicBlockCipher, ClpIBulkBlockCipherMode, ClpBlockCipherBulkUtilities, - ClpFusedKernelTypes, - ClpIFusedEaxKernel, - ClpFusedKernelRegistry, - ClpFusedKernelDefaults, // registers in-tree fused AEAD kernel factories + ClpCipherKernelTypes, + ClpIEaxKernel, + ClpCipherKernelRegistry, + ClpCipherKernelDefaults, // registers in-tree fused AEAD kernel factories ClpCipherModeParameterUtilities, ClpIKeyParameter, ClpCMac, @@ -96,7 +96,7 @@ TEaxBlockCipher = class(TInterfacedObject, IEaxBlockCipher, // EAX kernel for the underlying cipher and encrypt direction. Decrypt // and non-AES ciphers stay on the TCMac / TSicBlockCipher scalar // path; set via FUseFusedBody below. - FEaxKernel: IFusedEaxKernel; + FEaxKernel: IEaxKernel; // True iff a fused body kernel is live for this Init cycle. Gates // the mode-owned OMAC substrate (FOmac* + FCtrBlock) against the @@ -311,11 +311,11 @@ procedure TEaxBlockCipher.Init(AForEncryption: Boolean; // TCMac / TSicBlockCipher path runs - no compile-time arch gating needed. FEaxKernel := nil; if FForEncryption then - TFusedKernelRegistry.TryAcquireEax(FCipher, - TFusedModeDirection.Encrypt, FEaxKernel) + TCipherKernelRegistry.TryAcquireEax(FCipher, + TCipherKernelDirection.Encrypt, FEaxKernel) else - TFusedKernelRegistry.TryAcquireEax(FCipher, - TFusedModeDirection.Decrypt, FEaxKernel); + TCipherKernelRegistry.TryAcquireEax(FCipher, + TCipherKernelDirection.Decrypt, FEaxKernel); FUseFusedBody := FEaxKernel <> nil; if FUseFusedBody then diff --git a/CryptoLib/src/Crypto/Modes/ClpGcmBlockCipher.pas b/CryptoLib/src/Crypto/Modes/ClpGcmBlockCipher.pas index 0f48f6fa..bfacaa53 100644 --- a/CryptoLib/src/Crypto/Modes/ClpGcmBlockCipher.pas +++ b/CryptoLib/src/Crypto/Modes/ClpGcmBlockCipher.pas @@ -40,10 +40,10 @@ interface ClpIBulkBlockCipher, ClpBlockCipherBulkUtilities, ClpByteUtilities, - ClpFusedKernelTypes, - ClpIFusedGcmKernel, - ClpFusedKernelRegistry, - ClpFusedKernelDefaults, // registers in-tree fused AEAD kernel factories + ClpCipherKernelTypes, + ClpIGcmKernel, + ClpCipherKernelRegistry, + ClpCipherKernelDefaults, // registers in-tree fused AEAD kernel factories ClpPack, ClpCheck, ClpBasicGcmMultiplier, @@ -106,11 +106,11 @@ TGcmBlockCipher = class(TInterfacedObject, IGcmBlockCipher, // exposes the generic IBulkBlockCipher capability. Drives the // non-fused 4/8-block CTR dispatchers (GetNextCtrBlocks4/8). FBulkCipher: IBulkBlockCipher; - // Fused CTR+GHASH kernel resolved via TFusedKernelRegistry at Init + // Fused CTR+GHASH kernel resolved via TCipherKernelRegistry at Init // time. Non-nil only when an accelerator factory accepts the - // underlying cipher + direction and the fused gate is open (always nil - // off-SIMD; IFusedGcmKernel is arch-neutral). - FGcmKernel: IFusedGcmKernel; + // underlying cipher + direction and the cipher-kernel gate is open (always nil + // off-SIMD; IGcmKernel is arch-neutral). + FGcmKernel: IGcmKernel; FGcmKernelMinBlocks: Int32; FMultiplier: IGcmMultiplier; FExp: IGcmExponentiator; @@ -190,15 +190,15 @@ TGcmBlockCipher = class(TInterfacedObject, IGcmBlockCipher, ALimit: Int32; AForEncrypt: Boolean); // ===================================================================== // Fused block-cipher keystream + 8-way GHASH pipeline (provided by the - // fused kernel registry; nil kernel -> not used, e.g. off-SIMD). + // cipher-kernel registry; nil kernel -> not used, e.g. off-SIMD). // ===================================================================== // This outer driver is arch-agnostic: pure Pascal batch orchestration - // plus one call into an IFusedGcmKernel per 8-block stride. The kernel + // plus one call into an IGcmKernel per 8-block stride. The kernel // fuses CTR-mode keystream generation with the GHASH multiply-reduce in a // single pass, interleaving the two at the instruction level so their // independent execution units overlap. How wide that interleave runs and // how it is scheduled against the available vector-register budget is a - // backend detail hidden entirely behind the IFusedGcmKernel surface, so + // backend detail hidden entirely behind the IGcmKernel surface, so // this driver only ever sees the kernel interface. /// /// Pipelined GCM path driven by FGcmKernel (when a fused kernel is @@ -467,7 +467,7 @@ procedure TGcmBlockCipher.InitCipherAndHashSubKey(const AKeyParam: IKeyParameter System.SetLength(FWorkCtrAhead, 128); TArrayUtilities.Fill(FWorkCtrAhead, 0, System.Length(FWorkCtrAhead), Byte(0)); - if TFusedKernelRegistry.TryAcquireGcm(FCipher, TFusedModeDirection.Encrypt, + if TCipherKernelRegistry.TryAcquireGcm(FCipher, TCipherKernelDirection.Encrypt, @FHPow[0], FGcmKernel) and (FGcmKernel <> nil) then begin FGcmKernelMinBlocks := FGcmKernel.MinimumBlockCount; @@ -1143,7 +1143,7 @@ procedure TGcmBlockCipher.GhashFourShuffledBlocks(PC0, PC16, PC32, PC48: PByte); // GHASH to reclaim instruction-level parallelism across the two independent // execution units. The FusedILP variant (further below) pushes this further // by interleaving both at the instruction level inside a single kernel -// supplied by the fused-kernel registry (nil off-SIMD, so that path is +// supplied by the cipher-kernel registry (nil off-SIMD, so that path is // simply skipped there). AForEncrypt selects which buffer feeds GHASH: // output ciphertext on encrypt, input ciphertext on decrypt. // ======================================================================= @@ -1381,7 +1381,7 @@ class procedure TGcmBlockCipher.FillCtr8BlocksRaw( // ======================================================================= // Fused block-cipher keystream + 8-way GHASH pipeline. The driver is // arch-agnostic: it drives the outer 8-block stride loop and delegates the -// fused work to whichever IFusedGcmKernel the registry resolved (nil +// fused work to whichever IGcmKernel the registry resolved (nil // off-SIMD, so the callers never invoke this path there). The kernel's // internal interleave and register budget are backend details behind the // interface, summarised on the matching banner in the class declaration. diff --git a/CryptoLib/src/Crypto/Modes/ClpGcmSivBlockCipher.pas b/CryptoLib/src/Crypto/Modes/ClpGcmSivBlockCipher.pas index b9ac8978..b3d1570c 100644 --- a/CryptoLib/src/Crypto/Modes/ClpGcmSivBlockCipher.pas +++ b/CryptoLib/src/Crypto/Modes/ClpGcmSivBlockCipher.pas @@ -38,10 +38,10 @@ interface ClpGcmUtilities, ClpGcmSivUtilities, ClpGcmSivSimd, - ClpFusedKernelTypes, - ClpIFusedGcmSivKernel, - ClpFusedKernelRegistry, - ClpFusedKernelDefaults, // registers in-tree fused AEAD kernel factories + ClpCipherKernelTypes, + ClpIGcmSivKernel, + ClpCipherKernelRegistry, + ClpCipherKernelDefaults, // registers in-tree fused AEAD kernel factories ClpKeyParameter, ClpAesUtilities, ClpInt64Utilities, @@ -128,10 +128,10 @@ TGcmSivHasher = class(TObject) // when the fused kernel is available; captured by reference by the // kernel and consumed read-only by TGcmSivHasher.UpdateHash. FHPow128: TCryptoLibByteArray; - // Fused POLYVAL kernel resolved via TFusedKernelRegistry. Non-nil + // Fused POLYVAL kernel resolved via TCipherKernelRegistry. Non-nil // only when the registry produced a kernel whose MinimumBlockCount // matches the mode's 8-block batch contract. - FGcmSivKernel: IFusedGcmSivKernel; + FGcmSivKernel: IGcmSivKernel; FGcmSivKernelBatchBytes: Int32; procedure CheckAeadStatus(ALen: Int32); @@ -869,8 +869,8 @@ procedure TGcmSivBlockCipher.DeriveKeys(const AKey: IKeyParameter); if System.Length(FHPow128) < 128 then System.SetLength(FHPow128, 128); TGcmUtilities.InitEightWayHPowFromH(LMyOut, FHPow128); - if TFusedKernelRegistry.TryAcquireGcmSiv(FTheCipher, - TFusedModeDirection.Encrypt, @FHPow128[0], FGcmSivKernel) and + if TCipherKernelRegistry.TryAcquireGcmSiv(FTheCipher, + TCipherKernelDirection.Encrypt, @FHPow128[0], FGcmSivKernel) and (FGcmSivKernel <> nil) then begin if FGcmSivKernel.MinimumBlockCount = 8 then diff --git a/CryptoLib/src/Crypto/Modes/ClpOcbBlockCipher.pas b/CryptoLib/src/Crypto/Modes/ClpOcbBlockCipher.pas index 2b92cf51..04240926 100644 --- a/CryptoLib/src/Crypto/Modes/ClpOcbBlockCipher.pas +++ b/CryptoLib/src/Crypto/Modes/ClpOcbBlockCipher.pas @@ -25,10 +25,10 @@ interface Generics.Collections, ClpIBlockCipher, ClpIBulkBlockCipher, - ClpFusedKernelTypes, - ClpIFusedOcbKernel, - ClpFusedKernelRegistry, - ClpFusedKernelDefaults, // registers in-tree fused AEAD kernel factories + ClpCipherKernelTypes, + ClpIOcbKernel, + ClpCipherKernelRegistry, + ClpCipherKernelDefaults, // registers in-tree fused AEAD kernel factories ClpIOcbBlockCipher, ClpIAeadBlockCipher, ClpIAeadCipher, @@ -124,14 +124,14 @@ TOcbBlockCipher = class(TInterfacedObject, IOcbBlockCipher, FMainBulk: IBulkBlockCipher; // Fused-kernel fast path: cipher-agnostic fused OCB kernel - // resolved via TFusedKernelRegistry on every Init. Nil when no + // resolved via TCipherKernelRegistry on every Init. Nil when no // registered factory accepts the cipher / direction pair or the // registry-wide kill switch is on; ProcessBytes then falls through // to the 8-wide bulk / scalar paths unchanged. // FOcbKernelMinBlocks is also the batch alignment: the kernel // loops internally in MinimumBlockCount chunks so the mode stages // up to FUSED_BATCH_BLOCKS worth of offsets per dispatch. - FOcbKernel: IFusedOcbKernel; + FOcbKernel: IOcbKernel; FOcbKernelMinBlocks: Int32; procedure CheckNonceReuse(AForEncryption: Boolean; @@ -267,7 +267,7 @@ procedure TOcbBlockCipher.Init(AForEncryption: Boolean; LN: TCryptoLibByteArray; LMacSizeBits, LBottom, LBits, LBytes, LI: Int32; LB1, LB2: UInt32; - LFusedDirection: TFusedModeDirection; + LFusedDirection: TCipherKernelDirection; begin LOldForEncryption := FForEncryption; FForEncryption := AForEncryption; @@ -340,10 +340,10 @@ procedure TOcbBlockCipher.Init(AForEncryption: Boolean; FOcbKernel := nil; FOcbKernelMinBlocks := 0; if FForEncryption then - LFusedDirection := TFusedModeDirection.Encrypt + LFusedDirection := TCipherKernelDirection.Encrypt else - LFusedDirection := TFusedModeDirection.Decrypt; - if TFusedKernelRegistry.TryAcquireOcb(FMainCipher, LFusedDirection, + LFusedDirection := TCipherKernelDirection.Decrypt; + if TCipherKernelRegistry.TryAcquireOcb(FMainCipher, LFusedDirection, FOcbKernel) and (FOcbKernel <> nil) then begin FOcbKernelMinBlocks := FOcbKernel.MinimumBlockCount; @@ -663,7 +663,7 @@ procedure TOcbBlockCipher.ProcessFusedBulk(const AInput: TCryptoLibByteArray; // LScratch reshape had to do on every fused decrypt batch. // // The `InPtr - BLOCK_SIZE` pointer is never dereferenced at offset 0 by - // the kernel (guaranteed by the IFusedOcbKernel.ProcessBlocks contract for + // the kernel (guaranteed by the IOcbKernel.ProcessBlocks contract for // Block0Ptr); the address itself only feeds register arithmetic and the // `[InPtr + 16..]` loads, all of which resolve inside AInput. LBlock0Ptr := @FMainBlock[0]; diff --git a/CryptoLib/src/Crypto/Modes/ClpSicBlockCipher.pas b/CryptoLib/src/Crypto/Modes/ClpSicBlockCipher.pas index 394f3028..f50ad5b4 100644 --- a/CryptoLib/src/Crypto/Modes/ClpSicBlockCipher.pas +++ b/CryptoLib/src/Crypto/Modes/ClpSicBlockCipher.pas @@ -26,9 +26,9 @@ interface ClpIBlockCipher, ClpIBlockCipherMode, ClpIBulkBlockCipher, - ClpIFusedCtrKernel, - ClpFusedKernelTypes, - ClpFusedKernelRegistry, + ClpICtrKernel, + ClpCipherKernelTypes, + ClpCipherKernelRegistry, ClpIBulkBlockCipherMode, ClpBlockCipherBulkUtilities, ClpByteUtilities, @@ -70,11 +70,11 @@ TSicBlockCipher = class(TInterfacedObject, ISicBlockCipher, // bulk-capable engine plugs in unchanged by implementing the // interface -- the mode does not care which cipher is underneath. FBulkCipher: IBulkBlockCipher; - // Acquired on Init from the fused-kernel registry when an accelerated + // Acquired on Init from the cipher-kernel registry when an accelerated // counter-mode kernel is available for FCipher: a single AES-NI pass that // fuses counter generation, encryption and XOR. Preferred over FBulkCipher // for the batch-aligned bulk; nil (with FBulkCipher fallback) otherwise. - FCtrKernel: IFusedCtrKernel; + FCtrKernel: ICtrKernel; /// /// Snapshot FCounter into APlainCounters and advance FCounter by ABlockCount @@ -217,7 +217,7 @@ procedure TSicBlockCipher.Init(AForEncryption: Boolean; // Acquire the fused counter-mode kernel if an accelerator is registered for // FCipher (sets FCtrKernel nil on miss). Direction is irrelevant for CTR // keystream (always AES-encrypt of the counter), so request Encrypt. - TFusedKernelRegistry.TryAcquireCtr(FCipher, TFusedModeDirection.Encrypt, + TCipherKernelRegistry.TryAcquireCtr(FCipher, TCipherKernelDirection.Encrypt, FCtrKernel); Reset(); diff --git a/CryptoLib/src/Crypto/Modes/Fused/ClpFusedKernelRegistry.pas b/CryptoLib/src/Crypto/Modes/Fused/ClpFusedKernelRegistry.pas deleted file mode 100644 index 587b95ed..00000000 --- a/CryptoLib/src/Crypto/Modes/Fused/ClpFusedKernelRegistry.pas +++ /dev/null @@ -1,850 +0,0 @@ -{ *********************************************************************************** } -{ * CryptoLib Library * } -{ * Author - Ugochukwu Mmaduekwe * } -{ * Github Repository * } -{ * * } -{ * Distributed under the MIT software license, see the accompanying file LICENSE * } -{ * or visit http://www.opensource.org/licenses/mit-license.php. * } -{ * * } -{ * Acknowledgements: * } -{ * * } -{ * Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring * } -{ * the development of this library * } -{ * ******************************************************************************* * } - -(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) - -unit ClpFusedKernelRegistry; - -{$I ..\..\..\Include\CryptoLib.inc} - -interface - -uses - SysUtils, - SyncObjs, - Generics.Collections, - ClpIBlockCipher, - ClpCryptoLibTypes, - ClpFusedKernelTypes, - ClpIFusedGcmKernel, - ClpIFusedOcbKernel, - ClpIFusedCcmKernel, - ClpIFusedEaxKernel, - ClpIFusedGcmSivKernel, - ClpIFusedCtrKernel, - ClpIFusedCbcKernel; - -type - /// - /// Process-wide kill switch for every fused AEAD kernel registered - /// with the registry. When ForceDisabled is True, every TryAcquireX - /// returns False without walking the factory list, so modes route - /// through their scalar fallbacks. Used by the dual-mode test - /// harness to prove both paths agree byte-for-byte. - /// - TFusedKernelGate = class sealed(TObject) - strict private - class var FForceDisabled: Boolean; - public - class property ForceDisabled: Boolean read FForceDisabled write FForceDisabled; - end; - - /// - /// Open factory-based resolver for the fused AEAD kernel family - /// (GCM, OCB, CCM, EAX, GCM-SIV). Accelerator units register an - /// IFused<Mode>KernelFactory in their initialization block; - /// modes resolve a kernel via TryAcquire<Mode> at Init time. - /// Factories are kept sorted by TFusedKernelPriority descending so - /// higher-priority accelerators win. TryCreate failures are - /// expected and the registry walks to the next factory. - /// Lookups are thread-safe: a single TCriticalSection guards - /// insertion / removal / snapshot; TryAcquireX takes a snapshot - /// under the lock then releases it before invoking factory - /// TryCreate, so factory work never serialises other call sites. - /// - TFusedKernelRegistry = class sealed(TObject) - strict private - class var FLock: TCriticalSection; - class var FGcmFactories: TList; - class var FOcbFactories: TList; - class var FCcmFactories: TList; - class var FEaxFactories: TList; - class var FGcmSivFactories: TList; - class var FCtrFactories: TList; - class var FCbcFactories: TList; - - class function SnapshotGcmFactories: TCryptoLibGenericArray; static; - class function SnapshotOcbFactories: TCryptoLibGenericArray; static; - class function SnapshotCcmFactories: TCryptoLibGenericArray; static; - class function SnapshotEaxFactories: TCryptoLibGenericArray; static; - class function SnapshotGcmSivFactories: TCryptoLibGenericArray; static; - class function SnapshotCtrFactories: TCryptoLibGenericArray; static; - class function SnapshotCbcFactories: TCryptoLibGenericArray; static; - - class constructor Create; - class destructor Destroy; - public - /// Register a factory. Insertion keeps the list sorted by - /// Ord(Priority) descending; equal priorities retain registration - /// order. Duplicate registrations (same interface identity) are - /// silently ignored. - class procedure RegisterGcmFactory(const AFactory: IFusedGcmKernelFactory); static; - class procedure RegisterOcbFactory(const AFactory: IFusedOcbKernelFactory); static; - class procedure RegisterCcmFactory(const AFactory: IFusedCcmKernelFactory); static; - class procedure RegisterEaxFactory(const AFactory: IFusedEaxKernelFactory); static; - class procedure RegisterGcmSivFactory(const AFactory: IFusedGcmSivKernelFactory); static; - class procedure RegisterCtrFactory(const AFactory: IFusedCtrKernelFactory); static; - class procedure RegisterCbcFactory(const AFactory: IFusedCbcKernelFactory); static; - - /// Remove AFactory. No-op if not registered. - class procedure UnregisterGcmFactory(const AFactory: IFusedGcmKernelFactory); static; - class procedure UnregisterOcbFactory(const AFactory: IFusedOcbKernelFactory); static; - class procedure UnregisterCcmFactory(const AFactory: IFusedCcmKernelFactory); static; - class procedure UnregisterEaxFactory(const AFactory: IFusedEaxKernelFactory); static; - class procedure UnregisterGcmSivFactory(const AFactory: IFusedGcmSivKernelFactory); static; - class procedure UnregisterCtrFactory(const AFactory: IFusedCtrKernelFactory); static; - class procedure UnregisterCbcFactory(const AFactory: IFusedCbcKernelFactory); static; - - /// Walk the factory list (highest priority first) and - /// return the first kernel whose TryCreate succeeds. Returns False - /// with AKernel = nil when the gate is ForceDisabled, when no - /// factory is registered, or when every TryCreate returns False. - /// Never raises. - class function TryAcquireGcm(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - AHPowers: Pointer; - out AKernel: IFusedGcmKernel): Boolean; static; - class function TryAcquireOcb(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedOcbKernel): Boolean; static; - class function TryAcquireCcm(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedCcmKernel): Boolean; static; - class function TryAcquireEax(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedEaxKernel): Boolean; static; - /// GCM-SIV variant: AHPowers is forwarded to the factory - /// and captured by reference by the returned kernel; it MUST - /// outlive the kernel. - class function TryAcquireGcmSiv(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - AHPowers: Pointer; - out AKernel: IFusedGcmSivKernel): Boolean; static; - /// CTR variant: no auxiliary state (MAC-free). Returns False (and - /// AKernel nil) when the gate is ForceDisabled, no factory is registered, - /// or every TryCreate returns False. - class function TryAcquireCtr(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedCtrKernel): Boolean; static; - /// CBC-encrypt variant: no auxiliary state. Returns False (and - /// AKernel nil) when the gate is ForceDisabled, no factory is registered, - /// or every TryCreate returns False. - class function TryAcquireCbc(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedCbcKernel): Boolean; static; - - /// Snapshot of ProviderName strings in current priority - /// order. Used for diagnostics and test assertions. - class function GetRegisteredGcmProviders: TCryptoLibStringArray; static; - class function GetRegisteredOcbProviders: TCryptoLibStringArray; static; - class function GetRegisteredCcmProviders: TCryptoLibStringArray; static; - class function GetRegisteredEaxProviders: TCryptoLibStringArray; static; - class function GetRegisteredGcmSivProviders: TCryptoLibStringArray; static; - class function GetRegisteredCtrProviders: TCryptoLibStringArray; static; - class function GetRegisteredCbcProviders: TCryptoLibStringArray; static; - end; - -implementation - -{ TFusedKernelRegistry } - -class constructor TFusedKernelRegistry.Create; -begin - FLock := TCriticalSection.Create; - FGcmFactories := TList.Create; - FOcbFactories := TList.Create; - FCcmFactories := TList.Create; - FEaxFactories := TList.Create; - FGcmSivFactories := TList.Create; - FCtrFactories := TList.Create; - FCbcFactories := TList.Create; -end; - -class destructor TFusedKernelRegistry.Destroy; -begin - FCbcFactories.Free; - FCtrFactories.Free; - FGcmSivFactories.Free; - FEaxFactories.Free; - FCcmFactories.Free; - FOcbFactories.Free; - FGcmFactories.Free; - FLock.Free; -end; - -{ ---- Register --------------------------------------------------------------- } - -class procedure TFusedKernelRegistry.RegisterGcmFactory( - const AFactory: IFusedGcmKernelFactory); -var - LI: Int32; - LInserted: Boolean; - LPriority: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - if FGcmFactories.IndexOf(AFactory) >= 0 then Exit; - LPriority := Ord(AFactory.Priority); - LInserted := False; - for LI := 0 to FGcmFactories.Count - 1 do - begin - if LPriority > Ord(FGcmFactories[LI].Priority) then - begin - FGcmFactories.Insert(LI, AFactory); - LInserted := True; - Break; - end; - end; - if not LInserted then - FGcmFactories.Add(AFactory); - finally - FLock.Leave; - end; -end; - -class procedure TFusedKernelRegistry.RegisterOcbFactory( - const AFactory: IFusedOcbKernelFactory); -var - LI: Int32; - LInserted: Boolean; - LPriority: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - if FOcbFactories.IndexOf(AFactory) >= 0 then Exit; - LPriority := Ord(AFactory.Priority); - LInserted := False; - for LI := 0 to FOcbFactories.Count - 1 do - begin - if LPriority > Ord(FOcbFactories[LI].Priority) then - begin - FOcbFactories.Insert(LI, AFactory); - LInserted := True; - Break; - end; - end; - if not LInserted then - FOcbFactories.Add(AFactory); - finally - FLock.Leave; - end; -end; - -class procedure TFusedKernelRegistry.RegisterCcmFactory( - const AFactory: IFusedCcmKernelFactory); -var - LI: Int32; - LInserted: Boolean; - LPriority: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - if FCcmFactories.IndexOf(AFactory) >= 0 then Exit; - LPriority := Ord(AFactory.Priority); - LInserted := False; - for LI := 0 to FCcmFactories.Count - 1 do - begin - if LPriority > Ord(FCcmFactories[LI].Priority) then - begin - FCcmFactories.Insert(LI, AFactory); - LInserted := True; - Break; - end; - end; - if not LInserted then - FCcmFactories.Add(AFactory); - finally - FLock.Leave; - end; -end; - -class procedure TFusedKernelRegistry.RegisterEaxFactory( - const AFactory: IFusedEaxKernelFactory); -var - LI: Int32; - LInserted: Boolean; - LPriority: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - if FEaxFactories.IndexOf(AFactory) >= 0 then Exit; - LPriority := Ord(AFactory.Priority); - LInserted := False; - for LI := 0 to FEaxFactories.Count - 1 do - begin - if LPriority > Ord(FEaxFactories[LI].Priority) then - begin - FEaxFactories.Insert(LI, AFactory); - LInserted := True; - Break; - end; - end; - if not LInserted then - FEaxFactories.Add(AFactory); - finally - FLock.Leave; - end; -end; - -class procedure TFusedKernelRegistry.RegisterGcmSivFactory( - const AFactory: IFusedGcmSivKernelFactory); -var - LI: Int32; - LInserted: Boolean; - LPriority: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - if FGcmSivFactories.IndexOf(AFactory) >= 0 then Exit; - LPriority := Ord(AFactory.Priority); - LInserted := False; - for LI := 0 to FGcmSivFactories.Count - 1 do - begin - if LPriority > Ord(FGcmSivFactories[LI].Priority) then - begin - FGcmSivFactories.Insert(LI, AFactory); - LInserted := True; - Break; - end; - end; - if not LInserted then - FGcmSivFactories.Add(AFactory); - finally - FLock.Leave; - end; -end; - -class procedure TFusedKernelRegistry.RegisterCtrFactory( - const AFactory: IFusedCtrKernelFactory); -var - LI: Int32; - LInserted: Boolean; - LPriority: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - if FCtrFactories.IndexOf(AFactory) >= 0 then Exit; - LPriority := Ord(AFactory.Priority); - LInserted := False; - for LI := 0 to FCtrFactories.Count - 1 do - begin - if LPriority > Ord(FCtrFactories[LI].Priority) then - begin - FCtrFactories.Insert(LI, AFactory); - LInserted := True; - Break; - end; - end; - if not LInserted then - FCtrFactories.Add(AFactory); - finally - FLock.Leave; - end; -end; - -class procedure TFusedKernelRegistry.RegisterCbcFactory( - const AFactory: IFusedCbcKernelFactory); -var - LI: Int32; - LInserted: Boolean; - LPriority: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - if FCbcFactories.IndexOf(AFactory) >= 0 then Exit; - LPriority := Ord(AFactory.Priority); - LInserted := False; - for LI := 0 to FCbcFactories.Count - 1 do - begin - if LPriority > Ord(FCbcFactories[LI].Priority) then - begin - FCbcFactories.Insert(LI, AFactory); - LInserted := True; - Break; - end; - end; - if not LInserted then - FCbcFactories.Add(AFactory); - finally - FLock.Leave; - end; -end; - -{ ---- Unregister ------------------------------------------------------------- } - -class procedure TFusedKernelRegistry.UnregisterGcmFactory( - const AFactory: IFusedGcmKernelFactory); -var - LIdx: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - LIdx := FGcmFactories.IndexOf(AFactory); - if LIdx >= 0 then - FGcmFactories.Delete(LIdx); - finally - FLock.Leave; - end; -end; - -class procedure TFusedKernelRegistry.UnregisterOcbFactory( - const AFactory: IFusedOcbKernelFactory); -var - LIdx: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - LIdx := FOcbFactories.IndexOf(AFactory); - if LIdx >= 0 then - FOcbFactories.Delete(LIdx); - finally - FLock.Leave; - end; -end; - -class procedure TFusedKernelRegistry.UnregisterCcmFactory( - const AFactory: IFusedCcmKernelFactory); -var - LIdx: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - LIdx := FCcmFactories.IndexOf(AFactory); - if LIdx >= 0 then - FCcmFactories.Delete(LIdx); - finally - FLock.Leave; - end; -end; - -class procedure TFusedKernelRegistry.UnregisterEaxFactory( - const AFactory: IFusedEaxKernelFactory); -var - LIdx: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - LIdx := FEaxFactories.IndexOf(AFactory); - if LIdx >= 0 then - FEaxFactories.Delete(LIdx); - finally - FLock.Leave; - end; -end; - -class procedure TFusedKernelRegistry.UnregisterGcmSivFactory( - const AFactory: IFusedGcmSivKernelFactory); -var - LIdx: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - LIdx := FGcmSivFactories.IndexOf(AFactory); - if LIdx >= 0 then - FGcmSivFactories.Delete(LIdx); - finally - FLock.Leave; - end; -end; - -class procedure TFusedKernelRegistry.UnregisterCtrFactory( - const AFactory: IFusedCtrKernelFactory); -var - LIdx: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - LIdx := FCtrFactories.IndexOf(AFactory); - if LIdx >= 0 then - FCtrFactories.Delete(LIdx); - finally - FLock.Leave; - end; -end; - -class procedure TFusedKernelRegistry.UnregisterCbcFactory( - const AFactory: IFusedCbcKernelFactory); -var - LIdx: Int32; -begin - if AFactory = nil then Exit; - FLock.Enter; - try - LIdx := FCbcFactories.IndexOf(AFactory); - if LIdx >= 0 then - FCbcFactories.Delete(LIdx); - finally - FLock.Leave; - end; -end; - -{ ---- Snapshots -------------------------------------------------------------- } - -class function TFusedKernelRegistry.SnapshotGcmFactories: TCryptoLibGenericArray; -var - LI, LCount: Int32; -begin - FLock.Enter; - try - LCount := FGcmFactories.Count; - System.SetLength(Result, LCount); - for LI := 0 to LCount - 1 do - Result[LI] := FGcmFactories[LI]; - finally - FLock.Leave; - end; -end; - -class function TFusedKernelRegistry.SnapshotOcbFactories: TCryptoLibGenericArray; -var - LI, LCount: Int32; -begin - FLock.Enter; - try - LCount := FOcbFactories.Count; - System.SetLength(Result, LCount); - for LI := 0 to LCount - 1 do - Result[LI] := FOcbFactories[LI]; - finally - FLock.Leave; - end; -end; - -class function TFusedKernelRegistry.SnapshotCcmFactories: TCryptoLibGenericArray; -var - LI, LCount: Int32; -begin - FLock.Enter; - try - LCount := FCcmFactories.Count; - System.SetLength(Result, LCount); - for LI := 0 to LCount - 1 do - Result[LI] := FCcmFactories[LI]; - finally - FLock.Leave; - end; -end; - -class function TFusedKernelRegistry.SnapshotEaxFactories: TCryptoLibGenericArray; -var - LI, LCount: Int32; -begin - FLock.Enter; - try - LCount := FEaxFactories.Count; - System.SetLength(Result, LCount); - for LI := 0 to LCount - 1 do - Result[LI] := FEaxFactories[LI]; - finally - FLock.Leave; - end; -end; - -class function TFusedKernelRegistry.SnapshotGcmSivFactories: TCryptoLibGenericArray; -var - LI, LCount: Int32; -begin - FLock.Enter; - try - LCount := FGcmSivFactories.Count; - System.SetLength(Result, LCount); - for LI := 0 to LCount - 1 do - Result[LI] := FGcmSivFactories[LI]; - finally - FLock.Leave; - end; -end; - -class function TFusedKernelRegistry.SnapshotCtrFactories: TCryptoLibGenericArray; -var - LI, LCount: Int32; -begin - FLock.Enter; - try - LCount := FCtrFactories.Count; - System.SetLength(Result, LCount); - for LI := 0 to LCount - 1 do - Result[LI] := FCtrFactories[LI]; - finally - FLock.Leave; - end; -end; - -class function TFusedKernelRegistry.SnapshotCbcFactories: TCryptoLibGenericArray; -var - LI, LCount: Int32; -begin - FLock.Enter; - try - LCount := FCbcFactories.Count; - System.SetLength(Result, LCount); - for LI := 0 to LCount - 1 do - Result[LI] := FCbcFactories[LI]; - finally - FLock.Leave; - end; -end; - -{ ---- TryAcquire ------------------------------------------------------------- } - -class function TFusedKernelRegistry.TryAcquireGcm(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; AHPowers: Pointer; - out AKernel: IFusedGcmKernel): Boolean; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - AKernel := nil; - Result := False; - if TFusedKernelGate.ForceDisabled then Exit; - if ACipher = nil then Exit; - if AHPowers = nil then Exit; - LSnapshot := SnapshotGcmFactories; - for LI := 0 to System.Length(LSnapshot) - 1 do - begin - if LSnapshot[LI].TryCreate(ACipher, ADirection, AHPowers, AKernel) and (AKernel <> nil) then - begin - Result := True; - Exit; - end; - end; - AKernel := nil; -end; - -class function TFusedKernelRegistry.TryAcquireOcb(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; out AKernel: IFusedOcbKernel): Boolean; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - AKernel := nil; - Result := False; - if TFusedKernelGate.ForceDisabled then Exit; - if ACipher = nil then Exit; - LSnapshot := SnapshotOcbFactories; - for LI := 0 to System.Length(LSnapshot) - 1 do - begin - if LSnapshot[LI].TryCreate(ACipher, ADirection, AKernel) and (AKernel <> nil) then - begin - Result := True; - Exit; - end; - end; - AKernel := nil; -end; - -class function TFusedKernelRegistry.TryAcquireCcm(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; out AKernel: IFusedCcmKernel): Boolean; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - AKernel := nil; - Result := False; - if TFusedKernelGate.ForceDisabled then Exit; - if ACipher = nil then Exit; - LSnapshot := SnapshotCcmFactories; - for LI := 0 to System.Length(LSnapshot) - 1 do - begin - if LSnapshot[LI].TryCreate(ACipher, ADirection, AKernel) and (AKernel <> nil) then - begin - Result := True; - Exit; - end; - end; - AKernel := nil; -end; - -class function TFusedKernelRegistry.TryAcquireEax(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; out AKernel: IFusedEaxKernel): Boolean; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - AKernel := nil; - Result := False; - if TFusedKernelGate.ForceDisabled then Exit; - if ACipher = nil then Exit; - LSnapshot := SnapshotEaxFactories; - for LI := 0 to System.Length(LSnapshot) - 1 do - begin - if LSnapshot[LI].TryCreate(ACipher, ADirection, AKernel) and (AKernel <> nil) then - begin - Result := True; - Exit; - end; - end; - AKernel := nil; -end; - -class function TFusedKernelRegistry.TryAcquireGcmSiv(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; AHPowers: Pointer; - out AKernel: IFusedGcmSivKernel): Boolean; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - AKernel := nil; - Result := False; - if TFusedKernelGate.ForceDisabled then Exit; - if AHPowers = nil then Exit; - LSnapshot := SnapshotGcmSivFactories; - for LI := 0 to System.Length(LSnapshot) - 1 do - begin - if LSnapshot[LI].TryCreate(ACipher, ADirection, AHPowers, AKernel) and (AKernel <> nil) then - begin - Result := True; - Exit; - end; - end; - AKernel := nil; -end; - -class function TFusedKernelRegistry.TryAcquireCtr(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; out AKernel: IFusedCtrKernel): Boolean; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - AKernel := nil; - Result := False; - if TFusedKernelGate.ForceDisabled then Exit; - if ACipher = nil then Exit; - LSnapshot := SnapshotCtrFactories; - for LI := 0 to System.Length(LSnapshot) - 1 do - begin - if LSnapshot[LI].TryCreate(ACipher, ADirection, AKernel) and (AKernel <> nil) then - begin - Result := True; - Exit; - end; - end; - AKernel := nil; -end; - -class function TFusedKernelRegistry.TryAcquireCbc(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; out AKernel: IFusedCbcKernel): Boolean; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - AKernel := nil; - Result := False; - if TFusedKernelGate.ForceDisabled then Exit; - if ACipher = nil then Exit; - LSnapshot := SnapshotCbcFactories; - for LI := 0 to System.Length(LSnapshot) - 1 do - begin - if LSnapshot[LI].TryCreate(ACipher, ADirection, AKernel) and (AKernel <> nil) then - begin - Result := True; - Exit; - end; - end; - AKernel := nil; -end; - -{ ---- Provider queries ------------------------------------------------------- } - -class function TFusedKernelRegistry.GetRegisteredGcmProviders: TCryptoLibStringArray; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - LSnapshot := SnapshotGcmFactories; - System.SetLength(Result, System.Length(LSnapshot)); - for LI := 0 to System.Length(LSnapshot) - 1 do - Result[LI] := LSnapshot[LI].ProviderName; -end; - -class function TFusedKernelRegistry.GetRegisteredOcbProviders: TCryptoLibStringArray; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - LSnapshot := SnapshotOcbFactories; - System.SetLength(Result, System.Length(LSnapshot)); - for LI := 0 to System.Length(LSnapshot) - 1 do - Result[LI] := LSnapshot[LI].ProviderName; -end; - -class function TFusedKernelRegistry.GetRegisteredCcmProviders: TCryptoLibStringArray; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - LSnapshot := SnapshotCcmFactories; - System.SetLength(Result, System.Length(LSnapshot)); - for LI := 0 to System.Length(LSnapshot) - 1 do - Result[LI] := LSnapshot[LI].ProviderName; -end; - -class function TFusedKernelRegistry.GetRegisteredEaxProviders: TCryptoLibStringArray; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - LSnapshot := SnapshotEaxFactories; - System.SetLength(Result, System.Length(LSnapshot)); - for LI := 0 to System.Length(LSnapshot) - 1 do - Result[LI] := LSnapshot[LI].ProviderName; -end; - -class function TFusedKernelRegistry.GetRegisteredGcmSivProviders: TCryptoLibStringArray; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - LSnapshot := SnapshotGcmSivFactories; - System.SetLength(Result, System.Length(LSnapshot)); - for LI := 0 to System.Length(LSnapshot) - 1 do - Result[LI] := LSnapshot[LI].ProviderName; -end; - -class function TFusedKernelRegistry.GetRegisteredCtrProviders: TCryptoLibStringArray; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - LSnapshot := SnapshotCtrFactories; - System.SetLength(Result, System.Length(LSnapshot)); - for LI := 0 to System.Length(LSnapshot) - 1 do - Result[LI] := LSnapshot[LI].ProviderName; -end; - -class function TFusedKernelRegistry.GetRegisteredCbcProviders: TCryptoLibStringArray; -var - LSnapshot: TCryptoLibGenericArray; - LI: Int32; -begin - LSnapshot := SnapshotCbcFactories; - System.SetLength(Result, System.Length(LSnapshot)); - for LI := 0 to System.Length(LSnapshot) - 1 do - Result[LI] := LSnapshot[LI].ProviderName; -end; - -end. diff --git a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedCbcKernel.pas b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpICbcKernel.pas similarity index 83% rename from CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedCbcKernel.pas rename to CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpICbcKernel.pas index ac483a1d..381bde23 100644 --- a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedCbcKernel.pas +++ b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpICbcKernel.pas @@ -14,7 +14,7 @@ (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) -unit ClpIFusedCbcKernel; +unit ClpICbcKernel; {$I ..\..\..\..\Include\CryptoLib.inc} @@ -23,11 +23,12 @@ interface uses ClpIBlockCipher, ClpCryptoLibTypes, - ClpFusedKernelTypes; + ClpCipherKernelTypes, + ClpICipherKernelFactory; type /// - /// Mode-specific contract for a fused CBC body kernel, direction-bound at + /// Mode-specific contract for an accelerated CBC body kernel, direction-bound at /// construction (like the OCB / CCM kernels). Applies the CBC chain over a /// whole run in one call, keeping the chaining value in a register between /// blocks. Encrypt is inherently serial (C_i = E_K(P_i xor C_{i-1})), so its @@ -35,7 +36,7 @@ interface /// C_{i-1}) parallelises and is not yet implemented. Cipher state lives /// inside the implementation; the mode sees only this interface. /// - IFusedCbcKernel = interface + ICbcKernel = interface ['{898E71F2-B3C8-4B44-A3AB-2A493B4AE126}'] /// @@ -52,22 +53,15 @@ interface /// /// Factory contract for CBC-encrypt kernel providers. Registered with - /// TFusedKernelRegistry; the registry walks the factory list (highest + /// TCipherKernelRegistry; the registry walks the factory list (highest /// priority first) and returns the first kernel whose TryCreate succeeds. /// Factories self-probe (CPU features, cipher identity) and wrap construction /// in try/except; TryCreate MUST return False on failure rather than /// propagating. /// - IFusedCbcKernelFactory = interface + ICbcKernelFactory = interface(ICipherKernelFactory) ['{A4FBAB88-8E80-45A0-86E1-B95B6AFBA9A2}'] - /// Stable human-readable provider label (diagnostics / tests). - function ProviderName: String; - - /// Priority class controlling factory order inside the registry; - /// see TFusedKernelPriority. - function Priority: TFusedKernelPriority; - /// /// Attempt to construct a CBC kernel bound to ACipher for ADirection. /// Only Encrypt is implemented today; a Decrypt request returns False @@ -75,8 +69,8 @@ interface /// failure; never raises. /// function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedCbcKernel): Boolean; + ADirection: TCipherKernelDirection; + out AKernel: ICbcKernel): Boolean; end; implementation diff --git a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedCcmKernel.pas b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpICcmKernel.pas similarity index 89% rename from CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedCcmKernel.pas rename to CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpICcmKernel.pas index 4a644fb6..d28b11fa 100644 --- a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedCcmKernel.pas +++ b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpICcmKernel.pas @@ -14,7 +14,7 @@ (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) -unit ClpIFusedCcmKernel; +unit ClpICcmKernel; {$I ..\..\..\..\Include\CryptoLib.inc} @@ -22,11 +22,12 @@ interface uses ClpIBlockCipher, - ClpFusedKernelTypes; + ClpCipherKernelTypes, + ClpICipherKernelFactory; type /// - /// Mode-specific contract for a fused CCM body kernel running the + /// Mode-specific contract for an accelerated CCM body kernel running the /// CTR keystream and CBC-MAC lanes together per iteration. /// Direction-bound at construction: encrypt and decrypt take /// different paths through the inner MAC dependency chain. The @@ -34,7 +35,7 @@ interface /// ProcessBody once per Init / Reset cycle covering the full bulk /// body. /// - IFusedCcmKernel = interface + ICcmKernel = interface ['{BEAAEA01-DF32-441F-96AB-77D07C19578D}'] /// Minimum number of 16-byte body blocks the kernel can @@ -58,15 +59,12 @@ interface ACbcMacState: Pointer; ABlockCount: Int32); end; - IFusedCcmKernelFactory = interface + ICcmKernelFactory = interface(ICipherKernelFactory) ['{F30B4F47-0546-4212-A00D-850F2AF4FF5F}'] - function ProviderName: String; - function Priority: TFusedKernelPriority; - function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedCcmKernel): Boolean; + ADirection: TCipherKernelDirection; + out AKernel: ICcmKernel): Boolean; end; implementation diff --git a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedCtrKernel.pas b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpICtrKernel.pas similarity index 82% rename from CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedCtrKernel.pas rename to CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpICtrKernel.pas index c3ddcd59..9671b70d 100644 --- a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedCtrKernel.pas +++ b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpICtrKernel.pas @@ -14,7 +14,7 @@ (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) -unit ClpIFusedCtrKernel; +unit ClpICtrKernel; {$I ..\..\..\..\Include\CryptoLib.inc} @@ -23,19 +23,20 @@ interface uses ClpIBlockCipher, ClpCryptoLibTypes, - ClpFusedKernelTypes; + ClpCipherKernelTypes, + ClpICipherKernelFactory; type /// - /// Mode-specific contract for a fused counter (CTR / SIC) body kernel: + /// Mode-specific contract for an accelerated counter (CTR / SIC) body kernel: /// generate AES-CTR keystream and XOR it into the payload in a single pass, /// advancing the counter. It is the non-authenticated, MAC-free member of - /// the fused-kernel family - the shared core the AEAD kernels are built on + /// the cipher-kernel family - the shared core the AEAD kernels are built on /// (GCM = CTR + GHASH, CCM = CTR + CBC-MAC, EAX = CTR + OMAC). All cipher /// state (the key schedule) lives inside the implementation; the mode sees /// only this interface. /// - IFusedCtrKernel = interface + ICtrKernel = interface ['{2A9F4C71-6E38-4B0D-9C57-1F3B8E26D4A5}'] /// The batch granularity: ProcessCtrBlocks requires ABlockCount to @@ -58,22 +59,15 @@ interface /// /// Factory contract for CTR kernel providers. Registered with - /// TFusedKernelRegistry; the registry walks the per-mode factory list + /// TCipherKernelRegistry; the registry walks the per-mode factory list /// (highest-priority first) and returns the first kernel whose TryCreate /// succeeds. Factories self-probe (CPU features, cipher identity) and wrap /// construction in try/except; TryCreate MUST return False on failure /// rather than propagating. /// - IFusedCtrKernelFactory = interface + ICtrKernelFactory = interface(ICipherKernelFactory) ['{7D1E6B02-4A9C-4F58-8B3D-2C57F1E96A4D}'] - /// Stable human-readable provider label (diagnostics / tests). - function ProviderName: String; - - /// Priority class controlling factory order inside the registry; - /// see TFusedKernelPriority. - function Priority: TFusedKernelPriority; - /// /// Attempt to construct a CTR kernel bound to ACipher. ADirection is /// accepted for signature symmetry with the AEAD factories but ignored: @@ -81,8 +75,8 @@ interface /// the same E_K(counter) stream). /// function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedCtrKernel): Boolean; + ADirection: TCipherKernelDirection; + out AKernel: ICtrKernel): Boolean; end; implementation diff --git a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedEaxKernel.pas b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpIEaxKernel.pas similarity index 89% rename from CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedEaxKernel.pas rename to CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpIEaxKernel.pas index aaa9117f..369a5192 100644 --- a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedEaxKernel.pas +++ b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpIEaxKernel.pas @@ -14,7 +14,7 @@ (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) -unit ClpIFusedEaxKernel; +unit ClpIEaxKernel; {$I ..\..\..\..\Include\CryptoLib.inc} @@ -22,11 +22,12 @@ interface uses ClpIBlockCipher, - ClpFusedKernelTypes; + ClpCipherKernelTypes, + ClpICipherKernelFactory; type /// - /// Mode-specific contract for a fused EAX body kernel running the + /// Mode-specific contract for an accelerated EAX body kernel running the /// CTR keystream and OMAC lanes together per iteration. Direction- /// bound at construction: encrypt and decrypt take different paths /// through the inner MAC dependency chain. The kernel owns the @@ -35,7 +36,7 @@ interface /// CBC-MAC running thereafter) and handles nonce-OMAC, header-OMAC, /// and the final-block OMAC subkey XOR. /// - IFusedEaxKernel = interface + IEaxKernel = interface ['{3D87A0D4-7375-453F-BF72-CA3CA191CDCB}'] /// Minimum number of 16-byte body blocks the kernel can @@ -57,15 +58,12 @@ interface AOmacState: Pointer; ABlockCount: Int32); end; - IFusedEaxKernelFactory = interface + IEaxKernelFactory = interface(ICipherKernelFactory) ['{E3DDE544-91EF-4E41-B707-7ACD366FDB0A}'] - function ProviderName: String; - function Priority: TFusedKernelPriority; - function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedEaxKernel): Boolean; + ADirection: TCipherKernelDirection; + out AKernel: IEaxKernel): Boolean; end; implementation diff --git a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedGcmKernel.pas b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpIGcmKernel.pas similarity index 83% rename from CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedGcmKernel.pas rename to CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpIGcmKernel.pas index 51c0c6a4..e0ed4fcb 100644 --- a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedGcmKernel.pas +++ b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpIGcmKernel.pas @@ -14,7 +14,7 @@ (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) -unit ClpIFusedGcmKernel; +unit ClpIGcmKernel; {$I ..\..\..\..\Include\CryptoLib.inc} @@ -22,18 +22,19 @@ interface uses ClpIBlockCipher, - ClpFusedKernelTypes; + ClpCipherKernelTypes, + ClpICipherKernelFactory; type /// - /// Mode-specific contract for a fused GCM body kernel: produce + /// Mode-specific contract for an accelerated GCM body kernel: produce /// keystream for the current batch, XOR it into the payload, and /// fold the previous batch's ciphertext into the running GHASH /// accumulator. All cipher state (key schedule, H-power table, /// static constants) lives inside the implementation; the mode /// sees only this interface. /// - IFusedGcmKernel = interface + IGcmKernel = interface ['{D4D7F5F0-3C56-44E0-8BDD-944AC05E4D2E}'] /// Number of 16-byte blocks per batch consumed by @@ -58,24 +59,16 @@ interface /// /// Factory contract for GCM kernel providers. Registered with - /// TFusedKernelRegistry; the registry walks the per-mode factory + /// TCipherKernelRegistry; the registry walks the per-mode factory /// list (highest-priority first) and returns the first kernel /// whose TryCreate succeeds. Factories self-probe (CPU features, /// cipher identity, direction support) and wrap construction in /// try/except; TryCreate MUST return False on failure rather than /// propagating. /// - IFusedGcmKernelFactory = interface + IGcmKernelFactory = interface(ICipherKernelFactory) ['{6F25C598-3089-40DA-8A81-9C898A5FCBE1}'] - /// Stable human-readable provider label (used for - /// diagnostics, benchmark labelling, and test assertions). - function ProviderName: String; - - /// Priority class controlling factory order inside the - /// registry; see TFusedKernelPriority. - function Priority: TFusedKernelPriority; - /// /// Attempt to construct a kernel bound to ACipher for the /// requested ADirection, capturing AHPowers as its pre-computed @@ -83,8 +76,8 @@ interface /// pointer MUST outlive the returned kernel. /// function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; AHPowers: Pointer; - out AKernel: IFusedGcmKernel): Boolean; + ADirection: TCipherKernelDirection; AHPowers: Pointer; + out AKernel: IGcmKernel): Boolean; end; implementation diff --git a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedGcmSivKernel.pas b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpIGcmSivKernel.pas similarity index 84% rename from CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedGcmSivKernel.pas rename to CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpIGcmSivKernel.pas index 81fb67e3..55fa1d12 100644 --- a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedGcmSivKernel.pas +++ b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpIGcmSivKernel.pas @@ -14,7 +14,7 @@ (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) -unit ClpIFusedGcmSivKernel; +unit ClpIGcmSivKernel; {$I ..\..\..\..\Include\CryptoLib.inc} @@ -22,18 +22,19 @@ interface uses ClpIBlockCipher, - ClpFusedKernelTypes; + ClpCipherKernelTypes, + ClpICipherKernelFactory; type /// - /// Mode-specific contract for a fused GCM-SIV POLYVAL batch kernel. - /// GCM-SIV's fused path is authentication-only and does not touch + /// Mode-specific contract for an accelerated GCM-SIV POLYVAL batch kernel. + /// GCM-SIV's accelerated path is authentication-only and does not touch /// the cipher's key schedule; the kernel is therefore intrinsically /// cipher-agnostic, but is still registered through the shared - /// factory registry for uniformity with the other fused AEAD + /// factory registry for uniformity with the other accelerated AEAD /// kernels. /// - IFusedGcmSivKernel = interface + IGcmSivKernel = interface ['{5FA774F0-42CC-407C-9410-1D5D66421F66}'] /// Number of 16-byte blocks absorbed per @@ -58,16 +59,13 @@ interface /// kernel. ADirection is accepted for registry uniformity but /// POLYVAL is direction-agnostic and it is typically ignored. /// - IFusedGcmSivKernelFactory = interface + IGcmSivKernelFactory = interface(ICipherKernelFactory) ['{5EA5178B-93BD-4E96-B19E-C09B04B32655}'] - function ProviderName: String; - function Priority: TFusedKernelPriority; - function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; + ADirection: TCipherKernelDirection; AHPowers: Pointer; - out AKernel: IFusedGcmSivKernel): Boolean; + out AKernel: IGcmSivKernel): Boolean; end; implementation diff --git a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedOcbKernel.pas b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpIOcbKernel.pas similarity index 92% rename from CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedOcbKernel.pas rename to CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpIOcbKernel.pas index 132129d3..6ff2416f 100644 --- a/CryptoLib/src/Interfaces/Crypto/Modes/Fused/ClpIFusedOcbKernel.pas +++ b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Block/ClpIOcbKernel.pas @@ -14,7 +14,7 @@ (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) -unit ClpIFusedOcbKernel; +unit ClpIOcbKernel; {$I ..\..\..\..\Include\CryptoLib.inc} @@ -22,15 +22,16 @@ interface uses ClpIBlockCipher, - ClpFusedKernelTypes; + ClpCipherKernelTypes, + ClpICipherKernelFactory; type /// - /// Mode-specific contract for a fused OCB body kernel. All cipher + /// Mode-specific contract for an accelerated OCB body kernel. All cipher /// state lives inside the implementation; the mode sees only this /// interface. /// - IFusedOcbKernel = interface + IOcbKernel = interface ['{ADAF5C2A-FD31-42EF-A266-EB4B0F9AC06D}'] /// The minimum (and alignment) batch width the kernel @@ -40,7 +41,7 @@ interface /// /// Process ABlockCount blocks of OCB body in a single call with - /// the offset ladder, L-table lookup and checksum fold all fused + /// the offset ladder, L-table lookup and checksum fold all combined /// inside the kernel. /// ABlockCount MUST be a positive multiple of MinimumBlockCount; /// the kernel iterates internally in MinimumBlockCount-sized @@ -84,12 +85,9 @@ interface AStartBlockCount: UInt64); end; - IFusedOcbKernelFactory = interface + IOcbKernelFactory = interface(ICipherKernelFactory) ['{A430371B-1B11-46C2-AFC8-EF9B07DE4CFA}'] - function ProviderName: String; - function Priority: TFusedKernelPriority; - /// /// Attempt to construct an OCB kernel bound to ACipher for the /// requested ADirection. Returns False with AKernel = nil on any @@ -97,8 +95,8 @@ interface /// construction exception); never raises. /// function TryCreate(const ACipher: IBlockCipher; - ADirection: TFusedModeDirection; - out AKernel: IFusedOcbKernel): Boolean; + ADirection: TCipherKernelDirection; + out AKernel: IOcbKernel): Boolean; end; implementation diff --git a/CryptoLib/src/Interfaces/Crypto/CipherKernels/ClpICipherKernelFactory.pas b/CryptoLib/src/Interfaces/Crypto/CipherKernels/ClpICipherKernelFactory.pas new file mode 100644 index 00000000..2ab88419 --- /dev/null +++ b/CryptoLib/src/Interfaces/Crypto/CipherKernels/ClpICipherKernelFactory.pas @@ -0,0 +1,51 @@ +{ *********************************************************************************** } +{ * CryptoLib Library * } +{ * Author - Ugochukwu Mmaduekwe * } +{ * Github Repository * } +{ * * } +{ * Distributed under the MIT software license, see the accompanying file LICENSE * } +{ * or visit http://www.opensource.org/licenses/mit-license.php. * } +{ * * } +{ * Acknowledgements: * } +{ * * } +{ * Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring * } +{ * the development of this library * } +{ * ******************************************************************************* * } + +(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) + +unit ClpICipherKernelFactory; + +{$I ..\..\..\Include\CryptoLib.inc} + +interface + +uses + ClpCipherKernelTypes; + +type + /// + /// Family-agnostic base contract shared by every cipher kernel factory + /// (block-cipher AEAD modes and stream-cipher AEADs alike). It carries only + /// the identity and ordering a factory needs to live in the registry; the + /// actual TryCreate lives on each derived factory interface with its own + /// strongly-typed cipher parameter. The registry stores factories through + /// this base and rediscovers a concrete family with Supports(); an external + /// consumer can therefore register a cipher kernel for an algorithm the + /// framework never enumerated, with no framework edit. + /// + ICipherKernelFactory = interface + ['{006B1103-17E9-43C6-9A7A-EB515B120325}'] + + /// Stable human-readable provider label (diagnostics / tests). + function ProviderName: String; + + /// Priority class controlling factory order inside the registry; + /// see TCipherKernelPriority. Higher wins; equal priorities keep + /// registration order. + function Priority: TCipherKernelPriority; + end; + +implementation + +end. diff --git a/CryptoLib/src/Interfaces/Crypto/CipherKernels/Stream/ClpIChaCha20Poly1305Kernel.pas b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Stream/ClpIChaCha20Poly1305Kernel.pas new file mode 100644 index 00000000..a9a5cdbd --- /dev/null +++ b/CryptoLib/src/Interfaces/Crypto/CipherKernels/Stream/ClpIChaCha20Poly1305Kernel.pas @@ -0,0 +1,83 @@ +{ *********************************************************************************** } +{ * CryptoLib Library * } +{ * Author - Ugochukwu Mmaduekwe * } +{ * Github Repository * } +{ * * } +{ * Distributed under the MIT software license, see the accompanying file LICENSE * } +{ * or visit http://www.opensource.org/licenses/mit-license.php. * } +{ * * } +{ * Acknowledgements: * } +{ * * } +{ * Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring * } +{ * the development of this library * } +{ * ******************************************************************************* * } + +(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *) + +unit ClpIChaCha20Poly1305Kernel; + +{$I ..\..\..\..\Include\CryptoLib.inc} + +interface + +uses + ClpIStreamCipher, + ClpCipherKernelTypes, + ClpICipherKernelFactory; + +type + /// + /// Mode-specific contract for an accelerated ChaCha20-Poly1305 body kernel: in a + /// single pass over a run of 512-byte (8 x 64-byte) strides, generate the + /// ChaCha20 keystream, XOR it into the payload, and fold the appropriate + /// bytes into the running Poly1305 accumulator - encrypt folds the produced + /// ciphertext (encrypt-then-MAC per stride), decrypt folds the input + /// ciphertext before the XOR (MAC-then-decrypt). This is the stream-cipher + /// analogue of the block-cipher accelerated kernels (GCM = CTR + GHASH); the + /// engine key schedule and Poly1305 r/s clamp live inside the implementation. + /// + IChaCha20Poly1305Kernel = interface + ['{87051735-EA07-4800-A6D9-A8922BFDF6A2}'] + + /// Stride granularity in bytes (512 = 8 x 64-byte ChaCha blocks). + /// ProcessStrides consumes a positive multiple of this in one call. + function StrideBytes: Int32; + + /// + /// Process AStrideCount consecutive StrideBytes-sized strides in one pass, + /// interleaving ChaCha20 keystream XOR with Poly1305 accumulation. + /// AChaChaState points at the engine block state (counter advanced in + /// place); APoly1305State points at the running Poly1305 accumulator + /// (updated in place). AForEncrypt selects encrypt-then-MAC vs + /// MAC-then-decrypt. AInPtr and AOutPtr are identical (in-place) or fully + /// disjoint. + /// + procedure ProcessStrides(AInPtr, AOutPtr, AChaChaState, APoly1305State: Pointer; + AStrideCount: NativeInt; AForEncrypt: Boolean); + end; + + /// + /// Factory contract for accelerated ChaCha20-Poly1305 kernel providers. Registered + /// with TCipherKernelRegistry through the family-agnostic ICipherKernelFactory + /// base; the registry re-discovers it via Supports(). Factories self-probe + /// (CPU features, Supports(ACipher, IChaCha7539Engine)) and wrap construction + /// in try/except; TryCreate MUST return False on failure rather than + /// propagating. + /// + IChaCha20Poly1305KernelFactory = interface(ICipherKernelFactory) + ['{A633B415-7A54-44D7-B983-18BBECC2B32F}'] + + /// + /// Attempt to construct a cipher kernel bound to ACipher (a stream cipher; + /// the factory probes Supports(ACipher, IChaCha7539Engine) for the concrete + /// engine). ADirection is accepted for symmetry with the AEAD factories; + /// the kernel handles both directions via ProcessStrides' AForEncrypt. + /// + function TryCreate(const ACipher: IStreamCipher; + ADirection: TCipherKernelDirection; + out AKernel: IChaCha20Poly1305Kernel): Boolean; + end; + +implementation + +end. diff --git a/CryptoLib/src/Packages/Delphi/CryptoLib4PascalPackage.dpk b/CryptoLib/src/Packages/Delphi/CryptoLib4PascalPackage.dpk index ddbdc48c..b90db160 100644 --- a/CryptoLib/src/Packages/Delphi/CryptoLib4PascalPackage.dpk +++ b/CryptoLib/src/Packages/Delphi/CryptoLib4PascalPackage.dpk @@ -685,26 +685,29 @@ contains ClpEaxBlockCipher in '..\..\Crypto\Modes\ClpEaxBlockCipher.pas', ClpOcbBlockCipher in '..\..\Crypto\Modes\ClpOcbBlockCipher.pas', ClpGcmSivUtilities in '..\..\Crypto\Modes\Gcm\ClpGcmSivUtilities.pas', - ClpFusedKernelTypes in '..\..\Interfaces\Crypto\Modes\Fused\ClpFusedKernelTypes.pas', - ClpIFusedGcmKernel in '..\..\Interfaces\Crypto\Modes\Fused\ClpIFusedGcmKernel.pas', - ClpIFusedOcbKernel in '..\..\Interfaces\Crypto\Modes\Fused\ClpIFusedOcbKernel.pas', - ClpIFusedCcmKernel in '..\..\Interfaces\Crypto\Modes\Fused\ClpIFusedCcmKernel.pas', - ClpIFusedEaxKernel in '..\..\Interfaces\Crypto\Modes\Fused\ClpIFusedEaxKernel.pas', - ClpIFusedGcmSivKernel in '..\..\Interfaces\Crypto\Modes\Fused\ClpIFusedGcmSivKernel.pas', - ClpIFusedCtrKernel in '..\..\Interfaces\Crypto\Modes\Fused\ClpIFusedCtrKernel.pas', - ClpIFusedCbcKernel in '..\..\Interfaces\Crypto\Modes\Fused\ClpIFusedCbcKernel.pas', - ClpFusedKernelRegistry in '..\..\Crypto\Modes\Fused\ClpFusedKernelRegistry.pas', - ClpAesFusedAeadSimd in '..\..\Crypto\Modes\Fused\Internal\ClpAesFusedAeadSimd.pas', - ClpAesNiFusedX86Backend in '..\..\Crypto\Modes\Fused\Internal\ClpAesNiFusedX86Backend.pas', + ClpCipherKernelTypes in '..\..\Crypto\CipherKernels\ClpCipherKernelTypes.pas', + ClpICipherKernelFactory in '..\..\Interfaces\Crypto\CipherKernels\ClpICipherKernelFactory.pas', + ClpIChaCha20Poly1305Kernel in '..\..\Interfaces\Crypto\CipherKernels\Stream\ClpIChaCha20Poly1305Kernel.pas', + ClpIGcmKernel in '..\..\Interfaces\Crypto\CipherKernels\Block\ClpIGcmKernel.pas', + ClpIOcbKernel in '..\..\Interfaces\Crypto\CipherKernels\Block\ClpIOcbKernel.pas', + ClpICcmKernel in '..\..\Interfaces\Crypto\CipherKernels\Block\ClpICcmKernel.pas', + ClpIEaxKernel in '..\..\Interfaces\Crypto\CipherKernels\Block\ClpIEaxKernel.pas', + ClpIGcmSivKernel in '..\..\Interfaces\Crypto\CipherKernels\Block\ClpIGcmSivKernel.pas', + ClpICtrKernel in '..\..\Interfaces\Crypto\CipherKernels\Block\ClpICtrKernel.pas', + ClpICbcKernel in '..\..\Interfaces\Crypto\CipherKernels\Block\ClpICbcKernel.pas', + ClpCipherKernelFactoryBase in '..\..\Crypto\CipherKernels\ClpCipherKernelFactoryBase.pas', + ClpCipherKernelRegistry in '..\..\Crypto\CipherKernels\ClpCipherKernelRegistry.pas', + ClpAesFusedAeadSimd in '..\..\Crypto\CipherKernels\Block\Internal\ClpAesFusedAeadSimd.pas', + ClpAesNiFusedX86Backend in '..\..\Crypto\CipherKernels\Block\Internal\ClpAesNiFusedX86Backend.pas', ClpBinPolySimd in '..\..\Math\BinPoly\ClpBinPolySimd.pas', - ClpAesNiOcbKernel in '..\..\Crypto\Modes\Fused\ClpAesNiOcbKernel.pas', - ClpAesNiCcmKernel in '..\..\Crypto\Modes\Fused\ClpAesNiCcmKernel.pas', - ClpAesNiEaxKernel in '..\..\Crypto\Modes\Fused\ClpAesNiEaxKernel.pas', - ClpAesNiGcmKernel in '..\..\Crypto\Modes\Fused\ClpAesNiGcmKernel.pas', - ClpAesNiCtrKernel in '..\..\Crypto\Modes\Fused\ClpAesNiCtrKernel.pas', - ClpAesNiCbcKernel in '..\..\Crypto\Modes\Fused\ClpAesNiCbcKernel.pas', - ClpPclmulGcmSivKernel in '..\..\Crypto\Modes\Fused\ClpPclmulGcmSivKernel.pas', - ClpFusedKernelDefaults in '..\..\Crypto\Modes\Fused\ClpFusedKernelDefaults.pas', + ClpAesNiOcbKernel in '..\..\Crypto\CipherKernels\Block\ClpAesNiOcbKernel.pas', + ClpAesNiCcmKernel in '..\..\Crypto\CipherKernels\Block\ClpAesNiCcmKernel.pas', + ClpAesNiEaxKernel in '..\..\Crypto\CipherKernels\Block\ClpAesNiEaxKernel.pas', + ClpAesNiGcmKernel in '..\..\Crypto\CipherKernels\Block\ClpAesNiGcmKernel.pas', + ClpAesNiCtrKernel in '..\..\Crypto\CipherKernels\Block\ClpAesNiCtrKernel.pas', + ClpAesNiCbcKernel in '..\..\Crypto\CipherKernels\Block\ClpAesNiCbcKernel.pas', + ClpPclmulGcmSivKernel in '..\..\Crypto\CipherKernels\Block\ClpPclmulGcmSivKernel.pas', + ClpCipherKernelDefaults in '..\..\Crypto\CipherKernels\ClpCipherKernelDefaults.pas', ClpAeadParameters in '..\..\Crypto\Parameters\ClpAeadParameters.pas', ClpBufferedAeadCipher in '..\..\Crypto\ClpBufferedAeadCipher.pas', ClpBufferedAeadBlockCipher in '..\..\Crypto\ClpBufferedAeadBlockCipher.pas', diff --git a/CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.lpk b/CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.lpk index 37b2c89c..b43b8ee6 100644 --- a/CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.lpk +++ b/CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.lpk @@ -10,7 +10,7 @@ - + @@ -31,7 +31,7 @@ Acknowledgements: Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring the development of this library "/> - + @@ -2706,60 +2706,60 @@ Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring the devel - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - + - + - + - - + + @@ -3178,7 +3178,7 @@ Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring the devel - + @@ -3190,11 +3190,11 @@ Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring the devel - - + + - + @@ -3206,17 +3206,29 @@ Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring the devel - - + + - + + + + + + + + + + + + + diff --git a/CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.pas b/CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.pas index 9ce3f30f..1b204020 100644 --- a/CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.pas +++ b/CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.pas @@ -218,11 +218,11 @@ interface ClpArmSimdFeatures, ClpSimdLevels, ClpX86SimdFeatures, ClpArmHwCapProvider, ClpDarwinSysCtl, ClpIBulkBlockCipherMode, ClpIBulkBlockCipher, ClpBlockCipherBulkUtilities, ClpCipherModeParameterUtilities, - ClpGcmSivUtilities, ClpFusedKernelTypes, ClpIFusedGcmKernel, - ClpIFusedOcbKernel, ClpIFusedCcmKernel, ClpIFusedEaxKernel, - ClpIFusedGcmSivKernel, ClpFusedKernelRegistry, ClpAesFusedAeadSimd, + ClpGcmSivUtilities, ClpCipherKernelTypes, ClpIGcmKernel, + ClpIOcbKernel, ClpICcmKernel, ClpIEaxKernel, + ClpIGcmSivKernel, ClpCipherKernelRegistry, ClpAesFusedAeadSimd, ClpAesNiOcbKernel, ClpAesNiCcmKernel, ClpAesNiEaxKernel, ClpAesNiGcmKernel, - ClpPclmulGcmSivKernel, ClpFusedKernelDefaults, ClpXChaCha20Engine, + ClpPclmulGcmSivKernel, ClpCipherKernelDefaults, ClpXChaCha20Engine, ClpIXChaCha20Engine, ClpXChaCha20Poly1305, ClpIXChaCha20Poly1305, ClpDigestStream, ClpMacSink, ClpMacStream, ClpSignerStream, ClpDefaultMacCalculator, ClpDefaultMacResult, ClpIMacAlgorithmFinder, @@ -256,8 +256,10 @@ interface ClpSalsaX86Backend, ClpPoly1305State, ClpPoly1305Simd, ClpPoly1305X86Backend, ClpGhashSimd, ClpGhashX86Backend, ClpGcmSivSimd, ClpGcmSivX86Backend, ClpAesNiFusedX86Backend, ClpBinPolySimd, ClpAesSimd, - ClpIFusedCtrKernel, ClpAesNiCtrKernel, ClpByteXorSimd, ClpByteXorX86Backend, - ClpIFusedCbcKernel, ClpAesNiCbcKernel, ClpIBulkStreamCipher; + ClpICtrKernel, ClpAesNiCtrKernel, ClpByteXorSimd, ClpByteXorX86Backend, + ClpICbcKernel, ClpAesNiCbcKernel, ClpIBulkStreamCipher, + ClpICipherKernelFactory, ClpIChaCha20Poly1305Kernel, + ClpCipherKernelFactoryBase; implementation