summary refs log tree commit diff
path: root/crypto/src/util
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-11-16 21:30:04 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-11-16 21:30:04 +0700
commit8bda1de4207632587d2df5fbd08797e22d5f8463 (patch)
tree206f6e7b0427cd96e7203d580ac08ffb4557180b /crypto/src/util
parentRemove redundant semicolons (diff)
downloadBouncyCastle.NET-ed25519-8bda1de4207632587d2df5fbd08797e22d5f8463.tar.xz
Finish port of latest PRNG/DRBG stuff from Java
Diffstat (limited to 'crypto/src/util')
-rw-r--r--crypto/src/util/Arrays.cs64
1 files changed, 20 insertions, 44 deletions
diff --git a/crypto/src/util/Arrays.cs b/crypto/src/util/Arrays.cs
index 32c56b8b5..df9b4e7ee 100644
--- a/crypto/src/util/Arrays.cs
+++ b/crypto/src/util/Arrays.cs
@@ -591,57 +591,33 @@ namespace Org.BouncyCastle.Utilities
             return rv;
         }
 
-        public static byte[] Concatenate(byte[] a, byte[] b, byte[] c)
+        public static byte[] ConcatenateAll(params byte[][] vs)
         {
-                if (a != null && b != null && c != null)
-                {
-                        byte[] rv = new byte[a.Length + b.Length + c.Length];
-
-                        Array.Copy(a, 0, rv, 0, a.Length);
-                        Array.Copy(b, 0, rv, a.Length, b.Length);
-                      	Array.Copy(c, 0, rv, a.Length + b.Length, c.Length);
+            byte[][] nonNull = new byte[vs.Length][];
+            int count = 0;
+            int totalLength = 0;
 
-                        return rv;
-                }
-                else if (b == null)
-                {
-                        return Concatenate(a, c);
-	        }
-                else
+            for (int i = 0; i < vs.Length; ++i)
+            {
+                byte[] v = vs[i];
+                if (v != null)
                 {
-                        return Concatenate(a, b);
+                    nonNull[count++] = v;
+                    totalLength += v.Length;
                 }
-        }
+            }
 
-        public static byte[] Concatenate(byte[] a, byte[] b, byte[] c, byte[] d)
-        {
-                if (a != null && b != null && c != null && d != null)
-                {
-                        byte[] rv = new byte[a.Length + b.Length + c.Length + d.Length];
+            byte[] result = new byte[totalLength];
+            int pos = 0;
 
-                        Array.Copy(a, 0, rv, 0, a.Length);
-                        Array.Copy(b, 0, rv, a.Length, b.Length);
-                        Array.Copy(c, 0, rv, a.Length + b.Length, c.Length);
-                        Array.Copy(d, 0, rv, a.Length + b.Length + c.Length, d.Length);
+            for (int j = 0; j < count; ++j)
+            {
+                byte[] v = nonNull[j];
+                Array.Copy(v, 0, result, pos, v.Length);
+                pos += v.Length;
+            }
 
-                        return rv;
-                }
-                else if (d == null)
-                {
-                        return Concatenate(a, b, c);
-                }
-                else if (c == null)
-                {
-                        return Concatenate(a, b, d);
-                }
-                else if (b == null)
-                {
-                        return Concatenate(a, c, d);
-                }
-                else
-                {
-                        return Concatenate(b, c, d);
-                }
+            return result;
         }
 
         public static int[] Concatenate(int[] a, int[] b)