public void ShouldSha224NoReseedNoPersoNoAddInput() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = false, EntropyInputLen = 192, NonceLen = 96, PersoStringLen = 0, AdditionalInputLen = 0, ReturnedBitsLen = 896, DerFuncEnabled = false, Mechanism = DrbgMechanism.HMAC, Mode = DrbgMode.SHA224, ReseedImplemented = false }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("a76e77a969ab92645181f0157802523746c34bf321867641")); // Entropy Input entropyProvider.AddEntropy(new BitString("051ed6ba39368033adc93d4e")); // Nonce subject.Instantiate(0, new BitString(0)); // Perso string entropyProvider.AddEntropy(new BitString(0)); // Entropy Input Reseed entropyProvider.AddEntropy(new BitString(0)); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var expectation = new BitString("8925987db5566e60520f09bdddab488292bed92cd385e5b6fc223e1919640b4e34e34575033e56c0a8f608be21d3d221c67d39abec98d81312f3a2653d55ffbf44c337c82bed314c211be23ec394399ba351c4687dce649e7c2a1ba7b0b5dab125671b1bcf9008da65cad612d95ddc92"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldSha512t256() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = false, EntropyInputLen = 256, NonceLen = 128, PersoStringLen = 0, AdditionalInputLen = 256, ReturnedBitsLen = 1024, DerFuncEnabled = false, Mechanism = DrbgMechanism.HMAC, Mode = DrbgMode.SHA512t256, ReseedImplemented = true }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("46fc5de4ea7d31c60cc62b49d283b7bc71778a028273c0bd4e59f590e168ceb7")); // Entropy Input entropyProvider.AddEntropy(new BitString("d91d148f4a52bc99c269d46729d594bf")); // Nonce subject.Instantiate(256, new BitString(0)); // Perso string entropyProvider.AddEntropy(new BitString("76b955c9aa4c290418159f4d805b427de35e42aa1cf10f59e743c56c92280a55")); // Entropy Input Reseed subject.Reseed(new BitString("6722b8f0ae83cc1f52e3ded6f588b638881d5e097d8bee2675ae30efb417936a")); subject.Generate(parameters.ReturnedBitsLen, new BitString("d7eae425d0a484693557a53ef97dedf43f255c2a9e38a8334ccef35829e04f17")); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString("eb3d3e3fff84d72a84bf94fa49b643d7d1ebe768b4d508360cdf962eb3cd48d7")); // Additional Input var expectation = new BitString("9fe074750995b0c2638eb48ab66957b4033fa34202a7cc9a5354ea2db4aba89ca10dc5eda1f03f9f5a9fc4cd9b9191d96d056ab74f5a4fda15442f1839dff8f240b06e9276f03fb1d7c3b5a8a571c37dbf89e9ed8afe09e542add83332d730c4f74124b7f59fea6a6a8e816ac5e0d66d7944cf9cf18936163bb8a81a34f0d4a4"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldSha1NoReseedNoPrNoPersoNoAddInput() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = false, EntropyInputLen = 128, NonceLen = 64, PersoStringLen = 0, AdditionalInputLen = 0, ReturnedBitsLen = 640, DerFuncEnabled = false, Mechanism = DrbgMechanism.HMAC, Mode = DrbgMode.SHA1, ReseedImplemented = false }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("e91b63309e93d1d08e30e8d556906875")); // Entropy Input entropyProvider.AddEntropy(new BitString("f59747c468b0d0da")); // Nonce subject.Instantiate(0, new BitString(0)); // Perso string entropyProvider.AddEntropy(new BitString(0)); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var expectation = new BitString("b7928f9503a417110788f9d0c2585f8aee6fb73b220a626b3ab9825b7a9facc79723d7e1ba9255e40e65c249b6082a7bc5e3f129d3d8f69b04ed1183419d6c4f2a13b304d2c5743f41c8b0ee73225347"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldSha512t224() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = true, EntropyInputLen = 192, NonceLen = 96, PersoStringLen = 192, AdditionalInputLen = 0, ReturnedBitsLen = 896, DerFuncEnabled = false, Mechanism = DrbgMechanism.HMAC, Mode = DrbgMode.SHA512t224, ReseedImplemented = true }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("1e48129b9eb4bd5fa6fd7775f0813d3928c7d21de4d06c34")); // Entropy Input entropyProvider.AddEntropy(new BitString("a18e9fda78f5134ba2a264d4")); // Nonce subject.Instantiate(0, new BitString("558ca5ae37effdb8cee4e5204b17bfea686c8773d97a78e3")); // Perso string entropyProvider.AddEntropy(new BitString("3ca0289962abb8a5f1d138d69ebdcbf68d73185d98f77745")); // Entropy Input Reseed entropyProvider.AddEntropy(new BitString("9f213f9b53769b1ebdba3841c6c05a83919ad950639e0b7e")); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var expectation = new BitString("e33dcee09e13999b9ac710a8880a24eb4c745fbb1fab37b541039dbbd121e4c8049e3c4e31535fd3b9b1d97a7cfd586bbf2ecf973f03b08e379ddc1d996b71e026d62b1b0ae4ea0fe7e36cc507711df502ac7e5b3124a4c13afda69b06d7e39660b5bd13a17aa6723c4a953cca9f0e6c"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldSha256NoReseedNoPerso() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = true, EntropyInputLen = 256, NonceLen = 128, PersoStringLen = 0, AdditionalInputLen = 256, ReturnedBitsLen = 1024, DerFuncEnabled = false, Mechanism = DrbgMechanism.HMAC, Mode = DrbgMode.SHA256, ReseedImplemented = false }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("2cad88b2b6a06e703de46185ccb2ddcf5e0ee030995ebdf95cc4fbc38441f17f")); // Entropy Input entropyProvider.AddEntropy(new BitString("32310770e04172c0cf91f6590cce44a4")); // Nonce subject.Instantiate(0, new BitString(0)); // Perso string entropyProvider.AddEntropy(new BitString("448bfbc5ce9e3b9da3e9642daecd994dfe373e75253e8eb585141224eca7ad7b")); // Entropy Input Reseed entropyProvider.AddEntropy(new BitString("afb57f69799c0b892b3015990e133698d543aa87829ace868e4a5e9525d62357")); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString("ef6da5e6530e0d621749ab192e06327e995c3ac0c3963ab8c8cd2df2839ab5df")); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString("44278b31ed853f0a510bd14650ac4b4971d8b426799a43511d016be68dedbb8d")); // Additional Input var expectation = new BitString("4c7dfbe509dc5a3ac26998723c6a44cad20b197fc86117c778d1568ab828923862885e97198f77a1cb45113f5d78726a0f120aec94afc45f57c8dcc1cb092b343480012858ef5bc559f57023442209326ec4a54d91ca3a77dfdf9e75f117cef50e6fd2dc9af6ddce8e6515b4a97357a97b6cd274f68a042fa41bbd7b7261b034"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldSha512t224() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = true, EntropyInputLen = 192, NonceLen = 96, PersoStringLen = 192, AdditionalInputLen = 0, ReturnedBitsLen = 896, DerFuncEnabled = false, Mechanism = DrbgMechanism.Hash, Mode = DrbgMode.SHA512t224, ReseedImplemented = true }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("23b649d085ac363211067b01581925722a56be00b38c8a18")); // Entropy Input entropyProvider.AddEntropy(new BitString("b13d4b96fc9d6a544e8fc8e1")); // Nonce subject.Instantiate(0, new BitString("a5c95fa1bc898e89950b7b34f03a63d194108a98de882d58")); // Perso string entropyProvider.AddEntropy(new BitString("0a0be76e8665d231d7cb0ad0248cba3985dcaa7f2d20b2e8")); // Entropy Input Reseed entropyProvider.AddEntropy(new BitString("7321c5a56d89551cf99dcbde7260820dd301300e09aab920")); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var expectation = new BitString("19364b3d0a60572e6b3ac5af144c0e00d74ba64fecb2512460e11ac33f1f4f024352c787eca4b52b42291b8bcdd68a5c06472b374b3c7c6f7838a83595504ad8a1c4ea4d1993fec2566445774aa5f469ee11ae80a6decd13507d2b0a82253b192547054451fe07810f8edcdb1d269b6c"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldSha384NoReseedNoAddInput() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = true, EntropyInputLen = 256, NonceLen = 128, PersoStringLen = 256, AdditionalInputLen = 0, ReturnedBitsLen = 1536, DerFuncEnabled = false, Mechanism = DrbgMechanism.HMAC, Mode = DrbgMode.SHA384, ReseedImplemented = false }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("37dc21c72dc7c82d5e13c51ecaf5a8ae06402500d92caf96c0555a95069f4f01")); // Entropy Input entropyProvider.AddEntropy(new BitString("44a961ead5d6d9bc317afc8206202bdd")); // Nonce subject.Instantiate(0, new BitString("41e3b89347bd035bde510ab8ff83d5fdcc9d5f2de648bdb468a714f2c1083c52")); // Perso string entropyProvider.AddEntropy(new BitString("d57fc02a2a500df1fb5c4d9d8837b52a5220fdf068fe2b8b4bcc63fbc9bfc94c")); // Entropy Input Reseed entropyProvider.AddEntropy(new BitString("8e21d987e8b6cb0f4cd37b144c668f18b7a36ed4e9758ee7b96029aa0ab2196a")); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var expectation = new BitString("a929ee23c5832e5ab93ccaa40bf775593d7d04a1a8411dfa07b4c8a2da2dc91b1bcb9c27a0ba5a7152ce5ded5f76cf6b83c04c0f8a4f6b43383ae3e7d497280c0f944be91b0bca6a56df2d00641bfc1ec549b538898e559407b076164278c0eb7afb6d6f4495a50d4da178c04b259d21bb745692d3bd186edf5bb3da6f66b4418fc3d9b085b0a6c1a5e54696272c305c4b8887595b391dd6ed8da03dc9fdb2728d8c40a2defd8af05ef1c443a72323f2e0b0d268109fb7e7ee70192fa06bc6c2"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldAes256NoDfNoPrNoNonceAddInput() { TestableEntropyProvider entropyProvider = new TestableEntropyProvider(); DrbgFactory factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); DrbgParameters parameters = new DrbgParameters { PredResistanceEnabled = false, EntropyInputLen = 384, NonceLen = 0, PersoStringLen = 0, AdditionalInputLen = 384, ReturnedBitsLen = 512, DerFuncEnabled = false, Mechanism = DrbgMechanism.Counter, Mode = DrbgMode.AES256, ReseedImplemented = true }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("5f59060ab389bce8641d52253d2ab6d88d9b114a64b00de522b4f07be26a56c8f0cbdf33b81a888d389f343d19909f34")); // Entropy Input entropyProvider.AddEntropy(new BitString(0)); // Nonce subject.Instantiate(256, new BitString(0)); entropyProvider.AddEntropy(new BitString("f9ec27e777b9385cd77573668140b21a5e5d1b0ea66f950ee054c1c483b9062d93ea406a7c3a95286029803161fe0865")); // Entropy Input Reseed subject.Reseed(new BitString("005debda17ad3a6b8600314fd19be0871da2f4f3f58946e6745554f79d0915bb5ea0f5fe2eb794d44742c1e14461cd87")); subject.Generate(parameters.ReturnedBitsLen, new BitString("1ceb9c2772b1bcb91880f49862377ef3c9d7590a67ab78426a9549ebbe93f6656fb4f5ee2ddc45fd5502cf5160aea69a")); var result = subject.Generate(parameters.ReturnedBitsLen, new BitString("1047c50840b200de336babebee430d5a258ad98017d504b8ec9916e1284fa4b82ba4317bd9a6c090455944845dc700c4")); var expectation = new BitString("4ba0a32db68d2feeef2ea9ce0982f9e7072112eafe05553bc9ef381c16abf4dd2fc28e5a1c62532da760e87c28e24c641281727e5c56912884dda39445995323"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldAes128NoReseedNoAddInput() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = true, EntropyInputLen = 128, NonceLen = 64, PersoStringLen = 0, AdditionalInputLen = 0, ReturnedBitsLen = 512, DerFuncEnabled = true, Mechanism = DrbgMechanism.Counter, Mode = DrbgMode.AES128, ReseedImplemented = false }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("9605714ae47145fc9612d2b031122ce6")); // Entropy Input entropyProvider.AddEntropy(new BitString("65ddb5cda412f14d")); // Nonce subject.Instantiate(128, new BitString(0)); entropyProvider.AddEntropy(new BitString("9c0de210427a30f05f7ed1bf14d0d377")); entropyProvider.AddEntropy(new BitString("bcbdfc86694bad03cb75d5ac3cb8dd1e")); subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); var result = subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); var expectation = new BitString("b7ab81ed6e9562f81850c6e94e1cbc1339c7dfe09bbc31a7d7bf876f11a2a56f8640f30be79a0dc2c055a750c9b4b3dff61eb4b240c2e8793873b8813002db2a"); Assert.AreEqual(expectation.ToHex(), result.Bits.ToHex()); }
public void ShouldAes128NoReseedNoDfNoPrNoNonceNoAddInput() { TestableEntropyProvider entropyProvider = new TestableEntropyProvider(); DrbgFactory factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); DrbgParameters parameters = new DrbgParameters { PredResistanceEnabled = false, EntropyInputLen = 256, NonceLen = 0, PersoStringLen = 0, AdditionalInputLen = 0, ReturnedBitsLen = 512, DerFuncEnabled = false, Mechanism = DrbgMechanism.Counter, Mode = DrbgMode.AES128, ReseedImplemented = false }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("ed435694a0c1bc5a11ceb7c315984d8f62fda0b1327840c0775569a86257f566")); // Entropy Input entropyProvider.AddEntropy(new BitString(0)); // Nonce subject.Instantiate(128, new BitString(0)); entropyProvider.AddEntropy(new BitString(0)); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); var result = subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); var expectation = new BitString("35a540967abf5eb8dd0ce312771c3799fa7e39d2e2085e6e99668c2ae127eb9a4e02a4a55662127458d9a41e945ab924ec4cb61352041cc21676de7b0ed714aa"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldSha512t256() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = false, EntropyInputLen = 256, NonceLen = 128, PersoStringLen = 0, AdditionalInputLen = 256, ReturnedBitsLen = 1024, DerFuncEnabled = false, Mechanism = DrbgMechanism.Hash, Mode = DrbgMode.SHA512t256, ReseedImplemented = true }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("8391576a34d3986dcccd61e403cac3b3f219992128004870eec9e7925e51f92c")); // Entropy Input entropyProvider.AddEntropy(new BitString("e4e4d529853e19e2bc1165148b0070bc")); // Nonce subject.Instantiate(0, new BitString(0)); // Perso string entropyProvider.AddEntropy(new BitString("69f81788fdf6fee5b62dba259fd66135409c133d6c2e7a7e7a05eefea39b8999")); // Entropy Input Reseed subject.Reseed(new BitString("c3d25860b81a452314dc9a9dc24ad1e34b8182944ee17172da0be649c8df0f85")); subject.Generate(parameters.ReturnedBitsLen, new BitString("33a873e408d4ee7bf27bc576a0a0f36b1bcf9306a7645945ac6c66a74ce07165")); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString("980837cb5a73249882f693813e2afdd51823a94462b3c0f747e4994af76ce719")); // Additional Input var expectation = new BitString("ec1c599246b585813a16e3cbb2e461cc62e6b38d96862b98e4bb502d60466d696576571dc0998110fd022ff0ed85f79cc7f6366e8f1c15b14a5cc1e79d68e2ba299d5421e6231bb47d22c998b79424de4113ab0b46e38f8c1057fd4a58201f4c40e491a57201e1a9f581cbca3f03f0e0f729cdaeadfbc86a1a0d708305a18e1a"); Assert.AreEqual(expectation, result.Bits); }
private IDrbg GetHashImplementation(DrbgParameters drbgParameters, IEntropyProvider iEntropyProvider) { var hashFunction = GetHashFunction(drbgParameters.Mode); var sha = _shaFactory.GetShaInstance(hashFunction); return(new DrbgHash(iEntropyProvider, sha, drbgParameters)); }
public void ShouldSha1NoReseedNoPrNoPersoNoAddInput() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = false, EntropyInputLen = 128, NonceLen = 64, PersoStringLen = 0, AdditionalInputLen = 0, ReturnedBitsLen = 640, DerFuncEnabled = false, Mechanism = DrbgMechanism.Hash, Mode = DrbgMode.SHA1, ReseedImplemented = false }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("33764f3e4edf7dda77cf42d8f05db5ec")); // Entropy Input entropyProvider.AddEntropy(new BitString("327e8be96dc19e25")); // Nonce subject.Instantiate(0, new BitString(0)); // Perso string entropyProvider.AddEntropy(new BitString(0)); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var expectation = new BitString("04db51649d660a0712b7218a6c5fbf9acb8af0272a6c732af0f2e66292e6c4517e102877c24277c3522984c5320c52b6e1d50a6733d29f31549067b4ffb64bb5d15b261342db73617b415e503652bc7d"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldSha512224NoReseedNoPrNoPersoNoAddInput() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = false, EntropyInputLen = 192, NonceLen = 96, PersoStringLen = 0, AdditionalInputLen = 0, ReturnedBitsLen = 896, DerFuncEnabled = false, Mechanism = DrbgMechanism.Hash, Mode = DrbgMode.SHA512t224, ReseedImplemented = false }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("65568162700f22ac868a504110fa466c70cfe0e7c32f1451")); // Entropy Input entropyProvider.AddEntropy(new BitString("69545e871b89c7b3f95885eb")); // Nonce subject.Instantiate(0, new BitString(0)); // Perso string entropyProvider.AddEntropy(new BitString(0)); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var expectation = new BitString("588572c2e4f0d6c7077d2b9eb593687ca92c86e5a9729505fcff52adfcf8a5eb850b910b985df10299bfe7434f3b6b7af92a3edaed732751cdb421c38431e2763afc6799eb61e176f9f20945870680ff8b62484378d3a7fd7d29202e5d371785d68fe399d5f600f34517fcccadf58937"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldSha512() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = true, EntropyInputLen = 256, NonceLen = 128, PersoStringLen = 256, AdditionalInputLen = 256, ReturnedBitsLen = 2048, DerFuncEnabled = false, Mechanism = DrbgMechanism.HMAC, Mode = DrbgMode.SHA512, ReseedImplemented = true }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("3aca6b55561521007c9ece085e9a6635e346fa804335d6ad42ebd6814c017fa8")); // Entropy Input entropyProvider.AddEntropy(new BitString("aa7fd3c3dd5d03d9b8efc7f70574581f")); // Nonce subject.Instantiate(0, new BitString("4bc9a485ec840d377ae4504aa1df41e444c4231687f3d7851c26c275bc687463")); // Perso string entropyProvider.AddEntropy(new BitString("4cc19fae5a456f8a53a656d23a0b665d6ddf7f43020a5febbb552714e447565d")); // Entropy Input Reseed entropyProvider.AddEntropy(new BitString("637386b3ab33f78fd9751c7b7e67e1e15f6e50ddc548a1eb5813f6d0d48381bf")); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString("b39c43539fdc24343085cbb65b8d36c54732476d781104c355c391a951313a30")); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString("b6850edd4622675ef5a507eab911e249d63fcf62f330cc8a16bb2ccc5858de5d")); // Additional Input var expectation = new BitString("546664042bef33064da28a5718f2c2e5f72d7725e3fbe87ad2ee90fbfe6c114ed36440fbbccf29698b4360bc4ad74650de13825838106adc53002bc389ee900691649b972f3187b84d05cecc8fd034497dd99c6c997d1914b4ef838d84abf23fae7f3ac9efdcdc04c003ac642c5126b00f9f24bf1431a4f19ef0b5f3d230aab3fdf091ba31b7ddcacdf2566f2cfab30f55b3123e733829b697b7c8b248420ab98ba6f11b017175256368e8d8361102c9e6d57386becbeabda092dd57aec65bc20ebee78eea7294571e168c454066d256b81bb8b7bb469207a18ebedbb4348fbe97a4d86d2bd095c41f6de59aa0800e131e98181886a2633cdcc550914d83b327"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldSha384NoReseedNoAddInput() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = true, EntropyInputLen = 256, NonceLen = 128, PersoStringLen = 256, AdditionalInputLen = 0, ReturnedBitsLen = 1536, DerFuncEnabled = false, Mechanism = DrbgMechanism.Hash, Mode = DrbgMode.SHA384, ReseedImplemented = false }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("b16be65ecff9f739fd6ca4523224a07e7bde4f648c89f18c1f62b491ee1bde46")); // Entropy Input entropyProvider.AddEntropy(new BitString("0c69654d2d6333dffc082391c1625a02")); // Nonce subject.Instantiate(0, new BitString("f76c1246129b5a15e9f31fda4d29eeb8902d12b3ff6b2adbc3a4e9c3f9891b41")); // Perso string entropyProvider.AddEntropy(new BitString("512e26f4a76517dd08f8c61949f936aec036bfba734ba924d6816be8c7629964")); // Entropy Input Reseed entropyProvider.AddEntropy(new BitString("433563dda3519d3a0ffb2f0fa489dd38d3c4da3838f479ccb50cc50fec8e7cc9")); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var expectation = new BitString("3a3b479e2e09d5e81a4126f6bb6177aa1799c84cdb828c9e75ea20728a68492ab09c989c514a82ce195cd5f94192b3f532f5719db84f84115427335a41daff1d9db65a8905c12682b24b915ab16fa6ebaa016af8c05062f6112f8703cd3827dcf50ff23e7b79fd11d29b976e9f46080f878c35a14e2f3e8d7f72f8364441ed2cad648be07c1efebb88240256e36c4b8648d229c428081cdbb14e183d5483c8b53cc67b520db48502895d57db17945c8911253e1d8da0b7c7b4d484f296fe353c"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldSha512() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = true, EntropyInputLen = 256, NonceLen = 128, PersoStringLen = 256, AdditionalInputLen = 256, ReturnedBitsLen = 2048, DerFuncEnabled = false, Mechanism = DrbgMechanism.Hash, Mode = DrbgMode.SHA512, ReseedImplemented = true }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("702c8d9beddaf7fb897a425d0fd17d1d5002264001ff28e53d05fd8bab63babb")); // Entropy Input entropyProvider.AddEntropy(new BitString("4b69c503a3ae83dcfad2b3613e0f17d8")); // Nonce subject.Instantiate(0, new BitString("63a3d7801dfb8696f5d4c82608832b719dab156c1b3b6047bfec5e6604fc2b8f")); // Perso string entropyProvider.AddEntropy(new BitString("98ee8bf9ee77af04c0da1e6b3d06d2b20cb97ad4e46d9257875f82aca809a21a")); // Entropy Input Reseed entropyProvider.AddEntropy(new BitString("f438d35a35b7ec6ea13897e429280615220daa7f91f2dbcbe83263c5a26bfe85")); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString("a2ed6e9e3c2489e83226318c58e3795d449bad79f0bf0657502de9c97ce79983")); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString("f45bb93dcafd5d8a12398e5b2c0b376f023718db6989444cafbc298b97c838e7")); // Additional Input var expectation = new BitString("c871ba97832f3f1febe0e844228e387323001652a53d6e8d540818413aea238c006d646eb174c5b974dc8e80087e28a8beb00f103cb999dc76728643bc2f9af043a780492c1055965e2d1183073f60ee8e5b07b8018554bb38c74acd4e07d1b6d3af93ebe06876aa11ec40b407793f4637ef57787b01368e00b54f763a437d419e09171eb551235128d0ec38ef3546fb0edc8328db76fcd296afe9ad87b765aead3b7fa873bd6bd2be4b513504d72db955591d566cc050f73c7bdfb9ffd57e4858f7ca25b2e72ea513a55988a45c294f713d13658b9b414f8cf3f3ae92cdc835a31cf1766e092ee93d05e7fd001a2765c4be43fdcb535d20588dcfbfe3fa5ea8"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldSha256NoReseedNoPerso() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = true, EntropyInputLen = 256, NonceLen = 128, PersoStringLen = 0, AdditionalInputLen = 256, ReturnedBitsLen = 1024, DerFuncEnabled = false, Mechanism = DrbgMechanism.Hash, Mode = DrbgMode.SHA256, ReseedImplemented = false }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("587db71d1772d78a43ac5db76159cc1d938a279211cafa75c7268f603f2d8210")); // Entropy Input entropyProvider.AddEntropy(new BitString("6cd151fc87ad8a96e4cc2dfa5cbaa923")); // Nonce subject.Instantiate(0, new BitString(0)); // Perso string entropyProvider.AddEntropy(new BitString("f9b75d5aff19b49470fbfc72463ffdca845b62c26a7da35c2fc0be307ab0e639")); // Entropy Input Reseed entropyProvider.AddEntropy(new BitString("73add18476397e22be249cea23d4b43b761bdbed01e8218e53d214646b9bf35d")); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString("7e82047a4e258cc9b3b84425d7cbc803d8be2f5624ff69b6aea40a610cbef477")); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString("c1f98d3aa3c3a1db35cebabe3bdbdaee5708555528fd2f25d4b57b410ba0e06b")); // Additional Input var expectation = new BitString("549486b786fd7653d128ae45c1301d8ef072310f53ccf7741cd054b59d2258ccd40fffdf47d04f75697d10010d9d634ad78926e408ef4edebb81570815b8dc4e1405af5213d98df443adab024a99d4d5fc88c12c1b0ab4c91c55d6e07e3a764d4649dd4f092b920add34f24c8b6e365761eb9b45fc21c94a1853b8f6930aac12"); Assert.AreEqual(expectation, result.Bits); }
private IDrbg GetHmacImplementation(DrbgParameters drbgParameters, IEntropyProvider iEntropyProvider) { var hashFunction = GetHashFunction(drbgParameters.Mode); var hmac = _hmacFactory.GetHmacInstance(hashFunction); return(new DrbgHmac(iEntropyProvider, hmac, drbgParameters)); }
public void ShouldAes256NoDfNoPrNonceNoAddInput() { TestableEntropyProvider entropyProvider = new TestableEntropyProvider(); DrbgFactory factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); DrbgParameters parameters = new DrbgParameters { PredResistanceEnabled = false, EntropyInputLen = 384, NonceLen = 0, PersoStringLen = 0, AdditionalInputLen = 0, ReturnedBitsLen = 512, DerFuncEnabled = false, Mechanism = DrbgMechanism.Counter, Mode = DrbgMode.AES256, ReseedImplemented = true }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("0510f0fea150f9f193fda43dc3f2b6115ff5aa5f9c6aab7529ca007acd5d755422bb0250df0e0289576f3c6d0501701c")); // Entropy Input entropyProvider.AddEntropy(new BitString(0)); // Nonce subject.Instantiate(256, new BitString(0)); entropyProvider.AddEntropy(new BitString("9b8f648ac1467122208193923bf1847dd24831f2940a1827783f64adb8c5e223475bf83ca10b4486b6a51419c00d0abe")); // Entropy Input Reseed subject.Reseed(new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); var result = subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); var expectation = new BitString("b720ddf5c154b4e77e008bf910a26f2978571e03cbdefd94b3abf76267d819d9314c003c899af6978f3514b68829366b61548fc8bade86d90f2a1538bbc9ff1e"); Assert.AreEqual(expectation, result.Bits); }
public void ShouldSha224NoReseedNoPersoNoAddInput() { var entropyProvider = new TestableEntropyProvider(); var factory = new DrbgFactory(new NativeShaFactory(), new HmacFactory(new NativeShaFactory())); var parameters = new DrbgParameters { PredResistanceEnabled = true, EntropyInputLen = 192, NonceLen = 96, PersoStringLen = 0, AdditionalInputLen = 0, ReturnedBitsLen = 896, DerFuncEnabled = false, Mechanism = DrbgMechanism.Hash, Mode = DrbgMode.SHA224, ReseedImplemented = false }; var subject = factory.GetDrbgInstance(parameters, entropyProvider); entropyProvider.AddEntropy(new BitString("cc569f9c71e2ef011991085377ba2ec4ce4f20372cc9325b")); // Entropy Input entropyProvider.AddEntropy(new BitString("6f02ba8a24b96a087d3b516e")); // Nonce subject.Instantiate(0, new BitString(0)); // Perso string entropyProvider.AddEntropy(new BitString("efaf7059a0a18ecac458e12864c9840a8680cad8b6402090")); // Entropy Input Reseed entropyProvider.AddEntropy(new BitString("ae626fa52cf75ba0f830c4936f060d4ccfe8ab5aeda42cbf")); // Entropy Input Reseed //subject.Reseed(false, new BitString(0)); subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var result = subject.Generate(parameters.ReturnedBitsLen, new BitString(0)); // Additional Input var expectation = new BitString("3c65020a0c8d176d6ef15b5a3db00ba43ea348842c0fc0f03bc757694dc6145c1826049ac5c39b4bbf14bf02332110cd99ae8d346c435308a92a28a600aba3f20f1b145b5a07ba3da7cebb69bc1a6c8bdf74607947bae4faa5c31724ec1e8029a8006e247d3d418bcc6aa8186df53e86"); Assert.AreEqual(expectation, result.Bits); }
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 ShouldReturnArgumentExceptionWhenInvalidModeEnum() { DrbgParameters p = new DrbgParameters(); int i = -1; var badMode = (DrbgMode)i; p.Mechanism = DrbgMechanism.Counter; p.Mode = badMode; 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 IDrbgConditioningComponent GetInstance(HashFunction hashFunction) { var drbgParameters = new DrbgParameters { Mechanism = DrbgMechanism.Hash, Mode = GetModeFromHashFunction(hashFunction) }; var drbg = _factory.GetDrbgInstance(drbgParameters, new EntropyProvider(new Random800_90())); return(new HashConditioningComponent((DrbgHash)drbg)); }
public IDrbgConditioningComponent GetInstance(int keyLength) { var drbgParameters = new DrbgParameters { Mechanism = DrbgMechanism.Counter, Mode = GetModeFromKeyLength(keyLength) }; var drbgAes = _factory.GetDrbgInstance(drbgParameters, new EntropyProvider(new Random800_90())); // Cast because we need AES specifically return(new BlockCipherConditioningComponent((DrbgCounterAes)drbgAes)); }
private IDrbg GetCounterImplementation(DrbgParameters drbgParameters, IEntropyProvider iEntropyProvider) { switch (drbgParameters.Mode) { case DrbgMode.AES128: case DrbgMode.AES192: case DrbgMode.AES256: return(new DrbgCounterAes(iEntropyProvider, new BlockCipherEngineFactory(), new ModeBlockCipherFactory(), drbgParameters)); case DrbgMode.TDES: return(new DrbgCounterTdes(iEntropyProvider, new BlockCipherEngineFactory(), new ModeBlockCipherFactory(), drbgParameters)); default: throw new ArgumentException("Invalid DRBG mode provided for current mechanism"); } }
public IDrbg GetDrbgInstance(DrbgParameters drbgParameters, IEntropyProvider iEntropyProvider) { switch (drbgParameters.Mechanism) { case DrbgMechanism.Counter: return(GetCounterImplementation(drbgParameters, iEntropyProvider)); case DrbgMechanism.Hash: return(GetHashImplementation(drbgParameters, iEntropyProvider)); case DrbgMechanism.HMAC: return(GetHmacImplementation(drbgParameters, iEntropyProvider)); default: throw new ArgumentException("Invalid DRBG Mechanism provided"); } }
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 FakeDrbgImplementation(IEntropyProvider entropyProvider, DrbgParameters drbgParameters) : base(entropyProvider, drbgParameters) { var att = DrbgAttributesHelper.GetDrbgAttributes(drbgParameters.Mechanism, drbgParameters.Mode, drbgParameters.DerFuncEnabled); var intMax = Int32.MaxValue - 1; Attributes = new DrbgAttributes ( att.Mechanism, att.Mode, att.MaxSecurityStrength, att.MinEntropyInputLength, intMax, intMax, intMax, intMax, intMax, att.MinNonceLength, intMax ); }