From 0ebde6504685c71c5aa4a5e2ad4be1a04a8a6ef1 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 8 Jun 2023 14:26:10 +0700 Subject: Add more Pack method variants --- crypto/src/crypto/util/Pack.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crypto/src/crypto/util/Pack.cs b/crypto/src/crypto/util/Pack.cs index 3977d221e..dc0e93b7d 100644 --- a/crypto/src/crypto/util/Pack.cs +++ b/crypto/src/crypto/util/Pack.cs @@ -1036,6 +1036,26 @@ namespace Org.BouncyCastle.Crypto.Utilities } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void UInt32_To_LE_High(uint n, Span bs) + { + UInt32_To_LE_Low(n >> ((4 - bs.Length) << 3), bs); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void UInt32_To_LE_Low(uint n, Span bs) + { + int len = bs.Length; + Debug.Assert(1 <= len && len <= 4); + + bs[0] = (byte)n; + for (int i = 1; i < len; ++i) + { + n >>= 8; + bs[i] = (byte)n; + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void UInt64_To_BE(ulong n, Span bs) { -- cgit 1.4.1