MOTION  0.01
Framework for mixed-protocol multi-party computation
bmr_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 #include "utility/block.h"
31 
33 
34 class Wire final : public BooleanWire {
35  public:
36  Wire(Backend& backend, std::size_t number_of_simd);
37 
38  explicit Wire(BitVector<>&& values, Backend& backend);
39 
40  explicit Wire(const BitVector<>& values, Backend& backend);
41 
42  explicit Wire(bool value, Backend& backend);
43 
44  ~Wire() final = default;
45 
46  MpcProtocol GetProtocol() const final { return MpcProtocol::kBmr; }
47 
48  Wire() = delete;
49 
50  Wire(Wire&) = delete;
51 
52  std::size_t GetBitLength() const final { return 1; }
53 
54  const BitVector<>& GetPublicValues() const { return public_values_; }
55 
56  BitVector<>& GetMutablePublicValues() { return public_values_; }
57 
58  const BitVector<>& GetPermutationBits() const { return shared_permutation_bits_; }
59 
60  BitVector<>& GetMutablePermutationBits() { return shared_permutation_bits_; }
61 
62  const auto& GetSecretKeys() const { return secret_0_keys_; }
63 
64  auto& GetMutableSecretKeys() { return secret_0_keys_; }
65 
66  const auto& GetPublicKeys() const { return public_keys_; }
67 
68  auto& GetMutablePublicKeys() { return public_keys_; }
69 
71 
73 
74  void SetSetupIsReady() {
75  {
76  std::scoped_lock lock(setup_ready_cond_->GetMutex());
77  setup_ready_ = true;
78  }
79  setup_ready_cond_->NotifyAll();
80  }
81 
82  const auto& GetSetupReadyCondition() const { return setup_ready_cond_; }
83 
84  bool IsConstant() const noexcept final { return false; }
85 
86  protected:
87  void DynamicClear() final { setup_ready_ = false; }
88 
89  private:
90  void InitializationHelperBmr();
91 
92  // Store the cleartext values in public_values_ if this wire is an output wire.
93  BitVector<> public_values_;
94  BitVector<> shared_permutation_bits_;
95 
96  // Store one of the secret keys since we have the global offset for free XOR.
97  // Structure for n simd values: (k_1 || k_2 || ... || k_n).
98  Block128Vector secret_0_keys_;
99 
100  // Buffer for the super keys corresponding to each simd value.
101  // Structure for n simd values and m parties: (K_1 || K_2 || ... || K_n), where K is constructed
102  // by concatenating each of m parties' public keys, i.e., K = (k_1 || k_2 || ... || k_m).
103  Block128Vector public_keys_;
104 
105  std::atomic<bool> setup_ready_{false};
106  std::unique_ptr<FiberCondition> setup_ready_cond_;
107 };
108 
109 using WirePointer = std::shared_ptr<Wire>;
110 
111 } // namespace encrypto::motion::proto::bmr
encrypto::motion::Block128Vector::resize
void resize(std::size_t new_size)
Resize the Block128Vector to contain new_size elements. New elements are left uninitialized.
Definition: block.h:233
encrypto::motion::proto::bmr::Wire::GetProtocol
MpcProtocol GetProtocol() const final
Definition: bmr_wire.h:46
encrypto::motion::proto::bmr::Wire::GenerateRandomPrivateKeys
void GenerateRandomPrivateKeys()
Definition: bmr_wire.cpp:63
encrypto::motion::Wire::n_simd_
std::size_t n_simd_
Number of values that are logically processed in parallel.
Definition: wire.h:86
encrypto::motion::Wire::backend_
Backend & backend_
Definition: wire.h:83
encrypto::motion::proto::bmr::Wire::GetBitLength
std::size_t GetBitLength() const final
Definition: bmr_wire.h:52
encrypto::motion::BitVector::SecureRandom
static BitVector SecureRandom(const std::size_t size) noexcept
Returns a random BitVector.
Definition: bit_vector.cpp:893
fiber_condition.h
encrypto::motion::BooleanWire
Definition: wire.h:112
encrypto::motion::MpcProtocol::kBmr
@ kBmr
encrypto::motion::proto::bmr::Wire::GetPublicKeys
const auto & GetPublicKeys() const
Definition: bmr_wire.h:66
encrypto::motion::proto::bmr::WirePointer
std::shared_ptr< Wire > WirePointer
Definition: bmr_wire.h:109
bit_vector.h
bmr_wire.h
wire.h
backend.h
encrypto::motion::Block128Vector::SetToRandom
void SetToRandom()
Set all Block128 in this vector to random values.
Definition: block.cpp:47
encrypto::motion::proto::bmr::Wire::GetMutablePublicValues
BitVector & GetMutablePublicValues()
Definition: bmr_wire.h:56
encrypto::motion::Block128Vector
Vector of 128 bit / 16 B blocks.
Definition: block.h:168
block.h
encrypto::motion::BitVector<>
encrypto::motion::proto::bmr::Wire::GetMutableSecretKeys
auto & GetMutableSecretKeys()
Definition: bmr_wire.h:64
encrypto::motion::proto::bmr::Wire::DynamicClear
void DynamicClear() final
Definition: bmr_wire.h:87
encrypto::motion::proto::bmr::Wire::GetMutablePermutationBits
BitVector & GetMutablePermutationBits()
Definition: bmr_wire.h:60
encrypto::motion::proto::bmr::Wire::GetMutablePublicKeys
auto & GetMutablePublicKeys()
Definition: bmr_wire.h:68
encrypto::motion::Backend
Definition: backend.h:88
encrypto::motion::proto::bmr
Definition: backend.h:50
encrypto::motion::communication::CommunicationLayer::GetNumberOfParties
std::size_t GetNumberOfParties() const
Definition: communication_layer.h:65
encrypto::motion::proto::bmr::Wire::SetSetupIsReady
void SetSetupIsReady()
Definition: bmr_wire.h:74
encrypto::motion::proto::bmr::Wire::GenerateRandomPermutationBits
void GenerateRandomPermutationBits()
Definition: bmr_wire.cpp:65
encrypto::motion::proto::bmr::Wire
Definition: bmr_wire.h:34
encrypto::motion::proto::bmr::Wire::~Wire
~Wire() final=default
encrypto::motion::proto::bmr::Wire::GetPublicValues
const BitVector & GetPublicValues() const
Definition: bmr_wire.h:54
encrypto::motion::proto::bmr::Wire::IsConstant
bool IsConstant() const noexcept final
Definition: bmr_wire.h:84
encrypto::motion::proto::bmr::Wire::GetPermutationBits
const BitVector & GetPermutationBits() const
Definition: bmr_wire.h:58
encrypto::motion::MpcProtocol
MpcProtocol
Definition: typedefs.h:140
encrypto::motion::Backend::GetCommunicationLayer
communication::CommunicationLayer & GetCommunicationLayer()
Definition: backend.h:289
encrypto::motion::proto::bmr::Wire::Wire
Wire()=delete
encrypto::motion::proto::bmr::Wire::GetSecretKeys
const auto & GetSecretKeys() const
Definition: bmr_wire.h:62
encrypto::motion::proto::bmr::Wire::GetSetupReadyCondition
const auto & GetSetupReadyCondition() const
Definition: bmr_wire.h:82