summary refs log tree commit diff
path: root/crypto/src/math/raw/Bits.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2020-10-18 23:42:54 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2020-10-18 23:42:54 +0700
commit08b8d058c924763cb68f835655d4b39ac300f379 (patch)
treea4925fd9367f42a0c65f5b14c619f7b179cd53de /crypto/src/math/raw/Bits.cs
parentLatest XDH, EdDSA updates from bc-java (diff)
downloadBouncyCastle.NET-ed25519-08b8d058c924763cb68f835655d4b39ac300f379.tar.xz
Add Bits and Longs classes from bc-java
Diffstat (limited to 'crypto/src/math/raw/Bits.cs')
-rw-r--r--crypto/src/math/raw/Bits.cs29
1 files changed, 29 insertions, 0 deletions
diff --git a/crypto/src/math/raw/Bits.cs b/crypto/src/math/raw/Bits.cs
new file mode 100644
index 000000000..d344e1672
--- /dev/null
+++ b/crypto/src/math/raw/Bits.cs
@@ -0,0 +1,29 @@
+using System;
+
+namespace Org.BouncyCastle.Math.Raw
+{
+    internal abstract class Bits
+    {
+        internal static uint BitPermuteStep(uint x, uint m, int s)
+        {
+            uint t = (x ^ (x >> s)) & m;
+            return (t ^ (t << s)) ^ x;
+        }
+
+        internal static ulong BitPermuteStep(ulong x, ulong m, int s)
+        {
+            ulong t = (x ^ (x >> s)) & m;
+            return (t ^ (t << s)) ^ x;
+        }
+
+        internal static uint BitPermuteStepSimple(uint x, uint m, int s)
+        {
+            return ((x & m) << s) | ((x >> s) & m);
+        }
+
+        internal static ulong BitPermuteStepSimple(ulong x, ulong m, int s)
+        {
+            return ((x & m) << s) | ((x >> s) & m);
+        }
+    }
+}