From b791c4a030f0e06f5abab52a68a4225a33878207 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sun, 20 Nov 2022 17:43:39 +0700 Subject: Refactoring in Math.EC.Rfc8032 --- crypto/src/math/ec/rfc8032/Ed448.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'crypto/src/math/ec/rfc8032/Ed448.cs') diff --git a/crypto/src/math/ec/rfc8032/Ed448.cs b/crypto/src/math/ec/rfc8032/Ed448.cs index 7baa221a5..75629c293 100644 --- a/crypto/src/math/ec/rfc8032/Ed448.cs +++ b/crypto/src/math/ec/rfc8032/Ed448.cs @@ -298,6 +298,16 @@ namespace Org.BouncyCastle.Math.EC.Rfc8032 private static void Dom4(IXof d, byte phflag, byte[] ctx) { int n = Dom4Prefix.Length; + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + Span t = stackalloc byte[n + 2 + ctx.Length]; + Dom4Prefix.CopyTo(t); + t[n] = phflag; + t[n + 1] = (byte)ctx.Length; + ctx.CopyTo(t.Slice(n + 2)); + + d.BlockUpdate(t); +#else byte[] t = new byte[n + 2 + ctx.Length]; Dom4Prefix.CopyTo(t, 0); t[n] = phflag; @@ -305,6 +315,7 @@ namespace Org.BouncyCastle.Math.EC.Rfc8032 ctx.CopyTo(t, n + 2); d.BlockUpdate(t, 0, t.Length); +#endif } private static int EncodePoint(ref PointProjective p, byte[] r, int rOff) -- cgit 1.4.1