MOTION  0.01
Framework for mixed-protocol multi-party computation
typedefs.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 <fmt/format.h>
28 
29 #include <cstdint>
30 #include <stdexcept>
31 #include <string>
32 #include <tuple>
33 #include <type_traits>
34 
35 namespace encrypto::motion {
36 
37 enum class PrimitiveOperationType : std::uint8_t {
38  kIn,
39  kOut,
40  kXor, // for Boolean circuit only
41  kAnd, // for Boolean circuit only
42  kMux, // for Boolean circuit only
43  kInv, // for Boolean circuit only
44  kOr, // for Boolean circuit only
45  kAdd, // for arithmetic circuit only
46  kMul, // for arithmetic circuit only
47  kSqr, // for arithmetic circuit only
48  // conversions
49  kA2B, // for arithmetic GMW only
50  kA2Y, // for arithmetic GMW only
51  kB2A, // for GMW only
52  kB2Y, // for GMW only
53  kY2A, // for BMR only
54  kY2B, // for BMR only
55  kInvalid
56 };
57 
58 inline std::string to_string(PrimitiveOperationType t) {
59  switch (t) {
61  return "XOR";
62  }
64  return "AND";
65  }
67  return "MUX";
68  }
70  return "INV";
71  }
73  return "OR";
74  }
76  return "ADD";
77  }
79  return "MUL";
80  }
82  return "SQR";
83  }
85  return "IN";
86  }
88  return "OUT";
89  }
91  return "A2B";
92  }
94  return "A2Y";
95  }
97  return "B2A";
98  }
100  return "B2Y";
101  }
103  return "Y2A";
104  }
106  return "Y2B";
107  }
108  default:
109  throw std::invalid_argument("Invalid PrimitiveOperationType");
110  }
111 }
112 
113 enum class IntegerOperationType : unsigned int { kAdd, kDiv, kGt, kEq, kMul, kSub, kInvalid };
114 
115 inline std::string to_string(IntegerOperationType p) {
116  switch (p) {
118  return "INT_ADD";
119  }
121  return "INT_DIV";
122  }
124  return "INT_GT";
125  }
127  return "INT_EQ";
128  }
130  return "INT_MUL";
131  }
133  return "INT_SUB";
134  }
135  default:
136  throw std::invalid_argument("Invalid IntegerOperationType");
137  }
138 }
139 
140 enum class MpcProtocol : unsigned int {
142  kBooleanGmw,
143  kBmr,
146  kInvalid // for checking whether the value is valid
147 };
148 
149 inline std::string to_string(MpcProtocol p) {
150  switch (p) {
152  return "ArithmeticGMW";
153  }
155  return "BooleanGMW";
156  }
157  case MpcProtocol::kBmr: {
158  return "BMR";
159  }
160  default:
161  return fmt::format("InvalidProtocol with value {}", static_cast<int>(p));
162  }
163 }
164 
165 enum class CircuitType : unsigned int {
166  kArithmetic,
167  kBoolean,
168  kInvalid // for checking whether the value is valid
169 };
170 
171 enum class Role : unsigned int {
172  kServer,
173  kClient,
174  kInvalid // for checking whether the value is valid
175 };
176 
177 enum class GateType : unsigned int {
178  kInput = 0,
179  kInteractive = 1,
180  kNonInteractive = 2,
181  kInvalid = 3
182 };
183 
184 } // namespace encrypto::motion
encrypto::motion::PrimitiveOperationType::kIn
@ kIn
encrypto::motion::PrimitiveOperationType::kOr
@ kOr
encrypto::motion::PrimitiveOperationType::kMux
@ kMux
encrypto::motion::IntegerOperationType::kInvalid
@ kInvalid
encrypto::motion::Role
Role
Definition: typedefs.h:171
encrypto::motion::MpcProtocol::kArithmeticConstant
@ kArithmeticConstant
encrypto::motion::PrimitiveOperationType::kA2B
@ kA2B
encrypto::motion::CircuitType
CircuitType
Definition: typedefs.h:165
encrypto::motion::IntegerOperationType::kEq
@ kEq
encrypto::motion::PrimitiveOperationType::kB2A
@ kB2A
encrypto::motion::IntegerOperationType::kGt
@ kGt
encrypto::motion::IntegerOperationType::kMul
@ kMul
encrypto::motion::MpcProtocol::kBmr
@ kBmr
encrypto::motion::Role::kInvalid
@ kInvalid
encrypto::motion::GateType::kInput
@ kInput
encrypto::motion::PrimitiveOperationType::kInv
@ kInv
encrypto::motion::PrimitiveOperationType::kXor
@ kXor
encrypto::motion::PrimitiveOperationType::kAnd
@ kAnd
encrypto::motion::IntegerOperationType::kDiv
@ kDiv
encrypto::motion::MpcProtocol::kBooleanConstant
@ kBooleanConstant
encrypto::motion::IntegerOperationType
IntegerOperationType
Definition: typedefs.h:113
encrypto::motion::GateType::kNonInteractive
@ kNonInteractive
encrypto::motion::Role::kClient
@ kClient
encrypto::motion::CircuitType::kArithmetic
@ kArithmetic
encrypto::motion::MpcProtocol::kBooleanGmw
@ kBooleanGmw
encrypto::motion::PrimitiveOperationType::kY2A
@ kY2A
encrypto::motion::CircuitType::kInvalid
@ kInvalid
encrypto::motion::Role::kServer
@ kServer
encrypto::motion::PrimitiveOperationType::kAdd
@ kAdd
encrypto::motion::PrimitiveOperationType::kSqr
@ kSqr
encrypto::motion
Definition: algorithm_description.cpp:35
encrypto::motion::PrimitiveOperationType
PrimitiveOperationType
Definition: typedefs.h:37
encrypto::motion::MpcProtocol::kInvalid
@ kInvalid
encrypto::motion::PrimitiveOperationType::kInvalid
@ kInvalid
encrypto::motion::GateType::kInvalid
@ kInvalid
encrypto::motion::IntegerOperationType::kAdd
@ kAdd
encrypto::motion::IntegerOperationType::kSub
@ kSub
encrypto::motion::MpcProtocol
MpcProtocol
Definition: typedefs.h:140
encrypto::motion::PrimitiveOperationType::kMul
@ kMul
encrypto::motion::PrimitiveOperationType::kA2Y
@ kA2Y
encrypto::motion::MpcProtocol::kArithmeticGmw
@ kArithmeticGmw
encrypto::motion::PrimitiveOperationType::kB2Y
@ kB2Y
encrypto::motion::PrimitiveOperationType::kOut
@ kOut
encrypto::motion::GateType::kInteractive
@ kInteractive
encrypto::motion::to_string
std::string to_string(std::vector< T > values)
Returns a string representation of the std::vector values.
Definition: helpers.h:455
encrypto::motion::GateType
GateType
Definition: typedefs.h:177
encrypto::motion::PrimitiveOperationType::kY2B
@ kY2B
encrypto::motion::CircuitType::kBoolean
@ kBoolean