diff options
Diffstat (limited to 'crypto/src/crypto/signers/Ed25519ctxSigner.cs')
-rw-r--r-- | crypto/src/crypto/signers/Ed25519ctxSigner.cs | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/crypto/src/crypto/signers/Ed25519ctxSigner.cs b/crypto/src/crypto/signers/Ed25519ctxSigner.cs index 965453011..60c708019 100644 --- a/crypto/src/crypto/signers/Ed25519ctxSigner.cs +++ b/crypto/src/crypto/signers/Ed25519ctxSigner.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(Ed25519PrivateKeyParameters privateKey, Ed25519PublicKeyParameters publicKey, byte[] ctx) { + 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[] signature = new byte[Ed25519PrivateKeyParameters.SignatureSize]; - privateKey.Sign(Ed25519.Algorithm.Ed25519ctx, publicKey, ctx, buf, 0, count, signature, 0); - Reset(); - return signature; + byte[] signature = new byte[Ed25519PrivateKeyParameters.SignatureSize]; + privateKey.Sign(Ed25519.Algorithm.Ed25519ctx, publicKey, ctx, buf, 0, count, signature, 0); + Reset(); + return signature; + } } - [MethodImpl(MethodImplOptions.Synchronized)] internal bool VerifySignature(Ed25519PublicKeyParameters 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 = Ed25519.Verify(signature, 0, pk, 0, ctx, buf, 0, count); - Reset(); - return result; + byte[] pk = publicKey.GetEncoded(); + bool result = Ed25519.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; + } } } } |