Unverified Commit 50a42a1e authored by Oleh Nikolaiev's avatar Oleh Nikolaiev Committed by GitHub

Merge branch 'develop' into enhancement/SKALE-3007-sgx-parameters-validation

parents 4571af97 8e5e8758
......@@ -43,12 +43,7 @@
#include <string.h>
int gen_session_key(char *skey_str, char *pb_keyB, char *common_key) {
int ret = -1;
LOG_INFO(__FUNCTION__);
......@@ -60,7 +55,6 @@ int gen_session_key(char *skey_str, char *pb_keyB, char *common_key) {
point pub_keyB = point_init();
point session_key = point_init();
if (!common_key) {
LOG_ERROR("gen_session_key: Null common_key");
goto clean;
......@@ -107,18 +101,15 @@ int gen_session_key(char *skey_str, char *pb_keyB, char *common_key) {
point_clear(session_key);
return ret;
}
int session_key_recover(const char *skey_str, const char *sshare, char *common_key) {
int ret = -1;
SAFE_CHAR_BUF(pb_keyB_x, 65);
SAFE_CHAR_BUF(pb_keyB_y, 65);
mpz_t skey;
mpz_init(skey);
point pub_keyB = point_init();
......@@ -147,14 +138,6 @@ int session_key_recover(const char *skey_str, const char *sshare, char *common_k
goto clean;
}
if (mpz_set_str(skey, skey_str, 16) == -1) {
goto clean;
}
......@@ -187,17 +170,17 @@ int xor_encrypt(char *key, char *message, char *cypher) {
if (!cypher) {
LOG_ERROR("xor_encrypt: null cypher");
goto clean;
return ret;
}
if (!key) {
LOG_ERROR("xor_encrypt: null key");
goto clean;
return ret;
}
if (!message) {
LOG_ERROR("xor_encrypt: null message");
goto clean;
return ret;
}
SAFE_CHAR_BUF(cypher_bin, 33);
......@@ -206,13 +189,13 @@ int xor_encrypt(char *key, char *message, char *cypher) {
uint64_t key_length;
if (!hex2carray(key, &key_length, (uint8_t *) key_bin)) {
goto clean;
return ret;
}
uint64_t msg_length;
uint8_t msg_bin[33];
if (!hex2carray(message, &msg_length, msg_bin)) {
goto clean;
return ret;
}
for (int i = 0; i < 32; i++) {
......@@ -223,11 +206,7 @@ int xor_encrypt(char *key, char *message, char *cypher) {
ret = 0;
clean:
;
return ret;
}
int xor_decrypt(char *key, char *cypher, char *message) {
......@@ -236,34 +215,33 @@ int xor_decrypt(char *key, char *cypher, char *message) {
if (!cypher) {
LOG_ERROR("xor_encrypt: null cypher");
goto clean;
return ret;
}
if (!key) {
LOG_ERROR("xor_encrypt: null key");
goto clean;
return ret;
}
if (!message) {
LOG_ERROR("xor_encrypt: null message");
goto clean;
return ret;
}
SAFE_CHAR_BUF(msg_bin,33);
SAFE_CHAR_BUF(key_bin,33)
uint64_t key_length;
if (!hex2carray(key, &key_length, (uint8_t*) key_bin)) {
goto clean;
return ret;
}
uint64_t cypher_length;
SAFE_CHAR_BUF(cypher_bin, 33);
if (!hex2carray(cypher, &cypher_length, (uint8_t *) cypher_bin)) {
goto clean;
return ret;
}
for (int i = 0; i < 32; i++) {
......@@ -274,9 +252,5 @@ int xor_decrypt(char *key, char *cypher, char *message) {
ret = 0;
clean:
;
return ret;
}
......@@ -51,10 +51,7 @@ string stringFromFr(const libff::alt_bn128_Fr &_el) {
mpz_t t;
mpz_init(t);
try {
_el.as_bigint().to_mpz(t);
SAFE_CHAR_BUF(arr, BUF_LEN);
......@@ -95,7 +92,6 @@ string ConvertToString(const T &field_elem, int base = 10) {
char *tmp = mpz_get_str(arr, base, t);
ret = string(tmp);
goto clean;
......@@ -128,24 +124,20 @@ string ConvertG2ToString(const libff::alt_bn128_G2 &elem, int base = 10, const s
result += delim;
result += ConvertToString(elem.Y.c1);
goto clean;
return result;
} catch (exception &e) {
LOG_ERROR(e.what());
goto clean;
return result;
} catch (...) {
LOG_ERROR("Unknown throwable");
goto clean;
return result;
}
clean:
return result;
}
vector <libff::alt_bn128_Fr> SplitStringToFr(const char *coeffs, const char symbol) {
vector <libff::alt_bn128_Fr> result;
string str(coeffs);
string delim;
......@@ -168,14 +160,14 @@ vector <libff::alt_bn128_Fr> SplitStringToFr(const char *coeffs, const char symb
prev = pos + delim.length();
} while (pos < str.length() && prev < str.length());
goto clean;
return result;
} catch (exception &e) {
LOG_ERROR(e.what());
goto clean;
return result;
} catch (...) {
LOG_ERROR("Unknown throwable");
goto clean;
return result;
}
clean:
......@@ -202,22 +194,21 @@ int gen_dkg_poly(char *secret, unsigned _t) {
strncpy(secret, result.c_str(), result.length() + 1);
if (strlen(secret) == 0) {
goto clean;
return status;
}
status = 0;
} catch (exception &e) {
LOG_ERROR(e.what());
goto clean;
return status;
} catch (...) {
LOG_ERROR("Unknown throwable");
goto clean;
return status;
}
clean:
return status;
}
libff::alt_bn128_Fr PolynomialValue(const vector <libff::alt_bn128_Fr> &pol, libff::alt_bn128_Fr point, unsigned _t) {
......@@ -232,16 +223,15 @@ libff::alt_bn128_Fr PolynomialValue(const vector <libff::alt_bn128_Fr> &pol, lib
pow *= point;
}
goto clean;
return result;
} catch (exception &e) {
LOG_ERROR(e.what());
goto clean;
return result;
} catch (...) {
LOG_ERROR("Unknown throwable");
goto clean;
return result;
}
clean:
return result;
}
......@@ -271,10 +261,10 @@ void calc_secret_shares(const char *decrypted_coeffs,
} catch (exception &e) {
LOG_ERROR(e.what());
goto clean;
return;
} catch (...) {
LOG_ERROR("Unknown throwable");
goto clean;
return;
}
clean:
......@@ -283,8 +273,6 @@ void calc_secret_shares(const char *decrypted_coeffs,
int calc_secret_share(const char *decrypted_coeffs, char *s_share,
unsigned _t, unsigned _n, unsigned ind) {
int result = 1;
CHECK_ARG_CLEAN(decrypted_coeffs);
......@@ -296,7 +284,7 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share,
char symbol = ':';
vector <libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol);
if (poly.size() != _t) {
goto clean;
return result;
}
libff::alt_bn128_Fr secret_share = PolynomialValue(poly, libff::alt_bn128_Fr(ind), _t);
......@@ -306,14 +294,14 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share,
strncpy(s_share, cur_share.c_str(), cur_share.length() + 1);
result = 0;
goto clean;
return result;
} catch (exception &e) {
LOG_ERROR(e.what());
goto clean;
return result;
} catch (...) {
LOG_ERROR("Unknown throwable");
goto clean;
return result;
}
clean:
......@@ -381,12 +369,11 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares,
CHECK_ARG_CLEAN(public_shares);
CHECK_ARG_CLEAN(_t > 0);
try {
vector <libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol);
if (poly.size() != _t) {
goto clean;
return ret;
}
for (size_t i = 0; i < _t; ++i) {
libff::alt_bn128_G2 pub_share = poly.at(i) * libff::alt_bn128_G2::one();
......@@ -406,7 +393,7 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares,
}
clean:
return ret;
return ret;
}
string ConvertHexToDec(string hex_str) {
......@@ -435,8 +422,8 @@ string ConvertHexToDec(string hex_str) {
}
clean:
mpz_clear(dec);
return ret;
mpz_clear(dec);
return ret;
}
int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind) {
......@@ -461,7 +448,7 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind)
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 == "") {
ret = 2;
goto clean;
return ret;
}
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());
......@@ -498,11 +485,11 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind)
} catch (exception &e) {
LOG_ERROR(e.what());
goto clean;
return ret;
} catch (...) {
LOG_ERROR("Unknown throwable");
goto clean;
return ret;
}
clean:
......@@ -550,6 +537,6 @@ int calc_bls_public_key(char *skey_hex, char *pub_key) {
}
clean:
mpz_clear(skey);
return ret;
mpz_clear(skey);
return ret;
}
......@@ -77,7 +77,8 @@ string *stringFromFq(libff::alt_bn128_Fq *_fq) {
string *ret = nullptr;
mpz_t t;
mpz_init(t);SAFE_CHAR_BUF(arr, BUF_LEN);
mpz_init(t);
SAFE_CHAR_BUF(arr, BUF_LEN);
try {
_fq->as_bigint().to_mpz(t);
......@@ -140,7 +141,8 @@ string *stringFromG1(libff::alt_bn128_G1 *_g1) {
libff::alt_bn128_Fr *keyFromString(const char *_keyStringHex) {
mpz_t skey;
mpz_init(skey);SAFE_CHAR_BUF(skey_dec, BUF_LEN);
mpz_init(skey);
SAFE_CHAR_BUF(skey_dec, BUF_LEN);
libff::alt_bn128_Fr *ret = nullptr;
......
......@@ -58,7 +58,6 @@ void SGXWallet::printUsage() {
}
void SGXWallet::serializeKeys(const vector<string>& _ecdsaKeyNames, const vector<string>& _blsKeyNames, const string& _fileName) {
Json::Value top(Json::objectValue);
Json::Value ecdsaKeysJson(Json::objectValue);
......
......@@ -35,30 +35,21 @@ testList = ["[first-run]",
"[get-server-version]",
"[backup-key]",
"[delete-bls-key]",
"[ecdsa-key-gen]",
"[ecdsa-aes-key-gen]",
"[ecdsa-key-sig-gen]",
"[ecdsa-aes-key-sig-gen]",
"[ecdsa-get-pub-key]",
"[ecdsa-aes-get-pub-key]",
"[ecdsa-key-gen-api]",
"[ecdsa-key-gen-sign-api]",
"[bls-key-encrypt]",
"[dkg-gen]",
"[dkg-aes-gen]",
"[dkg-encr-sshares]",
"[dkg-aes-encr-sshares]",
"[dkg-verify]",
"[dkg-api]",
"[dkg-bls]",
"[dkg-poly-exists]",
# "[dkg-pub-shares]",
"[dkg-aes-pub-shares]",
"[many-threads-crypto]",
"[aes-encrypt-decrypt]",
"[sgx-encrypt-decrypt]",
"[aes-dkg]",
"[aes-not-aes]"
"[aes-dkg]"
]
......
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