diff options
6 files changed, 35 insertions, 42 deletions
diff --git a/crypto/src/crypto/generators/KDFCounterBytesGenerator.cs b/crypto/src/crypto/generators/KDFCounterBytesGenerator.cs index 470d7567b..9c2b2fdd8 100644 --- a/crypto/src/crypto/generators/KDFCounterBytesGenerator.cs +++ b/crypto/src/crypto/generators/KDFCounterBytesGenerator.cs @@ -1,4 +1,5 @@ using System; + using Org.BouncyCastle.Crypto.Macs; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Math; @@ -6,7 +7,7 @@ using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Crypto.Generators { - public class KDFCounterBytesGenerator : IMacDerivationFunction + public class KdfCounterBytesGenerator : IMacDerivationFunction { private static readonly BigInteger IntegerMax = BigInteger.ValueOf(0x7fffffff); @@ -27,7 +28,7 @@ namespace Org.BouncyCastle.Crypto.Generators // k is used as buffer for all K(i) values private byte[] k; - public KDFCounterBytesGenerator(IMac prf) + public KdfCounterBytesGenerator(IMac prf) { this.prf = prf; this.h = prf.GetMacSize(); @@ -36,7 +37,7 @@ namespace Org.BouncyCastle.Crypto.Generators public void Init(IDerivationParameters param) { - KDFCounterParameters kdfParams = param as KDFCounterParameters; + KdfCounterParameters kdfParams = param as KdfCounterParameters; if (kdfParams == null) { throw new ArgumentException("Wrong type of arguments given"); @@ -71,14 +72,9 @@ namespace Org.BouncyCastle.Crypto.Generators return prf; } - public IDigest Digest { - get - { - HMac hmac = (prf as HMac); - return hmac?.GetUnderlyingDigest(); - } + get { return prf is HMac ? ((HMac)prf).GetUnderlyingDigest() : null; } } public int GenerateBytes(byte[] output, int outOff, int length) diff --git a/crypto/src/crypto/generators/KDFDoublePipelineIterationBytesGenerator.cs b/crypto/src/crypto/generators/KDFDoublePipelineIterationBytesGenerator.cs index 57e0b2ae0..9010ae2cb 100644 --- a/crypto/src/crypto/generators/KDFDoublePipelineIterationBytesGenerator.cs +++ b/crypto/src/crypto/generators/KDFDoublePipelineIterationBytesGenerator.cs @@ -1,11 +1,12 @@ using System; + using Org.BouncyCastle.Crypto.Macs; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Math; namespace Org.BouncyCastle.Crypto.Generators { - public class KDFDoublePipelineIterationBytesGenerator : IMacDerivationFunction + public class KdfDoublePipelineIterationBytesGenerator : IMacDerivationFunction { private static readonly BigInteger IntegerMax = BigInteger.ValueOf(0x7fffffff); private static readonly BigInteger Two = BigInteger.Two; @@ -28,7 +29,7 @@ namespace Org.BouncyCastle.Crypto.Generators private byte[] k; - public KDFDoublePipelineIterationBytesGenerator(IMac prf) + public KdfDoublePipelineIterationBytesGenerator(IMac prf) { this.prf = prf; this.h = prf.GetMacSize(); @@ -39,7 +40,7 @@ namespace Org.BouncyCastle.Crypto.Generators public void Init(IDerivationParameters parameters) { - KDFDoublePipelineIterationParameters dpiParams = parameters as KDFDoublePipelineIterationParameters; + KdfDoublePipelineIterationParameters dpiParams = parameters as KdfDoublePipelineIterationParameters; if (dpiParams == null) { throw new ArgumentException("Wrong type of arguments given"); @@ -131,15 +132,11 @@ namespace Org.BouncyCastle.Crypto.Generators prf.DoFinal(k, 0); } - public IDigest Digest { - get - { - HMac hmac = (prf as HMac); - return hmac?.GetUnderlyingDigest(); - } + get { return prf is HMac ? ((HMac)prf).GetUnderlyingDigest() : null; } } + public int GenerateBytes(byte[] output, int outOff, int length) { int generatedBytesAfter = generatedBytes + length; diff --git a/crypto/src/crypto/generators/KDFFeedbackBytesGenerator.cs b/crypto/src/crypto/generators/KDFFeedbackBytesGenerator.cs index 106cd0125..19ce0ea2e 100644 --- a/crypto/src/crypto/generators/KDFFeedbackBytesGenerator.cs +++ b/crypto/src/crypto/generators/KDFFeedbackBytesGenerator.cs @@ -1,11 +1,12 @@ using System; + using Org.BouncyCastle.Crypto.Macs; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Math; namespace Org.BouncyCastle.Crypto.Generators { - public class KDFFeedbackBytesGenerator : IMacDerivationFunction + public class KdfFeedbackBytesGenerator : IMacDerivationFunction { private static readonly BigInteger IntegerMax = BigInteger.ValueOf(0x7fffffff); private static readonly BigInteger Two = BigInteger.Two; @@ -30,7 +31,7 @@ namespace Org.BouncyCastle.Crypto.Generators // k is used as buffer for all K(i) values private byte[] k; - public KDFFeedbackBytesGenerator(IMac prf) + public KdfFeedbackBytesGenerator(IMac prf) { this.prf = prf; this.h = prf.GetMacSize(); @@ -40,7 +41,7 @@ namespace Org.BouncyCastle.Crypto.Generators public void Init(IDerivationParameters parameters) { - KDFFeedbackParameters feedbackParams = parameters as KDFFeedbackParameters; + KdfFeedbackParameters feedbackParams = parameters as KdfFeedbackParameters; if (feedbackParams == null) { throw new ArgumentException("Wrong type of arguments given"); @@ -80,12 +81,9 @@ namespace Org.BouncyCastle.Crypto.Generators public IDigest Digest { - get - { - HMac hmac = (prf as HMac); - return hmac?.GetUnderlyingDigest(); - } + get { return prf is HMac ? ((HMac)prf).GetUnderlyingDigest() : null; } } + public int GenerateBytes(byte[] output, int outOff, int length) { int generatedBytesAfter = generatedBytes + length; diff --git a/crypto/src/crypto/parameters/KDFCounterParameters.cs b/crypto/src/crypto/parameters/KDFCounterParameters.cs index 79e0e5f53..49d6f7da3 100644 --- a/crypto/src/crypto/parameters/KDFCounterParameters.cs +++ b/crypto/src/crypto/parameters/KDFCounterParameters.cs @@ -1,9 +1,10 @@ using System; + using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Crypto.Parameters { - public class KDFCounterParameters : IDerivationParameters + public class KdfCounterParameters : IDerivationParameters { private byte[] ki; private byte[] fixedInputDataCounterPrefix; @@ -16,7 +17,7 @@ namespace Org.BouncyCastle.Crypto.Parameters /// <param name="ki">the KDF seed</param> /// <param name="fixedInputDataCounterSuffix">fixed input data to follow counter.</param> /// <param name="r">length of the counter in bits</param> - public KDFCounterParameters(byte[] ki, byte[] fixedInputDataCounterSuffix, int r) : this(ki, null, fixedInputDataCounterSuffix, r) + public KdfCounterParameters(byte[] ki, byte[] fixedInputDataCounterSuffix, int r) : this(ki, null, fixedInputDataCounterSuffix, r) { } @@ -29,7 +30,7 @@ namespace Org.BouncyCastle.Crypto.Parameters /// <param name="fixedInputDataCounterPrefix">fixed input data to precede counter</param> /// <param name="fixedInputDataCounterSuffix">fixed input data to follow counter.</param> /// <param name="r">length of the counter in bits.</param> - public KDFCounterParameters(byte[] ki, byte[] fixedInputDataCounterPrefix, byte[] fixedInputDataCounterSuffix, int r) + public KdfCounterParameters(byte[] ki, byte[] fixedInputDataCounterPrefix, byte[] fixedInputDataCounterSuffix, int r) { if (ki == null) { diff --git a/crypto/src/crypto/parameters/KDFDoublePipelineIterationParameters.cs b/crypto/src/crypto/parameters/KDFDoublePipelineIterationParameters.cs index d7995cb41..1a6bc8321 100644 --- a/crypto/src/crypto/parameters/KDFDoublePipelineIterationParameters.cs +++ b/crypto/src/crypto/parameters/KDFDoublePipelineIterationParameters.cs @@ -1,11 +1,11 @@ using System; + using Org.BouncyCastle.Asn1.Tests; using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Crypto.Parameters { - - public class KDFDoublePipelineIterationParameters : IDerivationParameters + public class KdfDoublePipelineIterationParameters : IDerivationParameters { // could be any valid value, using 32, don't know why private static readonly int UNUSED_R = 32; @@ -15,7 +15,7 @@ namespace Org.BouncyCastle.Crypto.Parameters private readonly int r; private readonly byte[] fixedInputData; - private KDFDoublePipelineIterationParameters(byte[] ki, byte[] fixedInputData, int r, bool useCounter) + private KdfDoublePipelineIterationParameters(byte[] ki, byte[] fixedInputData, int r, bool useCounter) { if (ki == null) { @@ -43,16 +43,16 @@ namespace Org.BouncyCastle.Crypto.Parameters this.useCounter = useCounter; } - public static KDFDoublePipelineIterationParameters CreateWithCounter( + public static KdfDoublePipelineIterationParameters CreateWithCounter( byte[] ki, byte[] fixedInputData, int r) { - return new KDFDoublePipelineIterationParameters(ki, fixedInputData, r, true); + return new KdfDoublePipelineIterationParameters(ki, fixedInputData, r, true); } - public static KDFDoublePipelineIterationParameters CreateWithoutCounter( + public static KdfDoublePipelineIterationParameters CreateWithoutCounter( byte[] ki, byte[] fixedInputData) { - return new KDFDoublePipelineIterationParameters(ki, fixedInputData, UNUSED_R, false); + return new KdfDoublePipelineIterationParameters(ki, fixedInputData, UNUSED_R, false); } public byte[] Ki diff --git a/crypto/src/crypto/parameters/KDFFeedbackParameters.cs b/crypto/src/crypto/parameters/KDFFeedbackParameters.cs index 87187dbdb..86ea232db 100644 --- a/crypto/src/crypto/parameters/KDFFeedbackParameters.cs +++ b/crypto/src/crypto/parameters/KDFFeedbackParameters.cs @@ -1,9 +1,10 @@ using System; + using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Crypto.Parameters { - public class KDFFeedbackParameters : IDerivationParameters + public class KdfFeedbackParameters : IDerivationParameters { // could be any valid value, using 32, don't know why private static readonly int UNUSED_R = -1; @@ -14,7 +15,7 @@ namespace Org.BouncyCastle.Crypto.Parameters private readonly int r; private readonly byte[] fixedInputData; - private KDFFeedbackParameters(byte[] ki, byte[] iv, byte[] fixedInputData, int r, bool useCounter) + private KdfFeedbackParameters(byte[] ki, byte[] iv, byte[] fixedInputData, int r, bool useCounter) { if (ki == null) { @@ -46,7 +47,7 @@ namespace Org.BouncyCastle.Crypto.Parameters this.useCounter = useCounter; } - public static KDFFeedbackParameters CreateWithCounter( + public static KdfFeedbackParameters CreateWithCounter( byte[] ki, byte[] iv, byte[] fixedInputData, int r) { if (r != 8 && r != 16 && r != 24 && r != 32) @@ -54,13 +55,13 @@ namespace Org.BouncyCastle.Crypto.Parameters throw new ArgumentException("Length of counter should be 8, 16, 24 or 32"); } - return new KDFFeedbackParameters(ki, iv, fixedInputData, r, true); + return new KdfFeedbackParameters(ki, iv, fixedInputData, r, true); } - public static KDFFeedbackParameters CreateWithoutCounter( + public static KdfFeedbackParameters CreateWithoutCounter( byte[] ki, byte[] iv, byte[] fixedInputData) { - return new KDFFeedbackParameters(ki, iv, fixedInputData, UNUSED_R, false); + return new KdfFeedbackParameters(ki, iv, fixedInputData, UNUSED_R, false); } public byte[] Ki |