diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-10-06 12:19:49 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-10-06 12:19:49 +0700 |
commit | 2d28fafa7fe1becdada43f939b5121946468052c (patch) | |
tree | ab0b57beefd9976b7d3091fbefc0fab4635f3d04 /crypto/src/openpgp/PgpPublicKey.cs | |
parent | Refactor RSACoreEngine.ConvertOutput (diff) | |
download | BouncyCastle.NET-ed25519-2d28fafa7fe1becdada43f939b5121946468052c.tar.xz |
Refactor stackalloc usage
Diffstat (limited to 'crypto/src/openpgp/PgpPublicKey.cs')
-rw-r--r-- | crypto/src/openpgp/PgpPublicKey.cs | 6 |
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 |