diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-11-18 15:04:56 +0100 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-11-18 15:04:56 +0100 |
| commit | e4cf0d04c4afff98603df440d12a4a19b3717a34 (patch) | |
| tree | 1cdba5161c787a9f9629fef01bcf30a4d8978930 | |
| parent | 5a3f32ff25e7672ebc453818e7aa01ae84598ce7 (diff) | |
| download | cmix-e4cf0d04c4afff98603df440d12a4a19b3717a34.tar.gz cmix-e4cf0d04c4afff98603df440d12a4a19b3717a34.tar.bz2 cmix-e4cf0d04c4afff98603df440d12a4a19b3717a34.zip | |
The Realtime precomputation step is now done on batch level.
| -rw-r--r-- | libcmix/cmix.c | 26 | ||||
| -rw-r--r-- | libcmix/cmix.h | 2 | ||||
| -rw-r--r-- | node/node.cpp | 61 | ||||
| -rw-r--r-- | node/node_node.cpp | 40 |
4 files changed, 72 insertions, 57 deletions
diff --git a/libcmix/cmix.c b/libcmix/cmix.c index 1430532..d21dab5 100644 --- a/libcmix/cmix.c +++ b/libcmix/cmix.c @@ -326,20 +326,22 @@ enum cmix_error blind_message(struct CMixContext const* ctx, char* m_out, char c return no_error; } -enum cmix_error swap_k_for_r(struct CMixContext const* ctx, char* out_buffer, char const* message, GroupElement const key, size_t index) { +enum cmix_error swap_k_for_r(struct CMixContext const* ctx, char** out_buffer, const char** message, const GroupElement* key, size_t nr_elements) { size_t len = get_group_element_array_size(ctx); - GroupElement mes = ctx->api.array_to_element(message, len, false); - GroupElement inv_key = ctx->api.invert(key); - - GroupElement unblinded = ctx->api.multiply(mes, inv_key, false); - GroupElement blinded = ctx->api.multiply(unblinded, ctx->r[index], false); - - element_to_buffer(ctx, out_buffer, blinded); - ctx->api.free_group_element(mes); - ctx->api.free_group_element(inv_key); - ctx->api.free_group_element(unblinded); - ctx->api.free_group_element(blinded); + for(size_t i = 0; i < nr_elements; ++i) { + GroupElement mes = ctx->api.array_to_element(message[i], len, false); + GroupElement inv_key = ctx->api.invert(key[i]); + + GroupElement unblinded = ctx->api.multiply(mes, inv_key, false); + GroupElement blinded = ctx->api.multiply(unblinded, ctx->r[i], false); + + element_to_buffer(ctx, out_buffer[i], blinded); + ctx->api.free_group_element(mes); + ctx->api.free_group_element(inv_key); + ctx->api.free_group_element(unblinded); + ctx->api.free_group_element(blinded); + } return no_error; } diff --git a/libcmix/cmix.h b/libcmix/cmix.h index 390b28f..057fd60 100644 --- a/libcmix/cmix.h +++ b/libcmix/cmix.h @@ -105,7 +105,7 @@ enum cmix_error enqueue_message(struct CMixContext* ctx, char const* message, si enum cmix_error enqueue_random_message(struct CMixContext* ctx, size_t index); -enum cmix_error swap_k_for_r(struct CMixContext const* ctx, char* out_buffer, char const* message, GroupElement const key, size_t index); +enum cmix_error swap_k_for_r(struct CMixContext const* ctx, char** out_buffer, char const** message, GroupElement const* key, size_t nr_elements); enum cmix_error remove_r_and_s(struct CMixContext const* ctx, char* out_buffer, char const* message, size_t index); diff --git a/node/node.cpp b/node/node.cpp index b29a873..3ad4a2d 100644 --- a/node/node.cpp +++ b/node/node.cpp @@ -208,34 +208,47 @@ 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; + + std::vector<char*> ms(index_map.size(), nullptr); + std::vector<char const*> msv(index_map.size(), nullptr); + std::vector<GroupElement> keys(index_map.size(), nullptr); + auto it = index_map.begin(); + for(size_t i = 0; i < index_map.size(); ++i) { + auto handle = it->first; + auto index = it->second; + + std::string* m = realpre.add_m(); + m->resize(len); + ms[i] = &(*m)[0]; - auto& queue = messages[pair.first]; + auto& queue = messages.at(handle); 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 { - std::string x = to_string(data.at(handle).shared_value, cmix_ctx); - { - std::stringstream ss; - ss << "shared_key: "; - for(auto&& c : x) { - ss << "\\" << std::setw(3) << std::setfill('0') << std::oct << (unsigned int) c; - } - BOOST_LOG_TRIVIAL(trace) << ss.str(); - } + std::string v; + v.resize(len); + generate_random_message(&cmix_ctx, &v[0]); + queue.push(v); + } - BOOST_LOG_TRIVIAL(trace) << + msv[i] = queue.front().data(); - swap_k_for_r(&cmix_ctx, &(*realpre.mutable_m(index))[0], queue.front().data(), data.at(handle).shared_value, index); - } - *realpre.mutable_h(index) = handle; + keys[i] = data.at(handle).shared_value; + + realpre.add_h(handle); + + it++; } + + swap_k_for_r( + &cmix_ctx, + ms.data(), + msv.data(), + keys.data(), + index_map.size() + ); + + for(auto&& pair : index_map) { + messages.at(pair.first).pop(); + } + next_node.async_send(realpre); } diff --git a/node/node_node.cpp b/node/node_node.cpp index 63a44df..7990a12 100644 --- a/node/node_node.cpp +++ b/node/node_node.cpp @@ -126,31 +126,31 @@ cmix_proto::RealPre fill_realtime_pre_message(CMixContext& ctx, T const& hs, T c cmix_proto::RealPre realpre; size_t len = get_group_element_array_size(&ctx); + + std::vector<char*> msv1(ms.size(), nullptr); + std::vector<char const*> msv2(ms.size(), nullptr); + std::vector<GroupElement> gs(ms.size(), nullptr); + for(int i = 0; i < ms.size(); ++i) { - realpre.add_h(); - realpre.add_m(); - realpre.mutable_m(i)->resize(len); + std::string* m = realpre.add_m(); + m->resize(len); + msv1[i] = &(*m)[0]; - std::string x = to_string(data.at(hs.Get(i)).shared_value, ctx); - { - std::stringstream ss; - ss << "shared_key: "; - for(auto&& c : x) { - ss << "\\" << std::setw(3) << std::setfill('0') << std::oct << (unsigned int) c; - } - BOOST_LOG_TRIVIAL(trace) << ss.str(); - } + msv2[i] = ms.Get(i).data(); + + realpre.add_h(hs.Get(i)); - swap_k_for_r( - &ctx, - &(*realpre.mutable_m(i))[0], - ms.Get(i).data(), - data.at(hs.Get(i)).shared_value, - i - ); - *realpre.mutable_h(i) = hs.Get(i); + gs[i] = data.at(hs.Get(i)).shared_value; } + swap_k_for_r( + &ctx, + msv1.data(), + msv2.data(), + gs.data(), + ms.size() + ); + return realpre; } |
