From cd3c400f5cebd7a2f8af6538b745d22fe241a55e Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 8 Jun 2023 14:26:42 +0700 Subject: Minor opt in Nat.ToBigInteger --- crypto/src/math/raw/Nat.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crypto/src/math/raw/Nat.cs b/crypto/src/math/raw/Nat.cs index f4d91b180..d748e04c5 100644 --- a/crypto/src/math/raw/Nat.cs +++ b/crypto/src/math/raw/Nat.cs @@ -2,6 +2,7 @@ using System.Diagnostics; #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER using System.Numerics; +using System.Runtime.InteropServices; #endif using Org.BouncyCastle.Crypto.Utilities; @@ -2742,6 +2743,9 @@ namespace Org.BouncyCastle.Math.Raw #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER public static BigInteger ToBigInteger(int len, ReadOnlySpan x) { + if (BitConverter.IsLittleEndian) + return new BigInteger(1, MemoryMarshal.AsBytes(x), bigEndian: false); + int bsLen = len << 2; Span bs = bsLen <= 512 ? stackalloc byte[bsLen] -- cgit 1.4.1