MOTION  0.01
Framework for mixed-protocol multi-party computation
ot_hl17.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Oleksandr Tkachenko
4 // Copyright (c) 2018 Lennart Braun
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 
24 #pragma once
25 
26 #include "ot.h"
27 
28 #include <flatbuffers/flatbuffers.h>
29 
30 #include <functional>
31 #include <memory>
32 
34 
35 namespace encrypto::motion {
36 
37 struct BaseOtData;
38 
43 class OtHL17 final : public RandomOt {
44  public:
45  OtHL17(std::function<void(flatbuffers::FlatBufferBuilder&&)> send, BaseOtData& data_storage);
46 
50  // std::pair<std::vector<std::byte>, std::vector<std::byte>> send() override;
51  // std::vector<std::byte> recv(bool) override;
52 
56  std::vector<std::pair<std::vector<std::byte>, std::vector<std::byte>>> Send(size_t) override;
57  std::vector<std::vector<std::byte>> Receive(const BitVector<>&) override;
62  // std::vector<std::pair<std::vector<std::byte>, std::vector<std::byte>>> parallel_send(
63  // size_t, size_t number_threads) override;
64  // std::vector<std::vector<std::byte>> parallel_recv(const std::vector<bool>&,
65  // size_t number_threads) override;
66 
67  private:
68  std::function<void(flatbuffers::FlatBufferBuilder&&)> send_function_;
69 
70  BaseOtData& base_ots_data_;
71 
72  // public: // for testing
73  struct SenderState {
74  SenderState(std::size_t ot_id) : i(ot_id) {}
75  // i-th OT
76  const std::size_t i;
77  // y
78  uint8_t y[32];
79  // // S
80  curve25519::ge_p3 S;
81  // // T
82  curve25519::ge_p3 T;
83  // // R
84  curve25519::ge_p3 R;
85  };
86 
87  struct ReceiverState {
88  ReceiverState(std::size_t ot_id) : i(ot_id) {}
89 
90  // i-th OT
91  const std::size_t i;
92 
93  bool choice;
94  // x
95  uint8_t x[32];
96  // S
97  curve25519::ge_p3 S;
98  // T
99  curve25519::ge_p3 T;
100  // R
101  curve25519::ge_p3 R;
102  // k_R
103  // e_c
104  };
105 
106  static constexpr size_t kCurve25519GeByteSize = 32;
107 
111  void Send0(SenderState& state, std::array<std::byte, kCurve25519GeByteSize>& message_output);
112  void Send1(SenderState& state);
113  std::pair<std::vector<std::byte>, std::vector<std::byte>> Send2(
114  SenderState& state, const std::array<std::byte, kCurve25519GeByteSize>& message_input);
115 
119  void Receive0(ReceiverState& state, bool choice);
120  void Receive1(ReceiverState& state, std::array<std::byte, kCurve25519GeByteSize>& message_output,
121  const std::array<std::byte, kCurve25519GeByteSize>& message_input);
122  std::vector<std::byte> Receive2(ReceiverState& state);
123 };
124 
125 } // namespace encrypto::motion
encrypto::motion::curve25519::x25519_ge_p3_to_cached
void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p)
Definition: mycurve25519.cpp:3846
encrypto::motion::BaseOtData
Definition: base_ot_data.h:77
helpers.h
encrypto::motion::curve25519::x25519_ge_p1p1_to_p3
void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p)
Definition: mycurve25519.cpp:3861
encrypto::motion::curve25519::x25519_ge_scalarmult
void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A)
Definition: mycurve25519.cpp:4143
encrypto::motion::HashPoint
void HashPoint(curve25519::ge_p3 &output, const curve25519::ge_p3 &input)
Definition: ot_hl17.cpp:50
encrypto::motion::OtHL17
Definition: ot_hl17.h:43
encrypto::motion::OtHL17::Send
std::vector< std::pair< std::vector< std::byte >, std::vector< std::byte > > > Send(size_t) override
Definition: ot_hl17.cpp:195
encrypto::motion::NewBlakeCtx
Blake2bCtx NewBlakeCtx()
Definition: blake2b.cpp:28
encrypto::motion::curve25519::x25519_ge_frombytes_vartime
int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s)
Definition: mycurve25519.cpp:3766
blake2b.h
backend.h
encrypto::motion::curve25519::x25519_ge_scalarmult_base
void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t *a)
Definition: mycurve25519.cpp:4084
encrypto::motion::BitVector<>
encrypto::motion::curve25519::x25519_sc_reduce
void x25519_sc_reduce(uint8_t s[64])
Definition: mycurve25519.cpp:4312
geninput.choices
choices
Definition: geninput.py:153
base_ot_data.h
encrypto::motion::curve25519::x25519_ge_tobytes
void x25519_ge_tobytes(uint8_t s[32], const ge_p2 *h)
Definition: mycurve25519.cpp:3742
ot.h
encrypto::motion
Definition: algorithm_description.cpp:35
x25519_ge_frombytes_vartime
int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s)
Definition: mycurve25519.cpp:3766
encrypto::motion::Blake2b
void Blake2b(std::uint8_t *message, std::uint8_t digest[64], std::size_t length, EVP_MD_CTX *context)
Definition: blake2b.cpp:32
encrypto::motion::OtHL17::OtHL17
OtHL17(std::function< void(flatbuffers::FlatBufferBuilder &&)> send, BaseOtData &data_storage)
Definition: ot_hl17.cpp:38
encrypto::motion::OtHL17::Receive
std::vector< std::vector< std::byte > > Receive(const BitVector<> &) override
Definition: ot_hl17.cpp:227
encrypto::motion::curve25519::sc_random
void sc_random(uint8_t s[32])
Definition: mycurve25519.cpp:5238
encrypto::motion::RandomOt
Definition: base_ots/ot.h:39
encrypto::motion::curve25519::x25519_ge_sub
void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q)
Definition: mycurve25519.cpp:3954
encrypto::motion::curve25519::x25519_ge_add
void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q)
Definition: mycurve25519.cpp:3936
ot_hl17.h
base_ot_message.h
encrypto::motion::communication::BuildBaseROtMessageSender
flatbuffers::FlatBufferBuilder BuildBaseROtMessageSender(std::byte *buffer, std::size_t size, std::size_t ot_id)
Definition: base_ot_message.cpp:43
encrypto::motion::BaseOtData::GetSenderData
BaseOtSenderData & GetSenderData()
Definition: base_ot_data.h:83
encrypto::motion::communication::BuildBaseROtMessageReceiver
flatbuffers::FlatBufferBuilder BuildBaseROtMessageReceiver(std::byte *buffer, std::size_t size, std::size_t ot_id)
Definition: base_ot_message.cpp:32
encrypto::motion::BaseOtData::GetReceiverData
BaseOtReceiverData & GetReceiverData()
Definition: base_ot_data.h:81
mycurve25519.h
encrypto::motion::curve25519::ge_p3_tobytes
void ge_p3_tobytes(uint8_t s[32], const ge_p3 *h)
Definition: mycurve25519.cpp:3754