diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-11-12 13:48:30 +0100 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-11-12 13:48:30 +0100 |
| commit | f93d52bbd0053574fb35d72b85c4b299dc1f3ee5 (patch) | |
| tree | 4a2120a162ce9161d70074fd9ffa3ed21d80a40e /node/node.cpp | |
| parent | 8ff9babe2da4a2efc8529e800a6093fbd0327286 (diff) | |
| download | cmix-f93d52bbd0053574fb35d72b85c4b299dc1f3ee5.tar.gz cmix-f93d52bbd0053574fb35d72b85c4b299dc1f3ee5.tar.bz2 cmix-f93d52bbd0053574fb35d72b85c4b299dc1f3ee5.zip | |
Fixes decryption share calculation, adds lots of debugging statements.
Diffstat (limited to 'node/node.cpp')
| -rw-r--r-- | node/node.cpp | 67 |
1 files changed, 64 insertions, 3 deletions
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>(boost::asio::ssl::context::sslv23)) , server(io_service, listen_settings, ssl_ctx, [this](std::unique_ptr<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>>&& socket, std::shared_ptr<boost::asio::ssl::context> ctx){accept_handler(std::move(socket), ctx);}) , clients() , data() +, messages() , network_settings(network_settings) , prev_node(SSLReceiver(std::unique_ptr<boost::asio::ssl::stream<tcp::socket>>(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket>(io_service, *ssl_ctx)))) , next_node(SSLSender(std::unique_ptr<boost::asio::ssl::stream<tcp::socket>>(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket>(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<decltype(pair)>::type::first_type const& handle = pair.first; + std::decay<decltype(pair)>::type::second_type const& index = pair.second; + + auto& queue = messages[pair.first]; + if(queue.empty()) { + std::vector<char> 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); +} |
