summary refs log tree commit diff
path: root/crypto/src/crypto/parameters/X448PrivateKeyParameters.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/crypto/parameters/X448PrivateKeyParameters.cs')
-rw-r--r--crypto/src/crypto/parameters/X448PrivateKeyParameters.cs30
1 files changed, 29 insertions, 1 deletions
diff --git a/crypto/src/crypto/parameters/X448PrivateKeyParameters.cs b/crypto/src/crypto/parameters/X448PrivateKeyParameters.cs
index 8ae7aa17d..555773b10 100644
--- a/crypto/src/crypto/parameters/X448PrivateKeyParameters.cs
+++ b/crypto/src/crypto/parameters/X448PrivateKeyParameters.cs
@@ -33,6 +33,17 @@ namespace Org.BouncyCastle.Crypto.Parameters
             Array.Copy(buf, off, data, 0, KeySize);
         }
 
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+        public X448PrivateKeyParameters(ReadOnlySpan<byte> buf)
+            : base(true)
+        {
+            if (buf.Length != KeySize)
+                throw new ArgumentException("must have length " + KeySize, nameof(buf));
+
+            buf.CopyTo(data);
+        }
+#endif
+
         public X448PrivateKeyParameters(Stream input)
             : base(true)
         {
@@ -45,6 +56,13 @@ namespace Org.BouncyCastle.Crypto.Parameters
             Array.Copy(data, 0, buf, off, KeySize);
         }
 
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+        public void Encode(Span<byte> buf)
+        {
+            data.CopyTo(buf);
+        }
+#endif
+
         public byte[] GetEncoded()
         {
             return Arrays.Clone(data);
@@ -52,17 +70,27 @@ namespace Org.BouncyCastle.Crypto.Parameters
 
         public X448PublicKeyParameters GeneratePublicKey()
         {
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+            Span<byte> publicKey = stackalloc byte[X448.PointSize];
+            X448.GeneratePublicKey(data, publicKey);
+            return new X448PublicKeyParameters(publicKey);
+#else
             byte[] publicKey = new byte[X448.PointSize];
             X448.GeneratePublicKey(data, 0, publicKey, 0);
             return new X448PublicKeyParameters(publicKey, 0);
+#endif
         }
 
         public void GenerateSecret(X448PublicKeyParameters publicKey, byte[] buf, int off)
         {
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+            GenerateSecret(publicKey, buf.AsSpan(off));
+#else
             byte[] encoded = new byte[X448.PointSize];
             publicKey.Encode(encoded, 0);
             if (!X448.CalculateAgreement(data, 0, encoded, 0, buf, off))
                 throw new InvalidOperationException("X448 agreement failed");
+#endif
         }
 
 #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
@@ -78,7 +106,7 @@ namespace Org.BouncyCastle.Crypto.Parameters
         private static byte[] Validate(byte[] buf)
         {
             if (buf.Length != KeySize)
-                throw new ArgumentException("must have length " + KeySize, "buf");
+                throw new ArgumentException("must have length " + KeySize, nameof(buf));
 
             return buf;
         }