public DrbgHashAttributes(DrbgMechanism mechanism, DrbgMode mode, int maxSecurityStrength, int outputLength, int seedLength) { Mechanism = mechanism; Mode = mode; MaxSecurityStrength = maxSecurityStrength; OutputLength = outputLength; SeedLength = seedLength; }
public DrbgCounterAttributes(DrbgMechanism mechanism, DrbgMode mode, int maxSecurityStrength, int blockSize, int outputLength, int keyLength) { Mechanism = mechanism; Mode = mode; MaxSecurityStrength = maxSecurityStrength; BlockSize = blockSize; OutputLength = outputLength; KeyLength = keyLength; }
public void ShouldReturnArgumentExceptionWithNonMatchingEnums(DrbgMechanism mechanism, DrbgMode mode) { var p = new DrbgParameters { Mechanism = mechanism, Mode = mode }; Assert.Throws(typeof(ArgumentException), () => _subject.GetDrbgInstance(p, _mockEntropy.Object)); }
public void ShouldReturnCorrectType(DrbgMechanism drbgMechanism, DrbgMode drbgMode, Type expectedType) { DrbgParameters p = new DrbgParameters(); p.Mechanism = drbgMechanism; p.Mode = drbgMode; var result = _subject.GetDrbgInstance(p, _mockEntropy.Object); Assert.IsInstanceOf(expectedType, result); }
public DrbgAttributes(DrbgMechanism mechanism, DrbgMode mode, int maxSecurityStrength, long minEntropyInputLength, long maxEntropyInputLength, long maxPersoStringLength, long maxAdditStringLength, long maxNumberOfBitsPerRequest, long maxNumberOfRequestsBetweenReseeds, long minNonceLength, long maxNonceLength) { Mechanism = mechanism; Mode = mode; MaxSecurityStrength = maxSecurityStrength; MinEntropyInputLength = minEntropyInputLength; MaxEntropyInputLength = maxEntropyInputLength; MaxPersonalizationStringLength = maxPersoStringLength; MaxAdditionalInputStringLength = maxAdditStringLength; MaxNumberOfBitsPerRequest = maxNumberOfBitsPerRequest; MaxNumberOfRequestsBetweenReseeds = maxNumberOfRequestsBetweenReseeds; MinNonceLength = minNonceLength; MaxNonceLength = maxNonceLength; }
public void ShouldReturnCorrectBits( DrbgMechanism mechanism, DrbgMode mode, bool predResist, bool reseed, int returnedBitLen, BitString entropy, BitString nonce, BitString persoString, BitString addInput1, BitString entropyInput1, BitString addInput2, BitString entropyInput2, BitString expectedBits ) { var entropyProvider = new TestableEntropyProvider(); var parameters = new DrbgParameters { PredResistanceEnabled = predResist, EntropyInputLen = entropy.BitLength, NonceLen = nonce.BitLength, PersoStringLen = persoString.BitLength, AdditionalInputLen = addInput1.BitLength, ReturnedBitsLen = returnedBitLen, DerFuncEnabled = false, Mechanism = mechanism, Mode = mode, ReseedImplemented = reseed }; var subject = _subject.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(entropy); // Entropy Input entropyProvider.AddEntropy(nonce); // Nonce subject.Instantiate(0, persoString); // Perso string entropyProvider.AddEntropy(entropyInput1); // Entropy Input Reseed entropyProvider.AddEntropy(entropyInput2); // Entropy Input Reseed subject.Generate(parameters.ReturnedBitsLen, addInput1); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, addInput2); // Additional Input Assert.AreEqual(expectedBits, result.Bits); }
public static DrbgAttributes GetDrbgAttributes(DrbgMechanism mechanism, DrbgMode mode, bool derivationFunction = false) { DrbgAttributes result = null; if (derivationFunction) { if (!DrbgAttributesWithDerFunc.TryFirst(w => w.Mechanism == mechanism && w.Mode == mode, out result)) { throw new ArgumentException("Invalid mechanism and/or mode"); } } else { if (!DrbgAttributesWithoutDerFunc.TryFirst(w => w.Mechanism == mechanism && w.Mode == mode, out result)) { throw new ArgumentException("Invalid mechanism and/or mode"); } } return(result); }