MOTION  0.01
Framework for mixed-protocol multi-party computation
constant_wire.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Oleksandr Tkachenko
4 // Cryptography and Privacy Engineering Group (ENCRYPTO)
5 // TU Darmstadt, Germany
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 
25 #pragma once
26 
27 #include "protocols/wire.h"
28 #include "utility/bit_vector.h"
29 
30 namespace encrypto::motion::proto {
31 
32 template <typename T>
33 class ConstantArithmeticWire final : public Wire {
34  public:
35  using value_type = T;
36 
37  ConstantArithmeticWire(Backend& backend, std::size_t number_of_simd)
38  : Wire(backend, number_of_simd) {}
39 
40  ConstantArithmeticWire(std::vector<T>&& values, Backend& backend)
41  : Wire(backend, values.size()), values_(std::move(values)) {}
42 
43  ConstantArithmeticWire(const std::vector<T>& values, Backend& backend)
44  : Wire(backend, values.size()), values_(values) {}
45 
46  ConstantArithmeticWire(T t, Backend& backend) : Wire(backend, 1), values_({t}) {}
47 
49 
51 
53 
54  const std::vector<T>& GetValues() const { return values_; }
55 
56  std::vector<T>& GetMutableValues() { return values_; }
57 
58  std::size_t GetBitLength() const final { return sizeof(T) * 8; }
59 
60  bool IsConstant() const noexcept final { return true; }
61 
62  private:
63  std::vector<T> values_;
64 };
65 
66 template <typename T>
67 using ConstantArithmeticWirePointer = std::shared_ptr<ConstantArithmeticWire<T>>;
68 
69 class ConstantBooleanWire final : public BooleanWire {
70  public:
71  ConstantBooleanWire(Backend& backend, std::size_t number_of_simd);
72 
73  ConstantBooleanWire(BitVector<>&& values, Backend& backend);
74 
75  ConstantBooleanWire(const BitVector<>& values, Backend& backend);
76 
77  ConstantBooleanWire(bool value, Backend& backend);
78 
79  ~ConstantBooleanWire() final = default;
80 
82 
83  ConstantBooleanWire() = delete;
84 
86 
87  std::size_t GetBitLength() const final { return 1; }
88 
89  const BitVector<>& GetValues() const { return values_; }
90 
91  BitVector<>& GetMutableValues() { return values_; }
92 
93  bool IsConstant() const noexcept final { return true; }
94 
95  private:
96  BitVector<> values_;
97 };
98 
99 using ConstantBooleanWirePointer = std::shared_ptr<ConstantBooleanWire>;
100 
101 } // namespace encrypto::motion::proto
encrypto::motion::proto
Definition: backend.h:43
encrypto::motion::proto::ConstantArithmeticWire::GetBitLength
std::size_t GetBitLength() const final
Definition: constant_wire.h:58
encrypto::motion::MpcProtocol::kArithmeticConstant
@ kArithmeticConstant
encrypto::motion::CircuitType
CircuitType
Definition: typedefs.h:165
encrypto::motion::BooleanWire
Definition: wire.h:112
encrypto::motion::proto::ConstantBooleanWirePointer
std::shared_ptr< ConstantBooleanWire > ConstantBooleanWirePointer
Definition: constant_wire.h:99
encrypto::motion::proto::ConstantBooleanWire::IsConstant
bool IsConstant() const noexcept final
Definition: constant_wire.h:93
encrypto::motion::proto::ConstantArithmeticWire::~ConstantArithmeticWire
~ConstantArithmeticWire() final=default
encrypto::motion::proto::ConstantArithmeticWire::GetCircuitType
CircuitType GetCircuitType() const final
Definition: constant_wire.h:52
bit_vector.h
encrypto::motion::proto::ConstantArithmeticWire::ConstantArithmeticWire
ConstantArithmeticWire(Backend &backend, std::size_t number_of_simd)
Definition: constant_wire.h:37
encrypto::motion::proto::ConstantArithmeticWire::IsConstant
bool IsConstant() const noexcept final
Definition: constant_wire.h:60
wire.h
encrypto::motion::proto::ConstantBooleanWire::GetProtocol
MpcProtocol GetProtocol() const final
Definition: constant_wire.h:81
encrypto::motion::proto::ConstantBooleanWire::GetValues
const BitVector & GetValues() const
Definition: constant_wire.h:89
encrypto::motion::MpcProtocol::kBooleanConstant
@ kBooleanConstant
encrypto::motion::BitVector<>
encrypto::motion::CircuitType::kArithmetic
@ kArithmetic
constant_wire.h
encrypto::motion::Backend
Definition: backend.h:88
encrypto::motion::proto::ConstantArithmeticWire::GetMutableValues
std::vector< T > & GetMutableValues()
Definition: constant_wire.h:56
encrypto::motion::proto::ConstantArithmeticWire::ConstantArithmeticWire
ConstantArithmeticWire(const std::vector< T > &values, Backend &backend)
Definition: constant_wire.h:43
encrypto::motion::proto::ConstantBooleanWire::GetMutableValues
BitVector & GetMutableValues()
Definition: constant_wire.h:91
encrypto::motion::proto::ConstantBooleanWire::~ConstantBooleanWire
~ConstantBooleanWire() final=default
encrypto::motion::proto::ConstantArithmeticWire::GetProtocol
MpcProtocol GetProtocol() const final
Definition: constant_wire.h:50
encrypto::motion::proto::ConstantBooleanWire
Definition: constant_wire.h:69
encrypto::motion::proto::ConstantArithmeticWire::GetValues
const std::vector< T > & GetValues() const
Definition: constant_wire.h:54
encrypto::motion::MpcProtocol
MpcProtocol
Definition: typedefs.h:140
encrypto::motion::proto::ConstantArithmeticWire::ConstantArithmeticWire
ConstantArithmeticWire(std::vector< T > &&values, Backend &backend)
Definition: constant_wire.h:40
encrypto::motion::proto::ConstantArithmeticWire::value_type
T value_type
Definition: constant_wire.h:35
encrypto::motion::Wire
Definition: wire.h:45
encrypto::motion::proto::ConstantBooleanWire::GetBitLength
std::size_t GetBitLength() const final
Definition: constant_wire.h:87
encrypto::motion::BitVector::Append
void Append(bool bit) noexcept
Appends a bit to BitVector.
Definition: bit_vector.cpp:621
encrypto::motion::proto::ConstantArithmeticWirePointer
std::shared_ptr< ConstantArithmeticWire< T > > ConstantArithmeticWirePointer
Definition: constant_wire.h:67
encrypto::motion::proto::ConstantArithmeticWire::ConstantArithmeticWire
ConstantArithmeticWire(T t, Backend &backend)
Definition: constant_wire.h:46
encrypto::motion::proto::ConstantBooleanWire::ConstantBooleanWire
ConstantBooleanWire()=delete
geninput.default
default
Definition: geninput.py:149
encrypto::motion::proto::ConstantArithmeticWire
Definition: constant_wire.h:33