From 67a5d0f5805539c0a05a5f7204d5f2cbd0a74f1a Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Tue, 7 Mar 2023 11:01:19 +0700 Subject: Add BasicGcmMultiplier.IsHardwareAccelerated --- crypto/src/crypto/modes/GCMBlockCipher.cs | 7 +------ crypto/src/crypto/modes/gcm/BasicGcmMultiplier.cs | 9 +++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'crypto') diff --git a/crypto/src/crypto/modes/GCMBlockCipher.cs b/crypto/src/crypto/modes/GCMBlockCipher.cs index 16e9e4597..f41214c5d 100644 --- a/crypto/src/crypto/modes/GCMBlockCipher.cs +++ b/crypto/src/crypto/modes/GCMBlockCipher.cs @@ -35,13 +35,8 @@ namespace Org.BouncyCastle.Crypto.Modes internal static IGcmMultiplier CreateGcmMultiplier() { -#if NETCOREAPP3_0_OR_GREATER - // TODO Prefer more tightly coupled test - if (Pclmulqdq.IsSupported) - { + if (BasicGcmMultiplier.IsHardwareAccelerated) return new BasicGcmMultiplier(); - } -#endif return new Tables4kGcmMultiplier(); } diff --git a/crypto/src/crypto/modes/gcm/BasicGcmMultiplier.cs b/crypto/src/crypto/modes/gcm/BasicGcmMultiplier.cs index abae4f3fa..7fa275449 100644 --- a/crypto/src/crypto/modes/gcm/BasicGcmMultiplier.cs +++ b/crypto/src/crypto/modes/gcm/BasicGcmMultiplier.cs @@ -1,4 +1,7 @@ using System; +#if NETCOREAPP3_0_OR_GREATER +using System.Runtime.Intrinsics.X86; +#endif namespace Org.BouncyCastle.Crypto.Modes.Gcm { @@ -6,6 +9,12 @@ namespace Org.BouncyCastle.Crypto.Modes.Gcm public class BasicGcmMultiplier : IGcmMultiplier { +#if NETCOREAPP3_0_OR_GREATER + internal static bool IsHardwareAccelerated => Pclmulqdq.IsSupported; +#else + internal static bool IsHardwareAccelerated => false; +#endif + private GcmUtilities.FieldElement H; public void Init(byte[] H) -- cgit 1.4.1