summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2019-08-04 18:10:17 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2019-08-04 18:10:17 +0700
commit66586c5998d313d37817b486a11115497b30fe40 (patch)
tree5c63bd438c7fef772ee91c1390cb9c0bf917c390
parentUse GetInstance instead of cast (diff)
downloadBouncyCastle.NET-ed25519-66586c5998d313d37817b486a11115497b30fe40.tar.xz
Use Arrays.Reverse utility method in several places
-rw-r--r--crypto/src/crypto/signers/ECGOST3410Signer.cs15
-rw-r--r--crypto/src/crypto/signers/GOST3410Signer.cs17
-rw-r--r--crypto/src/security/PrivateKeyFactory.cs11
3 files changed, 8 insertions, 35 deletions
diff --git a/crypto/src/crypto/signers/ECGOST3410Signer.cs b/crypto/src/crypto/signers/ECGOST3410Signer.cs
index f08d16551..ac6b080a5 100644
--- a/crypto/src/crypto/signers/ECGOST3410Signer.cs
+++ b/crypto/src/crypto/signers/ECGOST3410Signer.cs
@@ -6,6 +6,7 @@ using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Math.EC;
 using Org.BouncyCastle.Math.EC.Multiplier;
 using Org.BouncyCastle.Security;
+using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Crypto.Signers
 {
@@ -78,12 +79,7 @@ namespace Org.BouncyCastle.Crypto.Signers
                 throw new InvalidOperationException("not initialized for signing");
             }
 
-            byte[] mRev = new byte[message.Length]; // conversion is little-endian
-            for (int i = 0; i != mRev.Length; i++)
-            {
-                mRev[i] = message[mRev.Length - 1 - i];
-            }
-
+            byte[] mRev = Arrays.Reverse(message); // conversion is little-endian
             BigInteger e = new BigInteger(1, mRev);
 
             ECDomainParameters ec = key.Parameters;
@@ -133,12 +129,7 @@ namespace Org.BouncyCastle.Crypto.Signers
                 throw new InvalidOperationException("not initialized for verification");
             }
 
-            byte[] mRev = new byte[message.Length]; // conversion is little-endian
-            for (int i = 0; i != mRev.Length; i++)
-            {
-                mRev[i] = message[mRev.Length - 1 - i];
-            }
-
+            byte[] mRev = Arrays.Reverse(message); // conversion is little-endian
             BigInteger e = new BigInteger(1, mRev);
             BigInteger n = key.Parameters.N;
 
diff --git a/crypto/src/crypto/signers/GOST3410Signer.cs b/crypto/src/crypto/signers/GOST3410Signer.cs
index c5f3bd5ef..bcc1125b1 100644
--- a/crypto/src/crypto/signers/GOST3410Signer.cs
+++ b/crypto/src/crypto/signers/GOST3410Signer.cs
@@ -3,6 +3,7 @@ using System;
 using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Security;
+using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Crypto.Signers
 {
@@ -67,12 +68,7 @@ namespace Org.BouncyCastle.Crypto.Signers
         public virtual BigInteger[] GenerateSignature(
 			byte[] message)
 		{
-			byte[] mRev = new byte[message.Length]; // conversion is little-endian
-			for (int i = 0; i != mRev.Length; i++)
-			{
-				mRev[i] = message[mRev.Length - 1 - i];
-			}
-
+            byte[] mRev = Arrays.Reverse(message); // conversion is little-endian
 			BigInteger m = new BigInteger(1, mRev);
 			Gost3410Parameters parameters = key.Parameters;
 			BigInteger k;
@@ -102,13 +98,8 @@ namespace Org.BouncyCastle.Crypto.Signers
 			BigInteger	r,
 			BigInteger	s)
 		{
-			byte[] mRev = new byte[message.Length]; // conversion is little-endian
-			for (int i = 0; i != mRev.Length; i++)
-			{
-				mRev[i] = message[mRev.Length - 1 - i];
-			}
-
-			BigInteger m = new BigInteger(1, mRev);
+            byte[] mRev = Arrays.Reverse(message); // conversion is little-endian
+            BigInteger m = new BigInteger(1, mRev);
 			Gost3410Parameters parameters = key.Parameters;
 
 			if (r.SignValue < 0 || parameters.Q.CompareTo(r) <= 0)
diff --git a/crypto/src/security/PrivateKeyFactory.cs b/crypto/src/security/PrivateKeyFactory.cs
index f7709160d..ddcb88992 100644
--- a/crypto/src/security/PrivateKeyFactory.cs
+++ b/crypto/src/security/PrivateKeyFactory.cs
@@ -213,18 +213,9 @@ namespace Org.BouncyCastle.Security
                     }
                     else
                     {
-                        byte[] encVal = Asn1OctetString.GetInstance(privKey).GetOctets();
-                        byte[] dVal = new byte[encVal.Length];
-
-                        for (int i = 0; i != encVal.Length; i++)
-                        {
-                            dVal[i] = encVal[encVal.Length - 1 - i];
-                        }
-
+                        byte[] dVal = Arrays.Reverse(Asn1OctetString.GetInstance(privKey).GetOctets());
                         d = new BigInteger(1, dVal);
                     }
-
-
                 }
                 else
                 {