MOTION  0.01
Framework for mixed-protocol multi-party computation
arithmetic_gmw_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 
30 
31 // Allow only unsigned integers for Arithmetic wires.
32 template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
33 class Wire final : public motion::Wire {
34  using Base = motion::Wire;
35 
36  public:
37  using value_type = T;
38 
39  Wire(Backend& backend, std::size_t number_of_simd) : Base(backend, number_of_simd) {}
40 
41  Wire(std::vector<T>&& values, Backend& backend)
42  : Base(backend, values.size()), values_(std::move(values)) {}
43 
44  Wire(const std::vector<T>& values, Backend& backend)
45  : Base(backend, values.size()), values_(values) {}
46 
47  Wire(T t, Backend& backend) : Base(backend, 1), values_({t}) {}
48 
49  ~Wire() final = default;
50 
52 
54 
55  const std::vector<T>& GetValues() const { return values_; }
56 
57  std::vector<T>& GetMutableValues() { return values_; }
58 
59  std::size_t GetBitLength() const final { return sizeof(T) * 8; }
60 
61  bool IsConstant() const noexcept final { return false; }
62 
63  private:
64  std::vector<T> values_;
65 };
66 
67 template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
68 using WirePointer = std::shared_ptr<Wire<T>>;
69 
70 } // namespace encrypto::motion::proto::arithmetic_gmw
encrypto::motion::proto::arithmetic_gmw::Wire::IsConstant
bool IsConstant() const noexcept final
Definition: arithmetic_gmw_wire.h:61
encrypto::motion::CircuitType
CircuitType
Definition: typedefs.h:165
wire.h
encrypto::motion::proto::arithmetic_gmw::Wire::GetProtocol
MpcProtocol GetProtocol() const final
Definition: arithmetic_gmw_wire.h:51
encrypto::motion::CircuitType::kArithmetic
@ kArithmetic
encrypto::motion::proto::arithmetic_gmw::Wire::GetValues
const std::vector< T > & GetValues() const
Definition: arithmetic_gmw_wire.h:55
encrypto::motion::Backend
Definition: backend.h:88
encrypto::motion::proto::arithmetic_gmw::Wire::Wire
Wire(std::vector< T > &&values, Backend &backend)
Definition: arithmetic_gmw_wire.h:41
encrypto::motion::proto::arithmetic_gmw::Wire::Wire
Wire(Backend &backend, std::size_t number_of_simd)
Definition: arithmetic_gmw_wire.h:39
encrypto::motion::proto::arithmetic_gmw::Wire::~Wire
~Wire() final=default
encrypto::motion::MpcProtocol
MpcProtocol
Definition: typedefs.h:140
encrypto::motion::proto::arithmetic_gmw::Wire::GetBitLength
std::size_t GetBitLength() const final
Definition: arithmetic_gmw_wire.h:59
encrypto::motion::Wire
Definition: wire.h:45
encrypto::motion::proto::arithmetic_gmw::Wire::GetMutableValues
std::vector< T > & GetMutableValues()
Definition: arithmetic_gmw_wire.h:57
encrypto::motion::MpcProtocol::kArithmeticGmw
@ kArithmeticGmw
encrypto::motion::proto::arithmetic_gmw::Wire::Wire
Wire(const std::vector< T > &values, Backend &backend)
Definition: arithmetic_gmw_wire.h:44
geninput.default
default
Definition: geninput.py:149
encrypto::motion::proto::arithmetic_gmw
Definition: arithmetic_gmw_gate.h:45
encrypto::motion::proto::arithmetic_gmw::Wire
Definition: arithmetic_gmw_wire.h:33
encrypto::motion::proto::arithmetic_gmw::WirePointer
std::shared_ptr< Wire< T > > WirePointer
Definition: arithmetic_gmw_wire.h:68
encrypto::motion::proto::arithmetic_gmw::Wire::value_type
T value_type
Definition: arithmetic_gmw_wire.h:37
encrypto::motion::proto::arithmetic_gmw::Wire::Wire
Wire(T t, Backend &backend)
Definition: arithmetic_gmw_wire.h:47
encrypto::motion::proto::arithmetic_gmw::Wire::GetCircuitType
CircuitType GetCircuitType() const final
Definition: arithmetic_gmw_wire.h:53