summary refs log tree commit diff
path: root/crypto/src/openpgp/PgpPublicKey.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-10-06 12:19:49 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-10-06 12:19:49 +0700
commit2d28fafa7fe1becdada43f939b5121946468052c (patch)
treeab0b57beefd9976b7d3091fbefc0fab4635f3d04 /crypto/src/openpgp/PgpPublicKey.cs
parentRefactor RSACoreEngine.ConvertOutput (diff)
downloadBouncyCastle.NET-ed25519-2d28fafa7fe1becdada43f939b5121946468052c.tar.xz
Refactor stackalloc usage
Diffstat (limited to 'crypto/src/openpgp/PgpPublicKey.cs')
-rw-r--r--crypto/src/openpgp/PgpPublicKey.cs6
1 files changed, 4 insertions, 2 deletions
diff --git a/crypto/src/openpgp/PgpPublicKey.cs b/crypto/src/openpgp/PgpPublicKey.cs
index 6d5f35018..cdb8efd36 100644
--- a/crypto/src/openpgp/PgpPublicKey.cs
+++ b/crypto/src/openpgp/PgpPublicKey.cs
@@ -510,8 +510,10 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
             BigInteger encodedPoint = ecK.EncodedPoint;
 
 #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
-            int encodingLength = BigIntegers.GetUnsignedByteLength(encodedPoint);
-            Span<byte> encoding = stackalloc byte[encodingLength];
+            int encodedLength = BigIntegers.GetUnsignedByteLength(encodedPoint);
+            Span<byte> encoding = encodedLength <= 512
+                ? stackalloc byte[encodedLength]
+                : new byte[encodedLength];
             BigIntegers.AsUnsignedByteArray(encodedPoint, encoding);
             ECPoint q = x9.Curve.DecodePoint(encoding);
 #else