From 25db9ff8a4cfb4b98aeeaae360e8c718b9c5e20c Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Thu, 27 Oct 2016 09:25:53 +0200 Subject: Adds libgcrypt implementation for elgamal in multiplicative group. Also adapts the API to both handle sodium and gcrypt libraries. --- node/node.cpp | 53 +++++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) (limited to 'node/node.cpp') diff --git a/node/node.cpp b/node/node.cpp index 2dfbba8..857d5af 100644 --- a/node/node.cpp +++ b/node/node.cpp @@ -31,7 +31,7 @@ Node::Node(ListenSettings const& listen_settings, NodeNetworkSettings network_se } Node::~Node() { - api.free_key_pair(keypair); + api.free_key_pair(&keypair); } void Node::run() { @@ -68,46 +68,35 @@ void Node::connect_to_next_node() void Node::start_initialisation() { cmix_proto::Initialization init; - init.set_public_share(keypair.pub, keypair.pub_len); + char* pub_key; + size_t len; + api.get_key_array(&pub_key, &len, keypair.pub); + init.set_public_share(pub_key, len); + free(pub_key); + + BOOST_LOG_TRIVIAL(trace) << "Sending intialization as first node"; next_node.async_send(init); } void Node::handle_node_initialization(const cmix_proto::Initialization& init) { - if(init.public_share().size() != keypair.pub_len) { - prev_node.close(); - cmix_proto::Bye bye; - next_node.async_send(bye, [this]{io_service.stop();}); - BOOST_LOG_TRIVIAL(fatal) << "Previous node dit not send proper initialization message."; - return; - } - if(network_settings.is_first) { cmix_proto::SecretKey sec; sec.set_secret_key(network_key.data(), network_key.size()); next_node.async_send(sec); } else { - Bignum shared = allocate_bignum(init.public_share().size()); - std::copy_n(init.public_share().data(), init.public_share().size(), shared.data); - Bignum my_share = allocate_bignum(keypair.pub_len); - std::copy_n(my_share.data, my_share.len, keypair.pub); - Bignum mod = allocate_bignum(keypair.pub_len); - get_curve25519_mod(&mod); - Bignum new_shared = allocate_bignum(keypair.pub_len); - - calculate_shared_key_part(&new_shared, shared, my_share, mod); + char* buffer; + size_t len; + api.add_public_share(&buffer, &len, init.public_share().c_str(), init.public_share().size(), keypair.pub); cmix_proto::Initialization init; - init.set_public_share(new_shared.data, new_shared.len); + init.set_public_share(buffer, len); + free(buffer); + BOOST_LOG_TRIVIAL(trace) << "Sending intialization"; next_node.async_send(init); - - free_bignum(&shared); - free_bignum(&my_share); - free_bignum(&mod); - free_bignum(&new_shared); } } @@ -154,7 +143,14 @@ void Node::handle_client_keyexchange(ClientConnections::key_type handle, cmix_pr data[handle].shared_value = api.derive_shared_key(keypair, reinterpret_cast(ke.public_key().c_str()), true); cmix_proto::KeyExchange exchange; - exchange.set_public_key(keypair.pub, keypair.pub_len); + + char* buffer; + size_t len; + api.get_key_array(&buffer, &len, keypair.pub); + + exchange.set_public_key(buffer, len); + free(buffer); + clients.at(handle).async_send(exchange); } @@ -188,7 +184,7 @@ void Node::handle_client_message(ClientConnections::key_type handle, cmix_proto: void Node::handle_imanode(Purgatory::iterator handle) { handle->on_done([]{}); - prev_node = SSLReceiver(std::move(*handle)); + prev_node = std::move(*handle); purgatory.erase(handle); if(network_settings.is_first) { @@ -204,11 +200,12 @@ void Node::handle_imanode(Purgatory::iterator handle) { void Node::handle_imaclient(Purgatory::iterator handle, cmix_proto::ImAClient c) { std::string client_id = c.id(); - clients.emplace(c.id(), SSLSenderReceiver(std::move(*handle))); + clients.emplace(c.id(), std::move(*handle)); clients.at(c.id()).on_done([this, client_id]{ clients.erase(client_id); }); purgatory.erase(handle); + clients.at(c.id()).async_send(cmix_proto::NodeReady()); clients.at(c.id()).async_receive([this, client_id](cmix_proto::CMixMessage message) { handle_client_message(client_id, message); }); -- cgit v1.2.3-70-g09d2