public void TestAllHonest_7_2() { const int n = 7, f = 2; SetUpAllHonest(n, f); for (var i = 0; i < n; ++i) { var share = new RawShare(new byte[32], i); _broadcasters[i].InternalRequest(new ProtocolRequest <HoneyBadgerId, IRawShare>( _resultInterceptors[i].Id, (_broadcasts[i].Id as HoneyBadgerId) !, share )); } for (var i = 0; i < n; ++i) { _broadcasts[i].WaitFinish(); } for (var i = 0; i < n; ++i) { Assert.IsTrue(_broadcasts[i].Terminated, $"protocol {i} did not terminated"); Assert.AreEqual(_resultInterceptors[i].ResultSet, 1, $"protocol {i} has emitted result not once but {_resultInterceptors[i].ResultSet}"); Assert.AreEqual(n, _resultInterceptors[i].Result.Count); } }
public void ThresholdKeyGen() { var keygen = new TrustedKeyGen(N, F); var pubKey = keygen.GetPubKey(); // var verificationKey = keygen.GetVerificationKey(); var privKeyTmp = new List <PrivateKey>(); for (var i = 0; i < N; ++i) { privKeyTmp.Add(keygen.GetPrivKey(i)); } var privKey = privKeyTmp.ToArray(); var len = _rnd.Next() % 100 + 1; var data = new byte[len]; _rnd.NextBytes(data); var share = new RawShare(data, Id); var enc = pubKey.Encrypt(share); var chosen = new HashSet <int>(); while (chosen.Count < F) { chosen.Add(_rnd.Next(0, N - 1)); } var parts = new List <PartiallyDecryptedShare>(); foreach (var dec in chosen.Select(i => privKey[i].Decrypt(enc))) { // Assert.True(verificationKey.Verify(enc, dec)); parts.Add(dec); } var share2 = pubKey.FullDecrypt(enc, parts); Assert.AreEqual(share.Id, share2.Id); for (var i = 0; i < len; ++i) { Assert.AreEqual(share.Data[i], share2.Data[i]); } }
public void RandomTest() { var n = _rnd.Next(1, 10); var f = _rnd.Next((n - 1) / 3 + 1); var mode = _rnd.SelectRandom(Enum.GetValues(typeof(DeliveryServiceMode)).Cast <DeliveryServiceMode>()); var s = new HashSet <int>(); while (s.Count < f) { s.Add(_rnd.Next(n)); } SetUpSomeSilent(n, f, s); _deliveryService.Mode = mode; for (var i = 0; i < n; ++i) { var share = new RawShare(new byte[32], i); _broadcasters[i].InternalRequest(new ProtocolRequest <HoneyBadgerId, IRawShare>( _resultInterceptors[i].Id, (_broadcasts[i].Id as HoneyBadgerId) !, share )); } for (var i = 0; i < n; ++i) { if (s.Contains(i)) { continue; } _broadcasts[i].WaitFinish(); } for (var i = 0; i < n; ++i) { if (s.Contains(i)) { continue; } Assert.IsTrue(_broadcasts[i].Terminated, $"protocol {i} did not terminated"); Assert.AreEqual(_resultInterceptors[i].ResultSet, 1, $"protocol {i} has emitted result not once but {_resultInterceptors[i].ResultSet}"); Assert.AreEqual(n - f, _resultInterceptors[i].Result.Count); } }
public void TestSomeSilent_7_2() { const int n = 7, f = 2; var s = new HashSet <int>(); while (s.Count < f) { s.Add(_rnd.Next(n)); } SetUpSomeSilent(n, f, s); for (var i = 0; i < n; ++i) { var share = new RawShare(new byte[32], i); _broadcasters[i].InternalRequest(new ProtocolRequest <HoneyBadgerId, IRawShare>( _resultInterceptors[i].Id, (_broadcasts[i].Id as HoneyBadgerId) !, share )); } for (var i = 0; i < n; ++i) { if (s.Contains(i)) { continue; } _broadcasts[i].WaitFinish(); } for (var i = 0; i < n; ++i) { if (s.Contains(i)) { continue; } Assert.IsTrue(_broadcasts[i].Terminated, $"protocol {i} did not terminated"); Assert.AreEqual(_resultInterceptors[i].ResultSet, 1, $"protocol {i} has emitted result not once but {_resultInterceptors[i].ResultSet}"); Assert.AreEqual(n - f, _resultInterceptors[i].Result.Count); } }