diff --git a/CMakeLists.txt b/CMakeLists.txt index d9abb31..72ee331 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.0) +cmake_minimum_required (VERSION 3.0...4.1.2) project (emptool) set(NAME "emp-tool") diff --git a/emp-tool/circuits/aes_128_ctr.h b/emp-tool/circuits/aes_128_ctr.h index 6a1f278..dd9c33b 100644 --- a/emp-tool/circuits/aes_128_ctr.h +++ b/emp-tool/circuits/aes_128_ctr.h @@ -247,9 +247,10 @@ class AES_128_CTR_Calculator { public: return -1; } - uint8_t bytes[(length + 7) / 8]; + uint8_t * bytes = new uint8_t[(length + 7) / 8]; int success = emp::aes_128_ctr(key, iv, (uint8_t *) nullptr, bytes, (length + 7) / 8, start_chunk); if (success != 0) { + delete[] bytes; return success; } emp::Integer blind = emp::Integer(length, bytes, party); @@ -269,6 +270,7 @@ class AES_128_CTR_Calculator { public: } } } + delete[] bytes; return 0; } }; diff --git a/emp-tool/circuits/integer.h b/emp-tool/circuits/integer.h index 5395eab..459e30e 100644 --- a/emp-tool/circuits/integer.h +++ b/emp-tool/circuits/integer.h @@ -66,6 +66,8 @@ class Integer : public Swappable, public Comparable { public: void init(bool * b, int len, int party); void revealBools(bool *bools, int party=PUBLIC) const; +private: + uint64_t reveal_helper(int party, bool sign) const; }; #include "emp-tool/circuits/integer.hpp" diff --git a/emp-tool/circuits/integer.hpp b/emp-tool/circuits/integer.hpp index ebff9ba..210e589 100644 --- a/emp-tool/circuits/integer.hpp +++ b/emp-tool/circuits/integer.hpp @@ -179,35 +179,40 @@ inline void Integer::revealBools(bool *bools, int party) const { ProtocolExecution::prot_exec->reveal(bools, party, (block *)bits.data(), size()); } -template<> -inline uint32_t Integer::reveal(int party) const { - std::bitset<32> bs; +inline uint64_t Integer::reveal_helper(int party, bool sign) const { + std::bitset<64> bs; bs.reset(); - bool b[size()]; + bool b[64]; ProtocolExecution::prot_exec->reveal(b, party, (block *)bits.data(), size()); - for (size_t i = 0; i < min(32UL, size()); ++i) + for (size_t i = 0; i < size(); ++i) bs.set(i, b[i]); - return bs.to_ulong(); + for (size_t i = size(); i < 64; ++i) + bs.set(i, sign and (b[size()-1])); + return bs.to_ullong(); +} + + +template<> +inline uint32_t Integer::reveal(int party) const { + assert(size()<=32); + return reveal_helper(party, false); } template<> inline uint64_t Integer::reveal(int party) const { - std::bitset<64> bs; - bs.reset(); - bool b[size()]; - ProtocolExecution::prot_exec->reveal(b, party, (block *)bits.data(), size()); - for (size_t i = 0; i < min(64UL, size()); ++i) - bs.set(i, b[i]); - return bs.to_ullong(); + assert(size()<=64); + return reveal_helper(party, false); } template<> inline int32_t Integer::reveal(int party) const { - return reveal(party); + assert(size()<=32); + return reveal_helper(party, true); } template<> inline int64_t Integer::reveal(int party) const { - return reveal(party); + assert(size()<=64); + return reveal_helper(party, true); } diff --git a/test/int.cpp b/test/int.cpp index 96fd944..a694111 100644 --- a/test/int.cpp +++ b/test/int.cpp @@ -42,10 +42,26 @@ void scratch_pad() { cout <<(a+b).reveal(PUBLIC)<(PUBLIC)<(PUBLIC) == -1); + } + + for (int L = 33; L <= 64; ++L) { + Integer y = Integer(L, -2147483649LL, ALICE); + assert(y.reveal(PUBLIC) == -2147483649LL); + } + + cout << "Corner cases\t\t\tDONE"<, std::plus>(party); test_int, std::minus>(party); diff --git a/test/to_bool.cpp b/test/to_bool.cpp index 73eb147..dff28b3 100644 --- a/test/to_bool.cpp +++ b/test/to_bool.cpp @@ -13,7 +13,7 @@ struct testMe { // Just testing to see if we can move some arbitrary arrays of structs to bool and back again. int main() { - uint8_t len = 100; + const uint8_t len = 100; struct testMe structs[len]; struct testMe output[len]; bool b[len * 8 * sizeof(struct testMe)];