10 namespace po = boost::program_options;
24 std::string challenge_file;
26 std::string digest_file;
30 mpc_phase2_contribute()
33 "Create response (MPC contribution) from challenge")
37 , skip_user_input(
false)
42 void initialize_suboptions(
43 po::options_description &options,
44 po::options_description &all_options,
45 po::positional_options_description &pos)
override
47 options.add_options()(
49 po::value<std::string>(),
50 "Write contribution digest to file")(
51 "skip-user-input",
"Use only system randomness");
52 all_options.add(options).add_options()(
53 "challenge_file", po::value<std::string>(),
"challenge file")(
54 "response_file", po::value<std::string>(),
"response output file");
55 pos.add(
"challenge_file", 1).add(
"response_file", 1);
58 void parse_suboptions(
const po::variables_map &vm)
override
60 if (0 == vm.count(
"challenge_file")) {
61 throw po::error(
"challenge_file not specified");
63 if (0 == vm.count(
"response_file")) {
64 throw po::error(
"response_file not specified");
66 challenge_file = vm[
"challenge_file"].as<std::string>();
67 out_file = vm[
"response_file"].as<std::string>();
68 digest_file = vm.count(
"digest") ? vm[
"digest"].as<std::string>() :
"";
69 skip_user_input = (bool)vm.count(
"skip-user-input");
72 void subcommand_usage(
const char *argv0)
override
74 std::cout <<
"Usage:\n " << argv0 <<
" " << subcommand_name
75 <<
" [<options>] <challenge_file> <response_file>\n\n";
81 std::cout <<
"challenge_file: " << challenge_file <<
"\n";
82 std::cout <<
"out_file: " << out_file << std::endl;
83 std::cout <<
"digest: " << digest_file << std::endl;
84 std::cout <<
"skip_user_input: " << skip_user_input << std::endl;
87 libff::enter_block(
"Load challenge file");
89 read_from_file<srs_mpc_phase2_challenge<pp>>(challenge_file);
90 libff::leave_block(
"Load challenge file");
92 libff::enter_block(
"Computing randomness");
93 libff::Fr<pp> contribution = get_randomness();
94 libff::leave_block(
"Computing randomness");
96 libff::enter_block(
"Computing response");
98 srs_mpc_phase2_compute_response<pp>(challenge, contribution);
99 libff::leave_block(
"Computing response");
101 libff::enter_block(
"Writing response");
102 libff::print_indent();
103 std::cout << out_file << std::endl;
105 std::ofstream out(out_file);
108 libff::leave_block(
"Writing response");
111 response.
publickey.compute_digest(contrib_digest);
112 std::cout <<
"Digest of the contribution was:\n";
115 if (!digest_file.empty()) {
116 std::ofstream out(digest_file);
118 std::cout <<
"Digest written to: " << digest_file << std::endl;
124 libff::Fr<pp> get_randomness()
const
126 using random_word = std::random_device::result_type;
128 std::random_device rd;
136 const size_t buf_size_in_words =
137 sizeof(buf) / (
size_t)
sizeof(random_word);
140 for (
size_t i = 0; i < 1024 /
sizeof(buf); ++i) {
141 random_word *words = (random_word *)&buf;
142 for (
size_t j = 0; j < buf_size_in_words; ++j) {
145 hs.write((
const char *)&buf,
sizeof(buf));
148 if (!skip_user_input) {
149 std::cout <<
"Enter some random text and press [ENTER] ..."
151 std::string user_input;
152 std::getline(std::cin, user_input);
159 libff::Fr<pp> random_fp;