diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2018-05-08 10:10:24 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2018-05-08 10:10:24 +0800 |
commit | 3731172fc87e1b598a15352c4eef35f0a878cc51 (patch) | |
tree | d5671ac10ac7f5fe45a0d4382f150f3822ad93f9 /sample/bls_tool.cpp | |
parent | 2cb79ec588676444ad0d6e04e6660442640f32e9 (diff) | |
download | dexon-bls-3731172fc87e1b598a15352c4eef35f0a878cc51.tar dexon-bls-3731172fc87e1b598a15352c4eef35f0a878cc51.tar.gz dexon-bls-3731172fc87e1b598a15352c4eef35f0a878cc51.tar.bz2 dexon-bls-3731172fc87e1b598a15352c4eef35f0a878cc51.tar.lz dexon-bls-3731172fc87e1b598a15352c4eef35f0a878cc51.tar.xz dexon-bls-3731172fc87e1b598a15352c4eef35f0a878cc51.tar.zst dexon-bls-3731172fc87e1b598a15352c4eef35f0a878cc51.zip |
remove bls_tool.cpp
Diffstat (limited to 'sample/bls_tool.cpp')
-rw-r--r-- | sample/bls_tool.cpp | 207 |
1 files changed, 0 insertions, 207 deletions
diff --git a/sample/bls_tool.cpp b/sample/bls_tool.cpp deleted file mode 100644 index 5683c5e..0000000 --- a/sample/bls_tool.cpp +++ /dev/null @@ -1,207 +0,0 @@ -#include <bls.hpp> -#include <iostream> -#include <cybozu/option.hpp> - -template<class T> -void write(const T& t) -{ - std::cout << std::hex << std::showbase << t << std::endl; -} - -template<class T> -void read(T& t) -{ - if (!(std::cin >> t)) { - throw std::runtime_error("can't read"); - } -} - -void strip(std::string& str) -{ - if (str.empty()) return; - if (str[str.size() - 1] == '\n') str.resize(str.size() - 1); -} - -void readMessage(std::string& str) -{ - str.clear(); - std::string line; - std::getline(std::cin, line); // remove first blank line - while (std::getline(std::cin, line)) { - if (!str.empty()) str += '\n'; - str += line; - } - strip(str); - if (!str.empty()) return; - throw std::runtime_error("readMessage:message is empty"); -} - -bool g_verbose = false; - -void init() -{ - if (g_verbose) fprintf(stderr, "init\n"); - bls::SecretKey sec; - sec.init(); - write(sec); -} - -void pubkey() -{ - if (g_verbose) fprintf(stderr, "pubkey\n"); - bls::SecretKey sec; - read(sec); - if (g_verbose) std::cerr << "sec:" << sec << std::endl; - bls::PublicKey pub; - sec.getPublicKey(pub); - if (g_verbose) std::cerr << "pub:" << pub << std::endl; - write(pub); -} - -void sign() -{ - if (g_verbose) fprintf(stderr, "sign\n"); - bls::SecretKey sec; - read(sec); - if (g_verbose) std::cerr << "sec:" << sec << std::endl; - std::string m; - readMessage(m); - if (g_verbose) fprintf(stderr, "message:`%s`\n", m.c_str()); - bls::Sign s; - sec.sign(s, m); - write(s); -} - -void verify() -{ - if (g_verbose) fprintf(stderr, "verify\n"); - bls::Sign s; - read(s); - if (g_verbose) std::cerr << "sign:" << s << std::endl; - bls::PublicKey pub; - read(pub); - if (g_verbose) std::cerr << "pub:" << pub << std::endl; - std::string m; - readMessage(m); - if (g_verbose) fprintf(stderr, "message:`%s`\n", m.c_str()); - bool b = s.verify(pub, m); - write(b ? "1" : "0"); -} - -void share_pub() -{ - if (g_verbose) fprintf(stderr, "share_pub\n"); - size_t k; - read(k); - if (g_verbose) fprintf(stderr, "k:%d\n", (int)k); - bls::PublicKeyVec mpk(k); - for (size_t i = 0; i < k; i++) { - read(mpk[i]); - } - bls::Id id; - read(id); - if (g_verbose) std::cerr << "id:" << id << std::endl; - bls::PublicKey pub; - pub.set(mpk, id); - write(pub); -} - -void recover_sig() -{ - if (g_verbose) fprintf(stderr, "recover_sig\n"); - size_t k; - read(k); - if (g_verbose) fprintf(stderr, "k:%d\n", (int)k); - bls::SignatureVec sVec(k); - bls::IdVec idVec(k); - for (size_t i = 0; i < k; i++) { - read(idVec[i]); - read(sVec[i]); - } - bls::Sign s; - s.recover(sVec, idVec); - write(s); -} - -void aggregate_pub() -{ - if (g_verbose) fprintf(stderr, "aggregate_pub\n"); - size_t n; - read(n); - if (n == 0) throw std::runtime_error("aggregate_pub:n is zero"); - if (g_verbose) fprintf(stderr, "n:%d\n", (int)n); - bls::PublicKey pub; - read(pub); - if (g_verbose) std::cerr << "pub:" << pub << std::endl; - for (size_t i = 1; i < n; i++) { - bls::PublicKey rhs; - read(rhs); - pub.add(rhs); - } - write(pub); -} - -void aggregate_sig() -{ - if (g_verbose) fprintf(stderr, "aggregate_sig\n"); - size_t n; - read(n); - if (n == 0) throw std::runtime_error("aggregate_sig:n is zero"); - if (g_verbose) fprintf(stderr, "n:%d\n", (int)n); - bls::Sign s; - read(s); - if (g_verbose) std::cerr << "sign:" << s << std::endl; - for (size_t i = 1; i < n; i++) { - bls::Sign rhs; - read(rhs); - s.add(rhs); - } - write(s); -} - -int main(int argc, char *argv[]) - try -{ - const struct CmdTbl { - const char *name; - void (*exec)(); - } tbl[] = { - { "init", init }, - { "pubkey", pubkey }, - { "sign", sign }, - { "verify", verify }, - { "share-pub", share_pub }, - { "recover-sig", recover_sig }, - { "aggregate-pub", aggregate_pub }, - { "aggregate-sig", aggregate_sig }, - }; - std::string cmdCat; - for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { - if (i > 0) cmdCat += '|'; - cmdCat += tbl[i].name; - } - std::string mode; - cybozu::Option opt; - - opt.appendParam(&mode, cmdCat.c_str()); - opt.appendBoolOpt(&g_verbose, "v", ": verbose"); - opt.appendHelp("h"); - if (!opt.parse(argc, argv)) { - goto ERR_EXIT; - } - - bls::init(); - for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { - if (mode == tbl[i].name) { - tbl[i].exec(); - return 0; - } - } - fprintf(stderr, "bad mode %s\n", mode.c_str()); -ERR_EXIT: - opt.usage(); - return 1; -} catch (std::exception& e) { - fprintf(stderr, "ERR %s\n", e.what()); - return 1; -} |