summary refs log tree commit diff
path: root/crypto/src/util/Integers.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/util/Integers.cs')
-rw-r--r--crypto/src/util/Integers.cs17
1 files changed, 17 insertions, 0 deletions
diff --git a/crypto/src/util/Integers.cs b/crypto/src/util/Integers.cs
index ff907ac80..b0c899500 100644
--- a/crypto/src/util/Integers.cs
+++ b/crypto/src/util/Integers.cs
@@ -1,5 +1,6 @@
 using System;
 #if NETCOREAPP3_0_OR_GREATER
+using System.Numerics;
 using System.Runtime.Intrinsics.X86;
 #endif
 
@@ -107,24 +108,40 @@ namespace Org.BouncyCastle.Utilities
 
         public static int RotateLeft(int i, int distance)
         {
+#if NETCOREAPP3_0_OR_GREATER
+            return (int)BitOperations.RotateLeft((uint)i, distance);
+#else
             return (i << distance) ^ (int)((uint)i >> -distance);
+#endif
         }
 
         [CLSCompliant(false)]
         public static uint RotateLeft(uint i, int distance)
         {
+#if NETCOREAPP3_0_OR_GREATER
+            return BitOperations.RotateLeft(i, distance);
+#else
             return (i << distance) ^ (i >> -distance);
+#endif
         }
 
         public static int RotateRight(int i, int distance)
         {
+#if NETCOREAPP3_0_OR_GREATER
+            return (int)BitOperations.RotateRight((uint)i, distance);
+#else
             return (int)((uint)i >> distance) ^ (i << -distance);
+#endif
         }
 
         [CLSCompliant(false)]
         public static uint RotateRight(uint i, int distance)
         {
+#if NETCOREAPP3_0_OR_GREATER
+            return BitOperations.RotateRight(i, distance);
+#else
             return (i >> distance) ^ (i << -distance);
+#endif
         }
     }
 }