Unverified Commit 2ed572aa authored by kladko's avatar kladko

Cleaning up

parent dd4e9d36
...@@ -258,9 +258,6 @@ void calc_secret_shares(const char *decrypted_coeffs, ...@@ -258,9 +258,6 @@ void calc_secret_shares(const char *decrypted_coeffs,
CHECK_ARG_CLEAN(_n > 0); CHECK_ARG_CLEAN(_n > 0);
CHECK_ARG_CLEAN(_t <= _n); CHECK_ARG_CLEAN(_t <= _n);
try { try {
vector <libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol); vector <libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol);
...@@ -326,8 +323,6 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share, ...@@ -326,8 +323,6 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share,
int calc_secret_shareG2(const char *s_share, char *s_shareG2) { int calc_secret_shareG2(const char *s_share, char *s_shareG2) {
int result = 1; int result = 1;
mpz_t share; mpz_t share;
...@@ -416,43 +411,45 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares, ...@@ -416,43 +411,45 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares,
string ConvertHexToDec(string hex_str) { string ConvertHexToDec(string hex_str) {
try { mpz_t dec;
mpz_init(dec);
string ret = "";
mpz_t dec; try {
mpz_init(dec);
if (mpz_set_str(dec, hex_str.c_str(), 16) == -1) { if (mpz_set_str(dec, hex_str.c_str(), 16) == -1) {
mpz_clear(dec); goto clean;
return "";
} }
char arr[mpz_sizeinbase(dec, 10) + 2]; char arr[mpz_sizeinbase(dec, 10) + 2];
char *result = mpz_get_str(arr, 10, dec); char *result = mpz_get_str(arr, 10, dec);
CHECK_ARG_CLEAN(result);
mpz_clear(dec); ret = result;
return result;
} catch (exception &e) { } catch (exception &e) {
LOG_ERROR(e.what()); LOG_ERROR(e.what());
return ""; goto clean;
} catch (...) { } catch (...) {
LOG_ERROR("Unknown throwable"); LOG_ERROR("Unknown throwable");
return ""; goto clean;
} }
clean:
mpz_clear(dec);
return ret;
} }
int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind) { int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind) {
try { string pub_shares_str = public_shares;
vector <libff::alt_bn128_G2> pub_shares;
uint64_t share_length = 256;
uint8_t coord_length = 64;
int ret = 0;
CHECK_ARG_CLEAN(public_shares);
string pub_shares_str = public_shares; try {
vector <libff::alt_bn128_G2> pub_shares;
uint64_t share_length = 256;
uint8_t coord_length = 64;
for (size_t i = 0; i < _t; ++i) { for (size_t i = 0; i < _t; ++i) {
libff::alt_bn128_G2 pub_share; libff::alt_bn128_G2 pub_share;
...@@ -463,7 +460,8 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind) ...@@ -463,7 +460,8 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind)
string y_c0_str = ConvertHexToDec(pub_shares_str.substr(pos0 + 2 * coord_length, coord_length)); string y_c0_str = ConvertHexToDec(pub_shares_str.substr(pos0 + 2 * coord_length, coord_length));
string y_c1_str = ConvertHexToDec(pub_shares_str.substr(pos0 + 3 * coord_length, coord_length)); string y_c1_str = ConvertHexToDec(pub_shares_str.substr(pos0 + 3 * coord_length, coord_length));
if (x_c0_str == "" || x_c1_str == "" || y_c0_str == "" || y_c1_str == "") { if (x_c0_str == "" || x_c1_str == "" || y_c0_str == "" || y_c1_str == "") {
return 2; ret = 2;
goto clean;
} }
pub_share.X.c0 = libff::alt_bn128_Fq(x_c0_str.c_str()); pub_share.X.c0 = libff::alt_bn128_Fq(x_c0_str.c_str());
pub_share.X.c1 = libff::alt_bn128_Fq(x_c1_str.c_str()); pub_share.X.c1 = libff::alt_bn128_Fq(x_c1_str.c_str());
...@@ -496,22 +494,31 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind) ...@@ -496,22 +494,31 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind)
strncpy(public_shares + ConvertToString(val.X.c0).length() + 1, ConvertToString(val2.X.c0).c_str(), strncpy(public_shares + ConvertToString(val.X.c0).length() + 1, ConvertToString(val2.X.c0).c_str(),
ConvertToString(val2.X.c0).length()); ConvertToString(val2.X.c0).length());
return (val == sshare * libff::alt_bn128_G2::one()); ret = (val == sshare * libff::alt_bn128_G2::one());
} catch (exception &e) { } catch (exception &e) {
LOG_ERROR(e.what()); LOG_ERROR(e.what());
return 0; goto clean;
} catch (...) { } catch (...) {
LOG_ERROR("Unknown throwable"); LOG_ERROR("Unknown throwable");
return 0; goto clean;
} }
clean:
return ret;
} }
int calc_bls_public_key(char *skey_hex, char *pub_key) { int calc_bls_public_key(char *skey_hex, char *pub_key) {
mpz_t skey;
mpz_init(skey);
int ret = 1;
CHECK_ARG_CLEAN(skey_hex);
try { try {
mpz_t skey;
mpz_init(skey);
if (mpz_set_str(skey, skey_hex, 16) == -1) { if (mpz_set_str(skey, skey_hex, 16) == -1) {
mpz_clear(skey); mpz_clear(skey);
return 1; return 1;
...@@ -540,4 +547,8 @@ int calc_bls_public_key(char *skey_hex, char *pub_key) { ...@@ -540,4 +547,8 @@ int calc_bls_public_key(char *skey_hex, char *pub_key) {
LOG_ERROR("Unknown throwable"); LOG_ERROR("Unknown throwable");
return 1; return 1;
} }
clean:
mpz_clear(skey);
return ret;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment