public void MentalPokerTest() { // create and check VTMF instance System.Diagnostics.Debug.WriteLine("BarnettSmartVTMF_dlog()"); BarnettSmartVTMF_dlog vtmf = new BarnettSmartVTMF_dlog(); System.Diagnostics.Debug.WriteLine("vtmf.CheckGroup()"); Assert.IsTrue(vtmf.CheckGroup()); // TODO random fail?? // publish VTMF instance as string stream System.Diagnostics.Debug.WriteLine("vtmf.PublishGroup(vtmf_str)"); //vtmf.PublishGroup(d_channal); int player_count = PokerPlayer.PLAYER_COUNT; // open channel IChannel [][] channals = new IChannel[player_count][]; for (int index_player = 0; index_player < PokerPlayer.PLAYER_COUNT; index_player++) { channals[index_player] = new IChannel[player_count]; } for (int index_send = 0; index_send < PokerPlayer.PLAYER_COUNT; index_send++) { for (int index_recieve = index_send + 1; index_recieve < PokerPlayer.PLAYER_COUNT; index_recieve++) { ChannelTwoWayBigInteger channel = new ChannelTwoWayBigInteger(); channals[index_send][index_recieve] = channel.Channel0; channals[index_recieve][index_send] = channel.Channel1; } } System.Diagnostics.Debug.WriteLine("starting " + PokerPlayer.PLAYER_COUNT + " players"); // start poker childs Thread [] player_treads = new Thread [PokerPlayer.PLAYER_COUNT]; for (int i = 0; i < PokerPlayer.PLAYER_COUNT; i++) { PokerPlayer poker_player = new PokerPlayer(i, channals[i], new BarnettSmartVTMF_dlog(vtmf)); player_treads[i] = new Thread(poker_player.Run); player_treads[i].Start(); } for (int i = 0; i < PokerPlayer.PLAYER_COUNT; i++) { player_treads[i].Join(); } }
public void Run() { // create TMCG and VTMF instances BarnettSmartVTMF_dlog vtmf = d_vmtf; if (!vtmf.CheckGroup()) { throw new Exception("P_" + d_player_id + ": Group G was not correctly generated!"); } System.Diagnostics.Debug.WriteLine("P_" + d_player_id + " done generating keys"); // create and exchange VTMF keys vtmf.KeyGenerationProtocol_GenerateKey(); for (int i = 0; i < PLAYER_COUNT; i++) { if (i != d_player_id) { vtmf.KeyGenerationProtocol_PublishKey(d_player_channals[i]); } } for (int i = 0; i < PLAYER_COUNT; i++) { if (i != d_player_id) { if (!vtmf.KeyGenerationProtocol_UpdateKey(d_player_channals[i])) { throw new Exception("P_" + d_player_id + ": Public key of P_" + i + " was not correctly generated!"); } } } //vtmf.KeyGenerationProtocol_Finalize(); System.Diagnostics.Debug.WriteLine("P_" + d_player_id + " done create and exchange VTMF keys"); // VSSHE GrothVSSHE vsshe; if (d_player_id == 0) { // create and publish VSSHE instance as leader vsshe = new GrothVSSHE(DECKSIZE, vtmf.p, vtmf.q, vtmf.k, vtmf.g, vtmf.h); System.Diagnostics.Debug.WriteLine("P_" + d_player_id + " done GrothVSSHE"); if (!vsshe.CheckGroup()) { throw new Exception("P_" + d_player_id + ": VSSHE instance was not correctly generated!"); } System.Diagnostics.Debug.WriteLine("P_" + d_player_id + " done CheckGroup"); for (int i = 1; i < PLAYER_COUNT; i++) { vsshe.PublishGroup(d_player_channals[i]); // TODO not also publish to self! } System.Diagnostics.Debug.WriteLine("P_" + d_player_id + " done VSSHE"); } else { // receive and create VSSHE instance as non-leader vsshe = new GrothVSSHE(DECKSIZE, d_player_channals[0]); System.Diagnostics.Debug.WriteLine("P_" + d_player_id + " done GrothVSSHE"); if (!vsshe.CheckGroup()) { throw new Exception("P_" + d_player_id + ": VSSHE instance was not correctly generated!"); } if (vtmf.h != vsshe.com.h) { throw new Exception("P_" + d_player_id + ": VSSHE: Common public key does not match! " + vtmf.h.BitLength() + " " + vsshe.com.h.BitLength()); } if (vtmf.q != vsshe.com.q) { throw new Exception("P_" + d_player_id + ": VSSHE: VSSHE: Subgroup order does not match!"); } if (vtmf.p != vsshe.p || vtmf.q != vsshe.q || vtmf.g != vsshe.g || vtmf.h != vsshe.h) { throw new Exception("P_" + d_player_id + ": VSSHE: Encryption scheme does not match!"); } System.Diagnostics.Debug.WriteLine("P_" + d_player_id + " done VSSHE"); } }