summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-02-10 13:36:06 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-02-10 13:36:06 +0700
commitfb6052b2a4be48ca6f0d0eac4d9c32b29708755a (patch)
tree773f9940e2f68826a9e6f50699cdb29b6c7c26ab /crypto/src
parentTolerate null/empty seed (diff)
downloadBouncyCastle.NET-ed25519-fb6052b2a4be48ca6f0d0eac4d9c32b29708755a.tar.xz
Add ReverseInPlace methods
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/util/Arrays.cs32
1 files changed, 32 insertions, 0 deletions
diff --git a/crypto/src/util/Arrays.cs b/crypto/src/util/Arrays.cs

index 57d79c0bb..784d45efb 100644 --- a/crypto/src/util/Arrays.cs +++ b/crypto/src/util/Arrays.cs
@@ -804,6 +804,38 @@ namespace Org.BouncyCastle.Utilities return result; } + public static byte[] ReverseInPlace(byte[] a) + { + if (null == a) + return null; + + int p1 = 0, p2 = a.Length - 1; + while (p1 < p2) + { + byte t1 = a[p1], t2 = a[p2]; + a[p1++] = t2; + a[p2--] = t1; + } + + return a; + } + + public static int[] ReverseInPlace(int[] a) + { + if (null == a) + return null; + + int p1 = 0, p2 = a.Length - 1; + while (p1 < p2) + { + int t1 = a[p1], t2 = a[p2]; + a[p1++] = t2; + a[p2--] = t1; + } + + return a; + } + public static void Clear(byte[] data) { if (null != data)