aboutsummaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
Diffstat (limited to 'node')
-rw-r--r--node/CMakeLists.txt5
-rw-r--r--node/node.cpp40
2 files changed, 16 insertions, 29 deletions
diff --git a/node/CMakeLists.txt b/node/CMakeLists.txt
index 6fe0ef7..9151cbc 100644
--- a/node/CMakeLists.txt
+++ b/node/CMakeLists.txt
@@ -1,7 +1,5 @@
find_package(Boost COMPONENTS system program_options REQUIRED)
-find_package(gmp REQUIRED)
-
add_executable(node
main.cpp
node.hpp node.cpp
@@ -25,8 +23,7 @@ target_link_libraries(node
PRIVATE Boost::system
PRIVATE log
PRIVATE cmix
+ PRIVATE cmix-bignum
PRIVATE cmix-network
PRIVATE cmix-protobuf
- PRIVATE gmpxx
- PRIVATE gmp
)
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 <iostream>
@@ -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<uint8_t> 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);
}
}