From 4f8cc0568c9368c0d2dbe04ef286458221e6db59 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sun, 5 Apr 2020 18:54:21 +0700 Subject: Reset after wrong-length failure --- crypto/src/crypto/signers/Ed25519Signer.cs | 3 +++ crypto/src/crypto/signers/Ed25519ctxSigner.cs | 3 +++ crypto/src/crypto/signers/Ed25519phSigner.cs | 3 +++ crypto/src/crypto/signers/Ed448Signer.cs | 3 +++ crypto/src/crypto/signers/Ed448phSigner.cs | 3 +++ 5 files changed, 15 insertions(+) (limited to 'crypto/src') diff --git a/crypto/src/crypto/signers/Ed25519Signer.cs b/crypto/src/crypto/signers/Ed25519Signer.cs index e58d14ea4..eb3d25398 100644 --- a/crypto/src/crypto/signers/Ed25519Signer.cs +++ b/crypto/src/crypto/signers/Ed25519Signer.cs @@ -98,7 +98,10 @@ namespace Org.BouncyCastle.Crypto.Signers internal bool VerifySignature(Ed25519PublicKeyParameters publicKey, byte[] signature) { if (Ed25519.SignatureSize != signature.Length) + { + Reset(); return false; + } lock (this) { diff --git a/crypto/src/crypto/signers/Ed25519ctxSigner.cs b/crypto/src/crypto/signers/Ed25519ctxSigner.cs index 2b5296e96..3610e25de 100644 --- a/crypto/src/crypto/signers/Ed25519ctxSigner.cs +++ b/crypto/src/crypto/signers/Ed25519ctxSigner.cs @@ -100,7 +100,10 @@ namespace Org.BouncyCastle.Crypto.Signers internal bool VerifySignature(Ed25519PublicKeyParameters publicKey, byte[] ctx, byte[] signature) { if (Ed25519.SignatureSize != signature.Length) + { + Reset(); return false; + } lock (this) { diff --git a/crypto/src/crypto/signers/Ed25519phSigner.cs b/crypto/src/crypto/signers/Ed25519phSigner.cs index cb3c3080a..8f4afab19 100644 --- a/crypto/src/crypto/signers/Ed25519phSigner.cs +++ b/crypto/src/crypto/signers/Ed25519phSigner.cs @@ -74,7 +74,10 @@ namespace Org.BouncyCastle.Crypto.Signers if (forSigning || null == publicKey) throw new InvalidOperationException("Ed25519phSigner not initialised for verification"); if (Ed25519.SignatureSize != signature.Length) + { + prehash.Reset(); return false; + } byte[] pk = publicKey.GetEncoded(); return Ed25519.VerifyPrehash(signature, 0, pk, 0, context, prehash); diff --git a/crypto/src/crypto/signers/Ed448Signer.cs b/crypto/src/crypto/signers/Ed448Signer.cs index 9d1495f2e..746029834 100644 --- a/crypto/src/crypto/signers/Ed448Signer.cs +++ b/crypto/src/crypto/signers/Ed448Signer.cs @@ -100,7 +100,10 @@ namespace Org.BouncyCastle.Crypto.Signers internal bool VerifySignature(Ed448PublicKeyParameters publicKey, byte[] ctx, byte[] signature) { if (Ed448.SignatureSize != signature.Length) + { + Reset(); return false; + } lock (this) { diff --git a/crypto/src/crypto/signers/Ed448phSigner.cs b/crypto/src/crypto/signers/Ed448phSigner.cs index f01b6bfd4..197c2f706 100644 --- a/crypto/src/crypto/signers/Ed448phSigner.cs +++ b/crypto/src/crypto/signers/Ed448phSigner.cs @@ -74,7 +74,10 @@ namespace Org.BouncyCastle.Crypto.Signers if (forSigning || null == publicKey) throw new InvalidOperationException("Ed448phSigner not initialised for verification"); if (Ed448.SignatureSize != signature.Length) + { + prehash.Reset(); return false; + } byte[] pk = publicKey.GetEncoded(); return Ed448.VerifyPrehash(signature, 0, pk, 0, context, prehash); -- cgit 1.5.1