From c1e0d224b9e34b40679ec105cd3a007a9ce37054 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Mon, 30 Jan 2023 16:20:40 +0700 Subject: Ensure configured SecureRandom is passed on --- crypto/src/crypto/signers/PssSigner.cs | 15 +++++++-------- crypto/src/crypto/signers/X931Signer.cs | 11 +++++++++-- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'crypto/src') diff --git a/crypto/src/crypto/signers/PssSigner.cs b/crypto/src/crypto/signers/PssSigner.cs index c1613c8d1..2e4c37772 100644 --- a/crypto/src/crypto/signers/PssSigner.cs +++ b/crypto/src/crypto/signers/PssSigner.cs @@ -158,15 +158,15 @@ namespace Org.BouncyCastle.Crypto.Signers { parameters = withRandom.Parameters; random = withRandom.Random; - } - else + cipher.Init(forSigning, withRandom); + } + else { random = forSigning ? CryptoServicesRegistrar.GetSecureRandom() : null; - } - - cipher.Init(forSigning, parameters); + cipher.Init(forSigning, parameters); + } - RsaKeyParameters kParam; + RsaKeyParameters kParam; if (parameters is RsaBlindingParameters blinding) { kParam = blinding.PublicKey; @@ -185,8 +185,7 @@ namespace Org.BouncyCastle.Crypto.Signers } /// clear possible sensitive data - private void ClearBlock( - byte[] block) + private void ClearBlock(byte[] block) { Array.Clear(block, 0, block.Length); } diff --git a/crypto/src/crypto/signers/X931Signer.cs b/crypto/src/crypto/signers/X931Signer.cs index 9db4e1642..c185eacfd 100644 --- a/crypto/src/crypto/signers/X931Signer.cs +++ b/crypto/src/crypto/signers/X931Signer.cs @@ -71,9 +71,16 @@ namespace Org.BouncyCastle.Crypto.Signers public virtual void Init(bool forSigning, ICipherParameters parameters) { - kParam = (RsaKeyParameters)parameters; + if (parameters is ParametersWithRandom withRandom) + { + kParam = (RsaKeyParameters)withRandom.Parameters; + } + else + { + kParam = (RsaKeyParameters)parameters; + } - cipher.Init(forSigning, kParam); + cipher.Init(forSigning, parameters); keyBits = kParam.Modulus.BitLength; -- cgit 1.4.1