forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ot-ecdsa-party.hpp
137 lines (126 loc) · 4.6 KB
/
ot-ecdsa-party.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* fake-spdz-ecdsa-party.cpp
*
*/
#include "Networking/Server.h"
#include "Networking/CryptoPlayer.h"
#include "Math/gfp.h"
#include "ECDSA/P256Element.h"
#include "Protocols/SemiShare.h"
#include "Processor/BaseMachine.h"
#include "ECDSA/preprocessing.hpp"
#include "ECDSA/sign.hpp"
#include "Protocols/Beaver.hpp"
#include "Protocols/fake-stuff.hpp"
#include "Protocols/MascotPrep.hpp"
#include "Processor/Processor.hpp"
#include "Processor/Data_Files.hpp"
#include "Processor/Input.hpp"
#include <assert.h>
template<template<class U> class T>
void run(int argc, const char** argv)
{
ez::ezOptionParser opt;
EcdsaOptions opts(opt, argc, argv);
opt.add(
"", // Default.
0, // Required?
0, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Use SimpleOT instead of OT extension", // Help description.
"-S", // Flag token.
"--simple-ot" // Flag token.
);
opt.add(
"", // Default.
0, // Required?
0, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Don't check correlation in OT extension (only relevant with MASCOT)", // Help description.
"-U", // Flag token.
"--unchecked-correlation" // Flag token.
);
opt.add(
"", // Default.
0, // Required?
0, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Fewer rounds for authentication (only relevant with MASCOT)", // Help description.
"-A", // Flag token.
"--auth-fewer-rounds" // Flag token.
);
opt.add(
"", // Default.
0, // Required?
0, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Use Fiat-Shamir for amplification (only relevant with MASCOT)", // Help description.
"-H", // Flag token.
"--fiat-shamir" // Flag token.
);
opt.add(
"", // Default.
0, // Required?
0, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Skip sacrifice (only relevant with MASCOT)", // Help description.
"-E", // Flag token.
"--embrace-life" // Flag token.
);
opt.add(
"", // Default.
0, // Required?
0, // Number of args expected.
0, // Delimiter if expecting multiple args.
"No MACs (only relevant with MASCOT; implies skipping MAC checks)", // Help description.
"-M", // Flag token.
"--no-macs" // Flag token.
);
Names N(opt, argc, argv, 2);
int n_tuples = 1000;
if (not opt.lastArgs.empty())
n_tuples = atoi(opt.lastArgs[0]->c_str());
PlainPlayer P(N);
P256Element::init();
P256Element::Scalar::next::init_field(P256Element::Scalar::pr(), false);
BaseMachine machine;
machine.ot_setups.push_back({P, true});
P256Element::Scalar keyp;
SeededPRNG G;
keyp.randomize(G);
typedef T<P256Element::Scalar> pShare;
DataPositions usage;
OnlineOptions::singleton.batch_size = 1;
typename pShare::Direct_MC MCp(keyp, N, 0);
ArithmeticProcessor _({}, 0);
typename pShare::LivePrep sk_prep(0, usage);
SubProcessor<pShare> sk_proc(_, MCp, sk_prep, P);
pShare sk, __;
// synchronize
Bundle<octetStream> bundle(P);
P.Broadcast_Receive(bundle, false);
Timer timer;
timer.start();
auto stats = P.comm_stats;
sk_prep.get_two(DATA_INVERSE, sk, __);
cout << "Secret key generation took " << timer.elapsed() * 1e3 << " ms" << endl;
(P.comm_stats - stats).print(true);
OnlineOptions::singleton.batch_size = (1 + pShare::Protocol::uses_triples) * n_tuples;
typename pShare::LivePrep prep(0, usage);
prep.params.correlation_check &= not opt.isSet("-U");
prep.params.fewer_rounds = opt.isSet("-A");
prep.params.fiat_shamir = opt.isSet("-H");
prep.params.check = not opt.isSet("-E");
prep.params.generateMACs = not opt.isSet("-M");
opts.check_beaver_open &= prep.params.generateMACs;
opts.check_open &= prep.params.generateMACs;
SubProcessor<pShare> proc(_, MCp, prep, P);
typename pShare::prep_type::Direct_MC MCpp(keyp);
prep.triple_generator->MC = &MCpp;
bool prep_mul = not opt.isSet("-D");
prep.params.use_extension = not opt.isSet("-S");
vector<EcTuple<T>> tuples;
preprocessing(tuples, n_tuples, sk, proc, opts);
//check(tuples, sk, keyp, P);
sign_benchmark(tuples, sk, MCp, P, opts, prep_mul ? 0 : &proc);
}