diff --git a/crypto/src/crypto/encodings/OaepEncoding.cs b/crypto/src/crypto/encodings/OaepEncoding.cs
index 6871a039a..9ddaec779 100644
--- a/crypto/src/crypto/encodings/OaepEncoding.cs
+++ b/crypto/src/crypto/encodings/OaepEncoding.cs
@@ -74,7 +74,7 @@ namespace Org.BouncyCastle.Crypto.Encodings
}
else
{
- this.random = CryptoServicesRegistrar.GetSecureRandom();
+ this.random = forEncryption ? CryptoServicesRegistrar.GetSecureRandom() : null;
}
engine.Init(forEncryption, parameters);
@@ -285,24 +285,17 @@ namespace Org.BouncyCastle.Crypto.Encodings
return output;
}
- private byte[] MaskGeneratorFunction(
- byte[] Z,
- int zOff,
- int zLen,
- int length)
+ private byte[] MaskGeneratorFunction(byte[] Z, int zOff, int zLen, int length)
{
- if (mgf1Hash is IXof)
+ if (mgf1Hash is IXof xof)
{
byte[] mask = new byte[length];
- mgf1Hash.BlockUpdate(Z, zOff, zLen);
- ((IXof)mgf1Hash).OutputFinal(mask, 0, mask.Length);
-
+ xof.BlockUpdate(Z, zOff, zLen);
+ xof.OutputFinal(mask, 0, length);
return mask;
}
- else
- {
- return MaskGeneratorFunction1(Z, zOff, zLen, length);
- }
+
+ return MaskGeneratorFunction1(Z, zOff, zLen, length);
}
/**
|