|
@@ -1,7 +1,8 @@
|
|
|
-uint64_t binary_to_decimal(std::array<uint64_t, 64> inp)
|
|
|
+//template<size_t N>
|
|
|
+int64_t binary_to_decimal(int64_t* inp, size_t logn)
|
|
|
{
|
|
|
- uint64_t output = 0;
|
|
|
- for(size_t j = 0; j < 64; ++j)
|
|
|
+ int64_t output = 0;
|
|
|
+ for(size_t j = 0; j < logn; ++j)
|
|
|
{
|
|
|
output += (1ULL << j) * inp[j];
|
|
|
}
|
|
@@ -102,13 +103,18 @@ void P2_xor_to_additive(tcp::socket& s0, tcp::socket& s1, size_t socket_no)
|
|
|
boost::asio::write(s1, boost::asio::buffer(&gamma1, sizeof(gamma1)));
|
|
|
}
|
|
|
|
|
|
-int64_t xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb, tcp::socket& s2)
|
|
|
+void xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb, tcp::socket& s2, const size_t height, int64_t& R_share)
|
|
|
{
|
|
|
- const size_t logn = 64;
|
|
|
- std::array<uint64_t, logn> b, b_blinded, b_recv;
|
|
|
+ const size_t logn = height;
|
|
|
+ //std::array<uint64_t, logn> b, b_blinded, b_recv;
|
|
|
+
|
|
|
+ int64_t b[64], b_blinded[64], b_recv[64];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
for(size_t j = 0; j < logn; ++j)
|
|
|
{
|
|
|
- b[j] = target_share_read[j];
|
|
|
+ b[j] = target_share_read[logn-j - 1];
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
uint8_t target_bit_rec;
|
|
@@ -119,16 +125,18 @@ int64_t xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb
|
|
|
}
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
- uint64_t b_ = binary_to_decimal(b);
|
|
|
+ uint64_t b_ = binary_to_decimal(b, logn);;
|
|
|
std::cout << "b_ = " << b_ << std::endl;
|
|
|
#endif
|
|
|
|
|
|
- std::array<uint64_t, logn> c_mul;
|
|
|
- std::array<uint64_t, logn> d;
|
|
|
-
|
|
|
- uint64_t BLIND, Gamma;
|
|
|
- boost::asio::read(s2, boost::asio::buffer(&BLIND, sizeof(uint64_t)));
|
|
|
- boost::asio::read(s2, boost::asio::buffer(&Gamma, sizeof(uint64_t)));
|
|
|
+ // std::array<uint64_t, logn> c_mul;
|
|
|
+ // std::array<uint64_t, logn> d;
|
|
|
+ //uint64_t c_mul[logn], d[logn];
|
|
|
+ int64_t * c_mul = (int64_t*) malloc(logn * sizeof(int64_t));
|
|
|
+ int64_t * d = (int64_t*) malloc(logn * sizeof(int64_t));
|
|
|
+ int64_t BLIND, Gamma;
|
|
|
+ boost::asio::read(s2, boost::asio::buffer(&BLIND, sizeof(int64_t)));
|
|
|
+ boost::asio::read(s2, boost::asio::buffer(&Gamma, sizeof(int64_t)));
|
|
|
|
|
|
|
|
|
for(size_t j = 0; j < logn; ++j)
|
|
@@ -144,8 +152,8 @@ int64_t xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb
|
|
|
std::cout << "Gamma = " << Gamma << std::endl;
|
|
|
#endif
|
|
|
|
|
|
- uint64_t R_share = 0;
|
|
|
-
|
|
|
+ // uint64_t R_share = 0;
|
|
|
+
|
|
|
if(!party)
|
|
|
{
|
|
|
for(size_t j = 0; j < logn; ++j)
|
|
@@ -165,12 +173,12 @@ int64_t xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb
|
|
|
R_share += (1ULL << j) * d[j];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
#ifdef DEBUG
|
|
|
for(size_t j = 0; j < 1; ++j)
|
|
|
{
|
|
|
std::cout << "b = " << b[j] << std::endl;
|
|
|
- uint64_t mul_Rec = 0;
|
|
|
+ int64_t mul_Rec = 0;
|
|
|
boost::asio::write(sb, boost::asio::buffer(&c_mul[j], sizeof(c_mul[j])));
|
|
|
boost::asio::read(sb, boost::asio::buffer(&mul_Rec, sizeof(mul_Rec)));
|
|
|
std::cout << "c_mul = " << c_mul[j] << std::endl;
|
|
@@ -178,9 +186,14 @@ int64_t xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb
|
|
|
std::cout << "mul_Rec = " << mul_Rec << std::endl;
|
|
|
}
|
|
|
|
|
|
- std::array<uint64_t, logn> b_reconstruction_;
|
|
|
- std::array<uint64_t, logn> d_reconstruction_;
|
|
|
- std::array<uint64_t, logn> d_recv;
|
|
|
+ //std::array<uint64_t, logn> b_reconstruction_;
|
|
|
+ //std::array<uint64_t, logn> d_reconstruction_;
|
|
|
+ // uint64_t b_reconstruction_[logn], d_reconstruction_[logn], d_recv[logn];
|
|
|
+ int64_t * b_reconstruction_ = (int64_t*) malloc(logn * sizeof(int64_t));
|
|
|
+ int64_t * d_reconstruction_ = (int64_t*) malloc(logn * sizeof(int64_t));
|
|
|
+ int64_t * d_recv = (int64_t*) malloc(logn * sizeof(int64_t));
|
|
|
+
|
|
|
+ //std::array<uint64_t, logn> d_recv;
|
|
|
for(size_t j = 0; j < logn; ++j)
|
|
|
{
|
|
|
boost::asio::write(sb, boost::asio::buffer(&d[j], sizeof(d[j])));
|
|
@@ -192,30 +205,33 @@ int64_t xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb
|
|
|
|
|
|
for(size_t j = 0; j < logn; ++j)
|
|
|
{
|
|
|
- uint64_t d_reconstruction = d[j] + d_recv[j];
|
|
|
+ int64_t d_reconstruction = d[j] + d_recv[j];
|
|
|
d_reconstruction_[j] = d_reconstruction;
|
|
|
- uint64_t b_reconstruction = b[j] ^ b_recv[j];
|
|
|
+ int64_t b_reconstruction = b[j] ^ b_recv[j];
|
|
|
b_reconstruction_[j] = b_reconstruction;
|
|
|
assert(d_reconstruction == b_reconstruction);
|
|
|
}
|
|
|
|
|
|
- uint64_t b_value = binary_to_decimal(b_reconstruction_);
|
|
|
+ int64_t b_value = binary_to_decimal(b_reconstruction_, logn);
|
|
|
std::cout << "b_value = " << b_value << std::endl;
|
|
|
std::cout << "logn = " << logn << std::endl;
|
|
|
|
|
|
std::cout << "R_share = " << R_share << std::endl;
|
|
|
- R_share = binary_to_decimal(d);
|
|
|
+ #endif
|
|
|
+ R_share = binary_to_decimal(d, logn);
|
|
|
+
|
|
|
+ #ifdef DEBUG
|
|
|
std::cout << "R_share = " << R_share << std::endl;
|
|
|
- uint64_t R_share_reconstruction;
|
|
|
+ int64_t R_share_reconstruction;
|
|
|
boost::asio::write(sb, boost::asio::buffer(&R_share, sizeof(R_share)));
|
|
|
boost::asio::read(sb, boost::asio::buffer(&R_share_reconstruction, sizeof(R_share_reconstruction)));
|
|
|
R_share_reconstruction = R_share_reconstruction + R_share;
|
|
|
std::cout << "R_share_reconstruction = " << R_share_reconstruction << std::endl;
|
|
|
std::cout << "b_value = " << b_value << std::endl;
|
|
|
- std::cout << "d_recons = " << binary_to_decimal(d_reconstruction_)<< std::endl;
|
|
|
+ std::cout << "d_recons = " << binary_to_decimal(d_reconstruction_, logn) << std::endl;
|
|
|
#endif
|
|
|
|
|
|
- return R_share;
|
|
|
+ // return R_share;
|
|
|
}
|
|
|
|
|
|
|