MOTION  0.01
Framework for mixed-protocol multi-party computation
secure_unsigned_integer.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2021 Oleksandr Tkachenko, Arianne Roselina Prananto
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 
28 
29 namespace encrypto::motion {
30 
31 class Logger;
32 
34  public:
35  SecureUnsignedInteger() = default;
36 
38  : SecureUnsignedInteger(*other.share_) {}
39 
41  : SecureUnsignedInteger(std::move(*other.share_)) {
42  other.share_->Get().reset();
43  }
44 
46 
48  other.Get().reset();
49  }
50 
51  SecureUnsignedInteger(const SharePointer& other);
52 
54 
56  this->share_ = other.share_;
57  this->logger_ = other.logger_;
58  return *this;
59  }
60 
62  this->share_ = std::move(other.share_);
63  this->logger_ = std::move(other.logger_);
64  return *this;
65  }
66 
67  ShareWrapper& Get() { return *share_; }
68 
69  const ShareWrapper& Get() const { return *share_; }
70 
71  ShareWrapper& operator->() { return *share_; }
72 
73  const ShareWrapper& operator->() const { return *share_; }
74 
76 
78  *this = *this + other;
79  return *this;
80  }
81 
83 
85  *this = *this - other;
86  return *this;
87  }
88 
90 
92  *this = *this * other;
93  return *this;
94  }
95 
97 
99  *this = *this / other;
100  return *this;
101  }
102 
103  ShareWrapper operator>(const SecureUnsignedInteger& other) const;
104 
105  ShareWrapper operator==(const SecureUnsignedInteger& other) const;
106 
109  std::vector<SecureUnsignedInteger> Unsimdify() const;
110 
115  std::size_t output_owner = std::numeric_limits<std::int64_t>::max()) const;
116 
119  template <typename T>
120  T As() const;
121 
122  private:
123  std::shared_ptr<ShareWrapper> share_{nullptr};
124  std::shared_ptr<Logger> logger_{nullptr};
125 
126  std::string ConstructPath(const IntegerOperationType type, const std::size_t bitlength,
127  std::string suffix = "") const;
128 };
129 
130 } // namespace encrypto::motion
encrypto::motion::ShareWrapper
Definition: share_wrapper.h:44
encrypto::motion::SecureUnsignedInteger::operator->
ShareWrapper & operator->()
Definition: secure_unsigned_integer.h:71
encrypto::motion::SecureUnsignedInteger::operator-=
SecureUnsignedInteger & operator-=(const SecureUnsignedInteger &other)
Definition: secure_unsigned_integer.h:84
encrypto::motion::SecureUnsignedInteger::SecureUnsignedInteger
SecureUnsignedInteger(const SecureUnsignedInteger &other)
Definition: secure_unsigned_integer.h:37
unsimdify_gate.h
encrypto::motion::IntegerOperationType::kEq
@ kEq
encrypto::motion::IntegerOperationType::kGt
@ kGt
encrypto::motion::IntegerOperationType::kMul
@ kMul
encrypto::motion::MpcProtocol::kBmr
@ kBmr
encrypto::motion::SecureUnsignedInteger::SecureUnsignedInteger
SecureUnsignedInteger(const ShareWrapper &other)
Definition: secure_unsigned_integer.h:45
geninput.type
type
Definition: geninput.py:149
algorithm_description.h
encrypto::motion::SecureUnsignedInteger::operator>
ShareWrapper operator>(const SecureUnsignedInteger &other) const
Definition: secure_unsigned_integer.cpp:176
backend.h
encrypto::motion::SecureUnsignedInteger::operator*=
SecureUnsignedInteger & operator*=(const SecureUnsignedInteger &other)
Definition: secure_unsigned_integer.h:91
encrypto::motion::ShareWrapper::Split
std::vector< ShareWrapper > Split() const
splits the share into single wires.
Definition: share_wrapper.cpp:459
encrypto::motion::IntegerOperationType::kDiv
@ kDiv
encrypto::motion::IntegerOperationType
IntegerOperationType
Definition: typedefs.h:113
encrypto::motion::SecureUnsignedInteger::operator->
const ShareWrapper & operator->() const
Definition: secure_unsigned_integer.h:73
encrypto::motion::ShareWrapper::Concatenate
static ShareWrapper Concatenate(std::vector< ShareWrapper > &&input)
concatenates wires in multiple shares in one share.
Definition: share_wrapper.h:128
encrypto::motion::CircuitType::kArithmetic
@ kArithmetic
encrypto::motion::SecureUnsignedInteger::operator/=
SecureUnsignedInteger & operator/=(const SecureUnsignedInteger &other)
Definition: secure_unsigned_integer.h:98
encrypto::motion::MpcProtocol::kBooleanGmw
@ kBooleanGmw
encrypto::motion::SecureUnsignedInteger::SecureUnsignedInteger
SecureUnsignedInteger()=default
encrypto::motion::SecureUnsignedInteger::operator-
SecureUnsignedInteger operator-(const SecureUnsignedInteger &other) const
Definition: secure_unsigned_integer.cpp:78
encrypto::motion::SecureUnsignedInteger::As
T As() const
converts the information on the wires to T in type Unsigned Integer. See the description in ShareWrap...
Definition: secure_unsigned_integer.cpp:283
encrypto::motion::SecureUnsignedInteger::SecureUnsignedInteger
SecureUnsignedInteger(ShareWrapper &&other)
Definition: secure_unsigned_integer.h:47
encrypto::motion::SecureUnsignedInteger::operator*
SecureUnsignedInteger operator*(const SecureUnsignedInteger &other) const
Definition: secure_unsigned_integer.cpp:111
encrypto::motion::SecureUnsignedInteger::operator+=
SecureUnsignedInteger & operator+=(const SecureUnsignedInteger &other)
Definition: secure_unsigned_integer.h:77
secure_unsigned_integer.h
register.h
encrypto::motion::SecureUnsignedInteger::operator=
SecureUnsignedInteger & operator=(const SecureUnsignedInteger &other)
Definition: secure_unsigned_integer.h:55
logger.h
share_wrapper.h
encrypto::motion
Definition: algorithm_description.cpp:35
encrypto::motion::SharePointer
std::shared_ptr< Share > SharePointer
Definition: conversion_gate.h:49
encrypto::motion::SecureUnsignedInteger::operator==
ShareWrapper operator==(const SecureUnsignedInteger &other) const
Definition: secure_unsigned_integer.cpp:209
encrypto::motion::SecureUnsignedInteger
Definition: secure_unsigned_integer.h:33
encrypto::motion::IntegerOperationType::kAdd
@ kAdd
encrypto::motion::SecureUnsignedInteger::SecureUnsignedInteger
SecureUnsignedInteger(SecureUnsignedInteger &&other)
Definition: secure_unsigned_integer.h:40
encrypto::motion::SecureUnsignedInteger::operator=
SecureUnsignedInteger & operator=(SecureUnsignedInteger &&other)
Definition: secure_unsigned_integer.h:61
encrypto::motion::AlgorithmDescription::FromBristol
static AlgorithmDescription FromBristol(const std::string &path)
Definition: algorithm_description.cpp:37
encrypto::motion::IntegerOperationType::kSub
@ kSub
encrypto::motion::SecureUnsignedInteger::operator+
SecureUnsignedInteger operator+(const SecureUnsignedInteger &other) const
Definition: secure_unsigned_integer.cpp:46
encrypto::motion::SecureUnsignedInteger::Out
SecureUnsignedInteger Out(std::size_t output_owner=std::numeric_limits< std::int64_t >::max()) const
constructs an output gate, which reconstructs the cleartext result. The default parameter for the out...
Definition: secure_unsigned_integer.cpp:272
encrypto::motion::SecureUnsignedInteger::operator/
SecureUnsignedInteger operator/(const SecureUnsignedInteger &other) const
Definition: secure_unsigned_integer.cpp:144
encrypto::motion::is_specialization
Definition: share_wrapper.cpp:610
encrypto::motion::SecureUnsignedInteger::Get
const ShareWrapper & Get() const
Definition: secure_unsigned_integer.h:69
encrypto::motion::kRootDir
constexpr std::string_view kRootDir
Definition: config.h:39
encrypto::motion::MpcProtocol::kArithmeticGmw
@ kArithmeticGmw
encrypto::motion::ShareWrapper::Evaluate
ShareWrapper Evaluate(const std::shared_ptr< const AlgorithmDescription > &algo) const
evaluates AlgorithmDescription also on this->share_ as input.
Definition: share_wrapper.h:144
encrypto::motion::SecureUnsignedInteger::Get
ShareWrapper & Get()
Definition: secure_unsigned_integer.h:67
constants.h
encrypto::motion::kDebug
constexpr bool kDebug
Definition: config.h:36
encrypto::motion::SecureUnsignedInteger::Unsimdify
std::vector< SecureUnsignedInteger > Unsimdify() const
decomposes this->share_->Get() into shares with exactly 1 SIMD value. See the description in ShareWra...
Definition: secure_unsigned_integer.cpp:261
encrypto::motion::CircuitType::kBoolean
@ kBoolean