From f93d52bbd0053574fb35d72b85c4b299dc1f3ee5 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Sat, 12 Nov 2016 13:48:30 +0100 Subject: Fixes decryption share calculation, adds lots of debugging statements. --- node/node.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 3 deletions(-) (limited to 'node/node.cpp') diff --git a/node/node.cpp b/node/node.cpp index b5c8506..5bce063 100644 --- a/node/node.cpp +++ b/node/node.cpp @@ -11,19 +11,40 @@ using namespace boost::asio::ip; Node::Node(ListenSettings const& listen_settings, NodeNetworkSettings network_settings) : io_service() +, timer(io_service) , ssl_ctx(std::make_shared(boost::asio::ssl::context::sslv23)) , server(io_service, listen_settings, ssl_ctx, [this](std::unique_ptr>&& socket, std::shared_ptr ctx){accept_handler(std::move(socket), ctx);}) , clients() , data() +, messages() , network_settings(network_settings) , prev_node(SSLReceiver(std::unique_ptr>(new boost::asio::ssl::stream(io_service, *ssl_ctx)))) , next_node(SSLSender(std::unique_ptr>(new boost::asio::ssl::stream(io_service, *ssl_ctx)))) , cmix_ctx(initialize_cmix_context(get_implementation())) -, precomputation_data() , shutting_down(false) { initialize_keypair(&cmix_ctx); + std::string x = to_string(cmix_ctx.keypair.sec, cmix_ctx); + std::string y = to_string(cmix_ctx.keypair.pub, cmix_ctx); + { + std::stringstream ss; + ss << "sec: "; + for(auto&& c : x) { + ss << "\\" << std::setw(3) << std::setfill('0') << std::oct << (unsigned int) c; + } + BOOST_LOG_TRIVIAL(trace) << ss.str(); + } + + { + std::stringstream ss; + ss << "pub: "; + for(auto&& c : y) { + ss << "\\" << std::setw(3) << std::setfill('0') << std::oct << (unsigned int) c; + } + BOOST_LOG_TRIVIAL(trace) << ss.str(); + } + GOOGLE_PROTOBUF_VERIFY_VERSION; if(network_settings.is_first) { @@ -131,14 +152,15 @@ void Node::handle_message(Purgatory::iterator handle, cmix_proto::CMixMessage me } void Node::start_precomputation() { + BOOST_LOG_TRIVIAL(trace) << "Starting precomputation for " << clients.size() << " clients."; + index_map.clear(); if(start_mix(&cmix_ctx, clients.size()) != no_error) { exit(-1); } - int i = 0; + unsigned int i = 0; for(auto&& pair : clients) { index_map[pair.first] = i++; - generate_random_message(&cmix_ctx, i); } if(initialize_mix_randomness(&cmix_ctx) != no_error) { @@ -148,15 +170,54 @@ void Node::start_precomputation() { cmix_proto::PrePre prepre; for(size_t i = 0; i < cmix_ctx.nr_participants; ++i) { + prepre.add_m_er(); + prepre.add_r_er(); + size_t len = get_group_element_array_size(&cmix_ctx); prepre.mutable_r_er(i)->resize(len); prepre.mutable_m_er(i)->resize(len); + { + std::stringstream ss; + ss << "r: "; + std::string r = to_string(cmix_ctx.r[i], cmix_ctx); + for(auto&& c : r) { + ss << "\\" << std::setw(3) << std::setfill('0') << std::oct << (unsigned int) c; + } + BOOST_LOG_TRIVIAL(trace) << ss.str(); + } + if(encrypt_r(&cmix_ctx, &(*prepre.mutable_r_er(i))[0], &(*prepre.mutable_m_er(i))[0], i) != no_error) { exit(-1); } } + BOOST_LOG_TRIVIAL(trace) << "Sending prepre message: " << prepre.ShortDebugString(); next_node.async_send(prepre); } + +void Node::start_realtime_phase() { + + cmix_proto::RealPre realpre; + + size_t len = get_group_element_array_size(&cmix_ctx); + for(auto&& pair : index_map) { + realpre.add_h(); + realpre.add_m(); + realpre.mutable_m(pair.second)->resize(len); + std::decay::type::first_type const& handle = pair.first; + std::decay::type::second_type const& index = pair.second; + + auto& queue = messages[pair.first]; + if(queue.empty()) { + std::vector v(len); + generate_random_message(&cmix_ctx, v.data()); + swap_k_for_r(&cmix_ctx, &(*realpre.mutable_m(index))[0], v.data(), data[handle].shared_value, index); + } else { + swap_k_for_r(&cmix_ctx, &(*realpre.mutable_m(index))[0], queue.front().data(), data[handle].shared_value, index); + } + *realpre.mutable_h(index) = handle; + } + next_node.async_send(realpre); +} -- cgit v1.2.3-70-g09d2