Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
4 changes: 3 additions & 1 deletion emp-tool/circuits/aes_128_ctr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -269,6 +270,7 @@ class AES_128_CTR_Calculator { public:
}
}
}
delete[] bytes;
return 0;
}
};
Expand Down
2 changes: 2 additions & 0 deletions emp-tool/circuits/integer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class Integer : public Swappable<Integer>, public Comparable<Integer> { 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"
Expand Down
35 changes: 20 additions & 15 deletions emp-tool/circuits/integer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(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<uint32_t>(int party) const {
assert(size()<=32);
return reveal_helper(party, false);
}

template<>
inline uint64_t Integer::reveal<uint64_t>(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<int32_t>(int party) const {
return reveal<uint32_t>(party);
assert(size()<=32);
return reveal_helper(party, true);
}

template<>
inline int64_t Integer::reveal<int64_t>(int party) const {
return reveal<uint64_t>(party);
assert(size()<=64);
return reveal_helper(party, true);
}


Expand Down
16 changes: 16 additions & 0 deletions test/int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,26 @@ void scratch_pad() {
cout <<(a+b).reveal<int32_t>(PUBLIC)<<endl;
// cout << "LZ "<<a.leading_zeros().reveal<int64_t>(PUBLIC)<<endl;
}

void corner_cases() {
for (int L = 2; L <=32; ++L) {
Integer y = Integer(L, -1, ALICE);
assert(y.reveal<int32_t>(PUBLIC) == -1);
}

for (int L = 33; L <= 64; ++L) {
Integer y = Integer(L, -2147483649LL, ALICE);
assert(y.reveal<int64_t>(PUBLIC) == -2147483649LL);
}

cout << "Corner cases\t\t\tDONE"<<endl;
}

int main(int argc, char** argv) {
int party = PUBLIC;
setup_plain_prot(false, "");

corner_cases();
// scratch_pad();return 0;
test_int<std::plus<int>, std::plus<Integer>>(party);
test_int<std::minus<int>, std::minus<Integer>>(party);
Expand Down
2 changes: 1 addition & 1 deletion test/to_bool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
Loading