emp-toolkit
bit.hpp
Go to the documentation of this file.
1 inline Bit::Bit(bool b, int party) {
2  if (party == PUBLIC)
4  else local_backend->Feed(&bit, party, &b, 1);
5 }
6 
7 inline Bit Bit::select(const Bit & select, const Bit & new_v) const{
8  Bit tmp = *this;
9  tmp = tmp ^ new_v;
10  tmp = tmp & select;
11  return *this ^ tmp;
12 }
13 
14 template<typename O>
15 inline O Bit::reveal(int party) const {
16  O res;
17  local_backend->Reveal(&res, party, &bit, 1);
18  return res;
19 }
20 
21 template<>
22 inline string Bit::reveal<string>(int party) const {
23  bool res;
24  local_backend->Reveal(&res, party, &bit, 1);
25  return res ? "true" : "false";
26 }
27 
28 
29 
30 inline Bit Bit::operator==(const Bit& rhs) const {
31  return !(*this ^ rhs);
32 }
33 
34 inline Bit Bit::operator!=(const Bit& rhs) const {
35  return (*this) ^ rhs;
36 }
37 
38 inline Bit Bit::operator &(const Bit& rhs) const{
39  Bit res;
40  res.bit = local_gc->gc_and(bit, rhs.bit);
41  return res;
42 }
43 inline Bit Bit::operator ^(const Bit& rhs) const{
44  Bit res;
45  res.bit = local_gc->gc_xor(bit, rhs.bit);
46  return res;
47 }
48 
49 inline Bit Bit::operator |(const Bit& rhs) const{
50  return (*this ^ rhs) ^ (*this & rhs);
51 }
52 
53 inline Bit Bit::operator!() const {
54  return local_gc->gc_not(bit);
55 }
Bit(bool _b=false, int party=PUBLIC)
Definition: bit.hpp:1
O reveal(int party=PUBLIC) const
Definition: bit.hpp:15
Bit operator==(const Bit &rhs) const
Definition: bit.hpp:30
block gc_xor(const block &a, const block &b)
Definition: garble_circuit.h:24
block public_label(bool b)
Definition: garble_circuit.h:18
Bit operator!() const
Definition: bit.hpp:53
void Reveal(bool *out, int party, const block *lbls, int nel)
Definition: backend.h:15
#define PUBLIC
Definition: utils.h:14
void Feed(block *lbls, int party, const bool *b, int nel)
Definition: backend.h:12
Bit operator!=(const Bit &rhs) const
Definition: bit.hpp:34
Definition: bit.h:8
Bit operator^(const Bit &rhs) const
Definition: bit.hpp:43
block gc_not(const block &a)
Definition: garble_circuit.h:27
Backend * local_backend
Definition: backend.cpp:7
block gc_and(const block &a, const block &b)
Definition: garble_circuit.h:21
Bit select(const Bit &select, const Bit &new_v) const
Definition: bit.hpp:7
int party
Definition: input-check-malicious.cpp:12
GarbleCircuit * local_gc
Definition: backend.cpp:8
block bit
Definition: bit.h:9
Bit operator|(const Bit &rhs) const
Definition: bit.hpp:49
Bit operator&(const Bit &rhs) const