diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2017-05-21 14:27:55 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2017-05-21 14:27:55 +0200 |
| commit | e1e1e9ac34ab70c3a1f2344361c7e04e5f15c3bd (patch) | |
| tree | bf9c27edae6fb6c6f0c186cc06db92378e53055b | |
| parent | ce2d83a434cea8a6317690aadbb478a58858ad5b (diff) | |
| download | cmix-e1e1e9ac34ab70c3a1f2344361c7e04e5f15c3bd.tar.gz cmix-e1e1e9ac34ab70c3a1f2344361c7e04e5f15c3bd.tar.bz2 cmix-e1e1e9ac34ab70c3a1f2344361c7e04e5f15c3bd.zip | |
Removes bias from generating random curve points.
| -rw-r--r-- | libcmix-crypto/ed25519/gcrypt/gcrypt_ed25519.c | 56 | ||||
| -rw-r--r-- | node/node.cpp | 14 | ||||
| -rw-r--r-- | node/node_node.cpp | 2 | ||||
| -rw-r--r-- | statsd/stats.cpp | 37 | ||||
| -rw-r--r-- | statsd/stats.hpp | 2 |
5 files changed, 59 insertions, 52 deletions
diff --git a/libcmix-crypto/ed25519/gcrypt/gcrypt_ed25519.c b/libcmix-crypto/ed25519/gcrypt/gcrypt_ed25519.c index c8913cf..bcaca51 100644 --- a/libcmix-crypto/ed25519/gcrypt/gcrypt_ed25519.c +++ b/libcmix-crypto/ed25519/gcrypt/gcrypt_ed25519.c @@ -306,58 +306,60 @@ GroupElement DEF(get_group_element)(bool secure) { (void) secure; size_t parse_error_offset; gcry_error_t error; - + + gcry_mpi_point_t point = gcry_mpi_point_new(0); gcry_mpi_t a = NULL; void* bytes = NULL; + char* encoded_point = NULL; do { - gcry_free(bytes); - gcry_mpi_release(a); - bytes = gcry_random_bytes_secure(nr_bytes, GCRY_VERY_STRONG_RANDOM); - TRACE(__FILE__, __LINE__, bytes); - error = gcry_mpi_scan(&a, GCRYMPI_FMT_USG, bytes, nr_bytes, &parse_error_offset); - TRACE(__FILE__,__LINE__, a); - check(error); - } while(gcry_mpi_cmp_ui(a, 0) == 0 || gcry_mpi_cmp(a, p) != -1); - - char* encoded_point = (char*) calloc(nr_bytes+1, sizeof(char)); - TRACE(__FILE__, __LINE__, encoded_point) - gcry_mpi_point_t point = gcry_mpi_point_new(0); - do { + do { + gcry_free(bytes); + gcry_mpi_release(a); + bytes = gcry_random_bytes_secure(nr_bytes, GCRY_VERY_STRONG_RANDOM); + TRACE(__FILE__, __LINE__, bytes); + error = gcry_mpi_scan(&a, GCRYMPI_FMT_USG, bytes, nr_bytes, &parse_error_offset); + TRACE(__FILE__,__LINE__, a); + check(error); + } while(gcry_mpi_cmp_ui(a, 0) == 0 || gcry_mpi_cmp(a, p) != -1); + + char* encoded_point = (char*) calloc(nr_bytes+1, sizeof(char)); + TRACE(__FILE__, __LINE__, encoded_point) + + free(encoded_point); + encoded_point = (char*) calloc(nr_bytes+1, sizeof(char)); encoded_point[0] = 0x40; - + unsigned int byte_size = (unsigned) ceil(gcry_mpi_get_nbits(a) / 8.0); gcry_mpi_print(GCRYMPI_FMT_USG, (unsigned char*) encoded_point + 1, 32, NULL, a); - + for(int i = 0; i < 16; i++) { char temp = encoded_point[i+1]; encoded_point[i+1] = encoded_point[32-i]; encoded_point[32-i] = temp; } - + gcry_mpi_t encoded_mpi = gcry_mpi_new(0); TRACE(__FILE__, __LINE__, encoded_mpi) gcry_mpi_set_opaque_copy(encoded_mpi, encoded_point, (nr_bytes + 1) * sizeof(char) * 8); - + error = gcry_mpi_ec_decode_point(point, encoded_mpi, ctx); check(error); - + gcry_mpi_release(encoded_mpi); - + if(!gcry_mpi_ec_curve_point(point, ctx)) { gcry_mpi_point_release(point); point = gcry_mpi_point_new(0); - - gcry_mpi_add_ui(a, a, 1); } - + } while(!gcry_mpi_ec_curve_point(point, ctx)); - + gcry_mpi_release(a); gcry_free(bytes); free(encoded_point); - + TRACE(__FILE__, __LINE__, point); - + return point; } @@ -526,4 +528,4 @@ void DEF(deinitialize)(void) { gcry_ctx_release(ctx); } -LINK_IMPLEMENTATION
\ No newline at end of file +LINK_IMPLEMENTATION diff --git a/node/node.cpp b/node/node.cpp index cb25431..dd6061a 100644 --- a/node/node.cpp +++ b/node/node.cpp @@ -1,4 +1,4 @@ - #include "node.hpp" +#include "node.hpp" #include "cmix.h" @@ -143,10 +143,6 @@ void Node::handle_message(Purgatory::iterator handle, cmix_proto::CMixMessage me } void Node::start_precomputation() { - if(performance) { - performance->send("pre_pre_start"); - } - BOOST_LOG_TRIVIAL(trace) << "Starting precomputation for " << messages.size() << " clients."; participants.clear(); @@ -154,6 +150,10 @@ void Node::start_precomputation() { start_timer_delayed_mix(); return; } + + if(performance) { + performance->send("pre_pre_start"); + } if(start_mix(&cmix_ctx, messages.size()) != no_error) { exit(-1); @@ -217,11 +217,11 @@ void Node::start_precomputation() { } void Node::start_realtime_phase() { - + if(performance) { performance->send("real_pre_start"); } - + ArenaMessage<cmix_proto::RealPre> arena; cmix_proto::RealPre& realpre = arena.get(); diff --git a/node/node_node.cpp b/node/node_node.cpp index 844fdc3..37d878c 100644 --- a/node/node_node.cpp +++ b/node/node_node.cpp @@ -460,7 +460,7 @@ void Node::handle_node_realpost(cmix_proto::RealPost const& realpost) { char* dest; size_t dest_len; - char* payload; + char* payload = nullptr; size_t payload_len; split_message(&cmix_ctx, &dest, &dest_len, &payload, &payload_len, message); diff --git a/statsd/stats.cpp b/statsd/stats.cpp index a448449..2202f32 100644 --- a/statsd/stats.cpp +++ b/statsd/stats.cpp @@ -12,7 +12,7 @@ void Stats::accept_connection(std::unique_ptr<boost::asio::ip::tcp::socket>&& so }); } -void Stats::handle_performance(std::list<Receiver>::iterator it, const cmix_proto::Performance& perf) { +void Stats::handle_performance(std::list<Receiver>::iterator it, cmix_proto::Performance perf) { data[perf.node()][perf.column() + "wall_time"].push_back(std::stol(perf.wall_time())); data[perf.node()][perf.column() + "system_time"].push_back(std::stol(perf.system_time())); data[perf.node()][perf.column() + "user_time"].push_back(std::stol(perf.user_time())); @@ -24,20 +24,20 @@ void Stats::handle_performance(std::list<Receiver>::iterator it, const cmix_prot void Stats::handle_message(std::list<Receiver>::iterator it, cmix_proto::CMixMessage message) { switch(message.contents_case()) { - case cmix_proto::CMixMessage::ContentsCase::kPerformance: { - BOOST_LOG_TRIVIAL(trace) << "Handling performance"; - handle_performance(it, message.performance()); - break; - } - case cmix_proto::CMixMessage::ContentsCase::kBye: { - BOOST_LOG_TRIVIAL(trace) << "Handling Bye"; - - break; - } - default: { - BOOST_LOG_TRIVIAL(error) << "handle_message: CMixMessage contains unknown contents."; - connections.erase(it); - } + case cmix_proto::CMixMessage::ContentsCase::kPerformance: { + BOOST_LOG_TRIVIAL(trace) << "Handling performance"; + handle_performance(it, message.performance()); + break; + } + case cmix_proto::CMixMessage::ContentsCase::kBye: { + BOOST_LOG_TRIVIAL(trace) << "Handling Bye"; + + break; + } + default: { + BOOST_LOG_TRIVIAL(error) << "handle_message: CMixMessage contains unknown contents."; + connections.erase(it); + } } } @@ -67,7 +67,12 @@ void Stats::output(std::string file) if(it != table.second.begin()) { ofs << ", "; } - ofs << it->second[i]; + if(table.second.begin()->second.size() != it->second.size()) { + ofs << it->second[i*2]; + } else { + ofs << it->second[i]; + } + } ofs << std::endl; } diff --git a/statsd/stats.hpp b/statsd/stats.hpp index 4e1c18f..b23da40 100644 --- a/statsd/stats.hpp +++ b/statsd/stats.hpp @@ -29,7 +29,7 @@ class Stats { void accept_connection(std::unique_ptr<boost::asio::ip::tcp::socket>&& socket); - void handle_performance(std::list<Receiver>::iterator it, cmix_proto::Performance const& perf); + void handle_performance(std::list<Receiver>::iterator it, cmix_proto::Performance perf); void handle_message(std::list<Receiver>::iterator it, cmix_proto::CMixMessage message); |
