From 4f2c980343b321e7fccf48190c32bfb4bca426f4 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Tue, 4 Oct 2016 12:18:35 +0200 Subject: Added a bignum library to abstract possible implementations. --- node/node.cpp | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'node/node.cpp') diff --git a/node/node.cpp b/node/node.cpp index 53dd30c..c9f6b14 100644 --- a/node/node.cpp +++ b/node/node.cpp @@ -2,7 +2,7 @@ #include "logging.hpp" -#include "gmpxx.h" +#include "bignum.h" #include @@ -87,36 +87,26 @@ void Node::handle_initialization(const cmix_proto::Initialization& init) start_precomputation(); } else { - mpz_t shared; - mpz_init(shared); - mpz_import(shared, init.public_share().size(), -1, 1, 0, 0, init.public_share().data()); + Bignum shared = allocate_bignum(init.public_share().size()); + std::copy_n(init.public_share().data(), init.public_share().size(), shared.data); + Bignum my_share{keypair.pub, keypair.pub_len}; + Bignum mod = allocate_bignum(keypair.pub_len); + Bignum new_shared = allocate_bignum(keypair.pub_len); - mpz_t my_share; - mpz_init(my_share); - mpz_import(my_share, keypair.pub_len, -1, 1, 0, 0, keypair.pub); - - mpz_mul(shared, shared, my_share); - - mpz_t mod; - mpz_init(mod); - mpz_set_ui(mod, 2); - mpz_pow_ui(mod, mod, 255); - mpz_sub_ui(mod, mod, 19); - - mpz_mod(shared, shared, mod); - - std::vector new_shared(keypair.pub_len, '\0'); - size_t size; - mpz_export(new_shared.data(), &size, -1, 1, 0, 0, shared); + if(multiply_mod(&new_shared, shared, my_share, mod) != NoError) { + BOOST_LOG_TRIVIAL(fatal) << "Group multiplication failed"; + throw std::runtime_error("Group multiplication failed"); + } cmix_proto::Initialization init; - init.set_public_share(new_shared.data(), new_shared.size()); + init.set_public_share(new_shared.data, new_shared.len); next_node.send(init); + + free_bignum(&shared); + free_bignum(&mod); + free_bignum(&new_shared); - mpz_clear(shared); - mpz_clear(my_share); - mpz_clear(mod); } } -- cgit v1.2.3-70-g09d2