summary refs log tree commit diff
path: root/crypto/src/crypto/signers/Ed448Signer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/crypto/signers/Ed448Signer.cs')
-rw-r--r--crypto/src/crypto/signers/Ed448Signer.cs51
1 files changed, 28 insertions, 23 deletions
diff --git a/crypto/src/crypto/signers/Ed448Signer.cs b/crypto/src/crypto/signers/Ed448Signer.cs
index d18f956a8..0863e5dd1 100644
--- a/crypto/src/crypto/signers/Ed448Signer.cs
+++ b/crypto/src/crypto/signers/Ed448Signer.cs
@@ -1,6 +1,5 @@
 using System;
 using System.IO;
-using System.Runtime.CompilerServices;
 
 using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Math.EC.Rfc8032;
@@ -82,49 +81,55 @@ namespace Org.BouncyCastle.Crypto.Signers
 
         private class Buffer : MemoryStream
         {
-            [MethodImpl(MethodImplOptions.Synchronized)]
             internal byte[] GenerateSignature(Ed448PrivateKeyParameters privateKey, Ed448PublicKeyParameters publicKey, byte[] ctx)
             {
+                lock (this)
+                {
 #if PORTABLE
                 byte[] buf = ToArray();
                 int count = buf.Length;
 #else
-                byte[] buf = GetBuffer();
-                int count = (int)Position;
+                    byte[] buf = GetBuffer();
+                    int count = (int)Position;
 #endif
-                byte[] signature = new byte[Ed448PrivateKeyParameters.SignatureSize];
-                privateKey.Sign(Ed448.Algorithm.Ed448, publicKey, ctx, buf, 0, count, signature, 0);
-                Reset();
-                return signature;
+                    byte[] signature = new byte[Ed448PrivateKeyParameters.SignatureSize];
+                    privateKey.Sign(Ed448.Algorithm.Ed448, publicKey, ctx, buf, 0, count, signature, 0);
+                    Reset();
+                    return signature;
+                }
             }
 
-            [MethodImpl(MethodImplOptions.Synchronized)]
             internal bool VerifySignature(Ed448PublicKeyParameters publicKey, byte[] ctx, byte[] signature)
             {
+                lock (this)
+                {
 #if PORTABLE
-                byte[] buf = ToArray();
-                int count = buf.Length;
+                    byte[] buf = ToArray();
+                    int count = buf.Length;
 #else
-                byte[] buf = GetBuffer();
-                int count = (int)Position;
+                    byte[] buf = GetBuffer();
+                    int count = (int)Position;
 #endif
-                byte[] pk = publicKey.GetEncoded();
-                bool result = Ed448.Verify(signature, 0, pk, 0, ctx, buf, 0, count);
-                Reset();
-                return result;
+                    byte[] pk = publicKey.GetEncoded();
+                    bool result = Ed448.Verify(signature, 0, pk, 0, ctx, buf, 0, count);
+                    Reset();
+                    return result;
+                }
             }
 
-            [MethodImpl(MethodImplOptions.Synchronized)]
             internal void Reset()
             {
-                long count = Position;
+                lock (this)
+                {
+                    long count = Position;
 #if PORTABLE
-                this.Position = 0L;
-                Streams.WriteZeroes(this, count);
+                    this.Position = 0L;
+                    Streams.WriteZeroes(this, count);
 #else
-                Array.Clear(GetBuffer(), 0, (int)count);
+                    Array.Clear(GetBuffer(), 0, (int)count);
 #endif
-                this.Position = 0L;
+                    this.Position = 0L;
+                }
             }
         }
     }