summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-10-06 12:16:59 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-10-06 12:16:59 +0700
commit4b68aeba5f86a3eb536e66114b99e241c254dc0b (patch)
tree9acad43c2e2252c39c00426c4e467d097da29e95 /crypto/src
parentRefactor stackalloc usage in TLS (diff)
downloadBouncyCastle.NET-ed25519-4b68aeba5f86a3eb536e66114b99e241c254dc0b.tar.xz
Refactor RSACoreEngine.ConvertOutput
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/crypto/engines/RSACoreEngine.cs24
1 files changed, 5 insertions, 19 deletions
diff --git a/crypto/src/crypto/engines/RSACoreEngine.cs b/crypto/src/crypto/engines/RSACoreEngine.cs
index 5f6e98eea..bd3d62f7c 100644
--- a/crypto/src/crypto/engines/RSACoreEngine.cs
+++ b/crypto/src/crypto/engines/RSACoreEngine.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.Engines
 {
@@ -103,28 +104,13 @@ namespace Org.BouncyCastle.Crypto.Engines
 			return input;
 		}
 
-        public virtual byte[] ConvertOutput(
-			BigInteger result)
+        public virtual byte[] ConvertOutput(BigInteger result)
 		{
             CheckInitialised();
 
-            byte[] output = result.ToByteArrayUnsigned();
-
-			if (forEncryption)
-			{
-				int outSize = GetOutputBlockSize();
-
-				// TODO To avoid this, create version of BigInteger.ToByteArray that
-				// writes to an existing array
-				if (output.Length < outSize) // have ended up with less bytes than normal, lengthen
-				{
-					byte[] tmp = new byte[outSize];
-					output.CopyTo(tmp, tmp.Length - output.Length);
-					output = tmp;
-				}
-			}
-
-			return output;
+			return forEncryption
+				? BigIntegers.AsUnsignedByteArray(GetOutputBlockSize(), result)
+				: BigIntegers.AsUnsignedByteArray(result);
 		}
 
         public virtual BigInteger ProcessBlock(