-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
1,375 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* MaliciousShamirMC.h | ||
* | ||
*/ | ||
|
||
#ifndef AUTH_MALICIOUSSHAMIRMC_H_ | ||
#define AUTH_MALICIOUSSHAMIRMC_H_ | ||
|
||
#include "ShamirMC.h" | ||
|
||
template<class T> | ||
class MaliciousShamirMC : public ShamirMC<T> | ||
{ | ||
vector<vector<typename T::clear>> reconstructions; | ||
|
||
public: | ||
MaliciousShamirMC(); | ||
|
||
// emulate MAC_Check | ||
MaliciousShamirMC(const typename T::value_type& _, int __ = 0, int ___ = 0) : | ||
MaliciousShamirMC() | ||
{ (void)_; (void)__; (void)___; } | ||
|
||
// emulate Direct_MAC_Check | ||
MaliciousShamirMC(const typename T::value_type& _, Names& ____, int __ = 0, | ||
int ___ = 0) : | ||
MaliciousShamirMC() | ||
{ (void)_; (void)__; (void)___; (void)____; } | ||
|
||
|
||
void POpen_End(vector<typename T::clear>& values, const vector<T>& S, | ||
const Player& P); | ||
}; | ||
|
||
#endif /* AUTH_MALICIOUSSHAMIRMC_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* MaliciousShamirMC.cpp | ||
* | ||
*/ | ||
|
||
#include "MaliciousShamirMC.h" | ||
#include "Processor/ShamirMachine.h" | ||
|
||
template<class T> | ||
MaliciousShamirMC<T>::MaliciousShamirMC() | ||
{ | ||
this->threshold = 2 * ShamirMachine::s().threshold; | ||
} | ||
|
||
template<class T> | ||
void MaliciousShamirMC<T>::POpen_End(vector<typename T::clear>& values, | ||
const vector<T>& S, const Player& P) | ||
{ | ||
(void) P; | ||
int threshold = ShamirMachine::s().threshold; | ||
if (reconstructions.empty()) | ||
{ | ||
reconstructions.resize(2 * threshold + 2); | ||
for (int i = threshold + 1; i <= 2 * threshold + 1; i++) | ||
{ | ||
reconstructions[i].resize(i); | ||
for (int j = 0; j < i; j++) | ||
reconstructions[i][j] = Shamir<T>::get_rec_factor(j, i); | ||
} | ||
} | ||
|
||
values.clear(); | ||
values.resize(S.size()); | ||
vector<T> shares(2 * threshold + 1); | ||
for (size_t i = 0; i < values.size(); i++) | ||
{ | ||
for (size_t j = 0; j < shares.size(); j++) | ||
shares[j].unpack(this->os[j]); | ||
T value = 0; | ||
for (int j = 0; j < threshold + 1; j++) | ||
value += shares[j] * reconstructions[threshold + 1][j]; | ||
for (int j = threshold + 2; j <= 2 * threshold + 1; j++) | ||
{ | ||
T check = 0; | ||
for (int k = 0; k < j; k++) | ||
check += shares[k] * reconstructions[j][k]; | ||
if (check != value) | ||
throw mac_fail(); | ||
} | ||
values[i] = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* ShamirMC.h | ||
* | ||
*/ | ||
|
||
#ifndef AUTH_SHAMIRMC_H_ | ||
#define AUTH_SHAMIRMC_H_ | ||
|
||
#include "MAC_Check.h" | ||
#include "Math/ShamirShare.h" | ||
#include "Processor/ShamirMachine.h" | ||
|
||
template<class T> | ||
class ShamirMC : public MAC_Check_Base<T> | ||
{ | ||
vector<typename T::clear> reconstruction; | ||
|
||
protected: | ||
vector<octetStream> os; | ||
int threshold; | ||
|
||
public: | ||
ShamirMC() : threshold(ShamirMachine::s().threshold) {} | ||
|
||
// emulate MAC_Check | ||
ShamirMC(const typename T::value_type& _, int __ = 0, int ___ = 0) : ShamirMC() | ||
{ (void)_; (void)__; (void)___; } | ||
|
||
// emulate Direct_MAC_Check | ||
ShamirMC(const typename T::value_type& _, Names& ____, int __ = 0, int ___ = 0) : | ||
ShamirMC() | ||
{ (void)_; (void)__; (void)___; (void)____; } | ||
|
||
void POpen_Begin(vector<typename T::clear>& values,const vector<T>& S,const Player& P); | ||
void POpen_End(vector<typename T::clear>& values,const vector<T>& S,const Player& P); | ||
|
||
void Check(const Player& P) { (void)P; } | ||
}; | ||
|
||
#endif /* AUTH_SHAMIRMC_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* ShamirMC.cpp | ||
* | ||
*/ | ||
|
||
#include "ShamirMC.h" | ||
|
||
template<class T> | ||
void ShamirMC<T>::POpen_Begin(vector<typename T::clear>& values, | ||
const vector<T>& S, const Player& P) | ||
{ | ||
(void) values; | ||
os.clear(); | ||
os.resize(P.num_players()); | ||
if (P.my_num() <= threshold) | ||
{ | ||
for (auto& share : S) | ||
share.pack(os[P.my_num()]); | ||
for (int i = 0; i < P.num_players(); i++) | ||
if (i != P.my_num()) | ||
P.send_to(i, os[P.my_num()], true); | ||
} | ||
for (int i = 0; i <= threshold; i++) | ||
if (i != P.my_num()) | ||
P.receive_player(i, os[i], true); | ||
} | ||
|
||
template<class T> | ||
void ShamirMC<T>::POpen_End(vector<typename T::clear>& values, | ||
const vector<T>& S, const Player& P) | ||
{ | ||
(void) P; | ||
int n_relevant_players = ShamirMachine::s().threshold + 1; | ||
if (reconstruction.empty()) | ||
{ | ||
reconstruction.resize(n_relevant_players, 1); | ||
for (int i = 0; i < n_relevant_players; i++) | ||
reconstruction[i] = Shamir<typename T::clear>::get_rec_factor(i, | ||
n_relevant_players); | ||
} | ||
|
||
values.clear(); | ||
values.resize(S.size()); | ||
for (size_t i = 0; i < values.size(); i++) | ||
for (int j = 0; j < n_relevant_players; j++) | ||
values[i] += os[j].template get<typename T::clear>() * reconstruction[j]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.