Unverified Commit 2f267c40 authored by kladko's avatar kladko

SKALE-2454-add-logs-to-enclave

parent d79cbb71
...@@ -38,8 +38,8 @@ ...@@ -38,8 +38,8 @@
#define DKG_MAX_SEALED_LEN 3100 #define DKG_MAX_SEALED_LEN 3100
vector<string> splitString(const char *koefs, const char symbol) { vector<string> splitString(const char *coeffs, const char symbol) {
string str(koefs); string str(coeffs);
string delim; string delim;
delim.push_back(symbol); delim.push_back(symbol);
vector<string> G2_strings; vector<string> G2_strings;
...@@ -49,8 +49,8 @@ vector<string> splitString(const char *koefs, const char symbol) { ...@@ -49,8 +49,8 @@ vector<string> splitString(const char *koefs, const char symbol) {
if (pos == string::npos) pos = str.length(); if (pos == string::npos) pos = str.length();
string token = str.substr(prev, pos - prev); string token = str.substr(prev, pos - prev);
if (!token.empty()) { if (!token.empty()) {
string koef(token.c_str()); string coeff(token.c_str());
G2_strings.push_back(koef); G2_strings.push_back(coeff);
} }
prev = pos + delim.length(); prev = pos + delim.length();
} while (pos < str.length() && prev < str.length()); } while (pos < str.length() && prev < str.length());
...@@ -249,10 +249,10 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr ...@@ -249,10 +249,10 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr
char errMsg1[BUF_LEN]; char errMsg1[BUF_LEN];
int err_status = 0; int err_status = 0;
uint64_t dec_key_len; uint64_t decKeyLen;
uint8_t encr_key[BUF_LEN]; uint8_t encr_key[BUF_LEN];
memset(encr_key, 0, BUF_LEN); memset(encr_key, 0, BUF_LEN);
if (!hex2carray(encryptedKeyHex, &dec_key_len, encr_key)) { if (!hex2carray(encryptedKeyHex, &decKeyLen, encr_key)) {
throw SGXException(INVALID_HEX, "Invalid encryptedPolyHex"); throw SGXException(INVALID_HEX, "Invalid encryptedPolyHex");
} }
int result; int result;
...@@ -265,9 +265,9 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr ...@@ -265,9 +265,9 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr
if (!encryptKeys) if (!encryptKeys)
trustedDkgVerify(eid, &err_status, errMsg1, pshares, encr_sshare, encr_key, dec_key_len, t, ind, &result); trustedDkgVerify(eid, &err_status, errMsg1, pshares, encr_sshare, encr_key, decKeyLen, t, ind, &result);
else else
trustedDkgVerify_aes(eid, &err_status, errMsg1, pshares, encr_sshare, encr_key, dec_key_len, t, ind, &result); trustedDkgVerify_aes(eid, &err_status, errMsg1, pshares, encr_sshare, encr_key, decKeyLen, t, ind, &result);
if (result == 2) { if (result == 2) {
throw SGXException(INVALID_HEX, "Invalid public shares"); throw SGXException(INVALID_HEX, "Invalid public shares");
...@@ -289,12 +289,12 @@ bool CreateBLSShare(const string &blsKeyName, const char *s_shares, const char * ...@@ -289,12 +289,12 @@ bool CreateBLSShare(const string &blsKeyName, const char *s_shares, const char *
char errMsg1[BUF_LEN]; char errMsg1[BUF_LEN];
int err_status = 0; int err_status = 0;
uint64_t dec_key_len; uint64_t decKeyLen;
uint8_t encr_bls_key[BUF_LEN]; uint8_t encr_bls_key[BUF_LEN];
memset(encr_bls_key, 0, BUF_LEN); memset(encr_bls_key, 0, BUF_LEN);
uint8_t encr_key[BUF_LEN]; uint8_t encr_key[BUF_LEN];
memset(encr_key, 0, BUF_LEN); memset(encr_key, 0, BUF_LEN);
if (!hex2carray(encryptedKeyHex, &dec_key_len, encr_key)) { if (!hex2carray(encryptedKeyHex, &decKeyLen, encr_key)) {
throw SGXException(INVALID_HEX, "Invalid encryptedKeyHex"); throw SGXException(INVALID_HEX, "Invalid encryptedKeyHex");
} }
...@@ -302,9 +302,9 @@ bool CreateBLSShare(const string &blsKeyName, const char *s_shares, const char * ...@@ -302,9 +302,9 @@ bool CreateBLSShare(const string &blsKeyName, const char *s_shares, const char *
if (!encryptKeys) if (!encryptKeys)
trustedCreateBlsKey(eid, &err_status, errMsg1, s_shares, encr_key, dec_key_len, encr_bls_key, &enc_bls_len); trustedCreateBlsKey(eid, &err_status, errMsg1, s_shares, encr_key, decKeyLen, encr_bls_key, &enc_bls_len);
else else
trustedCreateBlsKey_aes(eid, &err_status, errMsg1, s_shares, encr_key, dec_key_len, encr_bls_key, &enc_bls_len); trustedCreateBlsKey_aes(eid, &err_status, errMsg1, s_shares, encr_key, decKeyLen, encr_bls_key, &enc_bls_len);
if (err_status != 0) { if (err_status != 0) {
...@@ -326,65 +326,65 @@ bool CreateBLSShare(const string &blsKeyName, const char *s_shares, const char * ...@@ -326,65 +326,65 @@ bool CreateBLSShare(const string &blsKeyName, const char *s_shares, const char *
} }
vector<string> GetBLSPubKey(const char *encryptedKeyHex) { vector<string> GetBLSPubKey(const char *encryptedKeyHex) {
//char* errMsg1 = (char*) calloc(1024,1);
char errMsg1[BUF_LEN]; char errMsg1[BUF_LEN];
int err_status = 0; int errStatus = 0;
uint64_t dec_key_len; uint64_t decKeyLen;
uint8_t encr_key[BUF_LEN]; uint8_t encrKey[BUF_LEN];
if (!hex2carray(encryptedKeyHex, &dec_key_len, encr_key)) { if (!hex2carray(encryptedKeyHex, &decKeyLen, encrKey)) {
throw SGXException(INVALID_HEX, "Invalid encryptedKeyHex"); throw SGXException(INVALID_HEX, "Invalid encryptedKeyHex");
} }
char pub_key[320]; char pubKey[320];
spdlog::debug("dec_key_len is {}", dec_key_len); spdlog::debug("decKeyLen is {}", decKeyLen);
if (!encryptKeys) if (!encryptKeys)
trustedGetBlsPubKey(eid, &err_status, errMsg1, encr_key, dec_key_len, pub_key); trustedGetBlsPubKey(eid, &errStatus, errMsg1, encrKey, decKeyLen, pubKey);
else else
trustedGetBlsPubKey_aes(eid, &err_status, errMsg1, encr_key, dec_key_len, pub_key); trustedGetBlsPubKeyAES(eid, &errStatus, errMsg1, encrKey, decKeyLen, pubKey);
if (err_status != 0) { if (errStatus != 0) {
spdlog::error(string(errMsg1) + " . Status is {}", err_status); spdlog::error(string(errMsg1) + " . Status is {}", errStatus);
throw SGXException(ERROR_IN_ENCLAVE, "Failed to get BLS public key in enclave"); throw SGXException(ERROR_IN_ENCLAVE, "Failed to get BLS public key in enclave");
} }
vector<string> pub_key_vect = splitString(pub_key, ':'); vector<string> pubKeyVect = splitString(pubKey, ':');
spdlog::debug("errMsg1 is {}", errMsg1); spdlog::debug("errMsg1 is {}", errMsg1);
spdlog::debug("pub key is "); spdlog::debug("pub key is ");
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
spdlog::debug("{}", pub_key_vect.at(i)); spdlog::debug("{}", pubKeyVect.at(i));
return pub_key_vect; return pubKeyVect;
} }
string decrypt_DHKey(const string &polyName, int ind) { string decryptDHKey(const string &polyName, int ind) {
vector<char> errMsg1(1024, 0); vector<char> errMsg1(1024, 0);
int err_status = 0; int err_status = 0;
string DH_key_name = polyName + "_" + to_string(ind) + ":"; string DH_key_name = polyName + "_" + to_string(ind) + ":";
shared_ptr<string> hexEncrKey_ptr = SGXWalletServer::readFromDb(DH_key_name, "DKG_DH_KEY_"); shared_ptr<string> hexEncrKeyPtr = SGXWalletServer::readFromDb(DH_key_name, "DKG_DH_KEY_");
spdlog::debug("encr DH key is {}", *hexEncrKey_ptr); spdlog::debug("encr DH key is {}", *hexEncrKeyPtr);
vector<char> hexEncrKey(2 * BUF_LEN, 0); vector<char> hexEncrKey(2 * BUF_LEN, 0);
uint64_t DH_enc_len = 0; uint64_t dhEncLen = 0;
uint8_t encrypted_DHkey[BUF_LEN]; uint8_t encryptedDHKey[BUF_LEN];
if (!hex2carray(hexEncrKey_ptr->c_str(), &DH_enc_len, encrypted_DHkey)) { if (!hex2carray(hexEncrKeyPtr->c_str(), &dhEncLen, encryptedDHKey)) {
throw SGXException(INVALID_HEX, "Invalid hexEncrKey"); throw SGXException(INVALID_HEX, "Invalid hexEncrKey");
} }
spdlog::debug("encr DH key length is {}", DH_enc_len); spdlog::debug("encr DH key length is {}", dhEncLen);
spdlog::debug("hex encr DH key length is {}", hexEncrKey_ptr->length()); spdlog::debug("hex encr DH key length is {}", hexEncrKeyPtr->length());
char DHKey[ECDSA_SKEY_LEN]; char DHKey[ECDSA_SKEY_LEN];
if (!encryptKeys) if (!encryptKeys)
decrypt_key(eid, &err_status, errMsg1.data(), encrypted_DHkey, DH_enc_len, DHKey); decrypt_key(eid, &err_status, errMsg1.data(), encryptedDHKey, dhEncLen, DHKey);
else else
decrypt_key_aes(eid, &err_status, errMsg1.data(), encrypted_DHkey, DH_enc_len, DHKey); decrypt_key_aes(eid, &err_status, errMsg1.data(), encryptedDHKey, dhEncLen, DHKey);
if (err_status != 0) { if (err_status != 0) {
throw SGXException(/*ERROR_IN_ENCLAVE*/ err_status, "decrypt key failed in enclave"); throw SGXException(/*ERROR_IN_ENCLAVE*/ err_status, "decrypt key failed in enclave");
} }
......
...@@ -31,13 +31,13 @@ std::string gen_dkg_poly( int _t); ...@@ -31,13 +31,13 @@ std::string gen_dkg_poly( int _t);
std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyHex, int t, int n); std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyHex, int t, int n);
std::vector<std::string> splitString(const char* koefs, const char symbol); std::vector<std::string> splitString(const char* coeffs, const char symbol);
std::string trustedGetSecretShares(const std::string& _polyName, const char* _encryptedPolyHex, const std::vector<std::string>& _publicKeys, int _t, int _n); std::string trustedGetSecretShares(const std::string& _polyName, const char* _encryptedPolyHex, const std::vector<std::string>& _publicKeys, int _t, int _n);
bool verifyShares(const char* publicShares, const char* encr_sshare, const char * encryptedKeyHex, int t, int n, int ind); bool verifyShares(const char* publicShares, const char* encr_sshare, const char * encryptedKeyHex, int t, int n, int ind);
std::string decrypt_DHKey(const std::string& polyName, int ind); std::string decryptDHKey(const std::string& polyName, int ind);
bool CreateBLSShare( const std::string& blsKeyName, const char * s_shares, const char * encryptedKeyHex); bool CreateBLSShare( const std::string& blsKeyName, const char * s_shares, const char * encryptedKeyHex);
......
...@@ -671,7 +671,7 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int ...@@ -671,7 +671,7 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int
string shareG2_name = "shareG2_" + _polyName + "_" + to_string(_ind) + ":"; string shareG2_name = "shareG2_" + _polyName + "_" + to_string(_ind) + ":";
shared_ptr<string> shareG2_ptr = readFromDb(shareG2_name); shared_ptr<string> shareG2_ptr = readFromDb(shareG2_name);
string DHKey = decrypt_DHKey(_polyName, _ind); string DHKey = decryptDHKey(_polyName, _ind);
result["share*G2"] = *shareG2_ptr; result["share*G2"] = *shareG2_ptr;
result["dhKey"] = DHKey; result["dhKey"] = DHKey;
......
...@@ -86,8 +86,8 @@ std::string ConvertG2ToString(const libff::alt_bn128_G2 & elem, int base = 10, s ...@@ -86,8 +86,8 @@ std::string ConvertG2ToString(const libff::alt_bn128_G2 & elem, int base = 10, s
return result; return result;
} }
std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* koefs, const char symbol){ std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* coeffs, const char symbol){
std::string str(koefs); std::string str(coeffs);
std::string delim; std::string delim;
delim.push_back(symbol); delim.push_back(symbol);
std::vector<libff::alt_bn128_Fr> tokens; std::vector<libff::alt_bn128_Fr> tokens;
...@@ -98,8 +98,8 @@ std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* koefs, const char s ...@@ -98,8 +98,8 @@ std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* koefs, const char s
if (pos == std::string::npos) pos = str.length(); if (pos == std::string::npos) pos = str.length();
std::string token = str.substr(prev, pos-prev); std::string token = str.substr(prev, pos-prev);
if (!token.empty()) { if (!token.empty()) {
libff::alt_bn128_Fr koef(token.c_str()); libff::alt_bn128_Fr coeff(token.c_str());
tokens.push_back(koef); tokens.push_back(coeff);
} }
prev = pos + delim.length(); prev = pos + delim.length();
} }
...@@ -146,12 +146,12 @@ libff::alt_bn128_Fr PolynomialValue(const std::vector<libff::alt_bn128_Fr>& pol, ...@@ -146,12 +146,12 @@ libff::alt_bn128_Fr PolynomialValue(const std::vector<libff::alt_bn128_Fr>& pol,
return value; return value;
} }
void calc_secret_shares(const char* decrypted_koefs, char * secret_shares, // calculates secret shares in base 10 to a string secret_shares, void calc_secret_shares(const char* decrypted_coeffs, char * secret_shares, // calculates secret shares in base 10 to a string secret_shares,
unsigned _t, unsigned _n) { // separated by ":" unsigned _t, unsigned _n) { // separated by ":"
// calculate for each node a list of secret values that will be used for verification // calculate for each node a list of secret values that will be used for verification
std::string result; std::string result;
char symbol = ':'; char symbol = ':';
std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_koefs, symbol); std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol);
for (size_t i = 0; i < _n; ++i) { for (size_t i = 0; i < _n; ++i) {
libff::alt_bn128_Fr secret_share = PolynomialValue(poly, libff::alt_bn128_Fr(i + 1), _t); libff::alt_bn128_Fr secret_share = PolynomialValue(poly, libff::alt_bn128_Fr(i + 1), _t);
...@@ -159,15 +159,15 @@ void calc_secret_shares(const char* decrypted_koefs, char * secret_shares, ...@@ -159,15 +159,15 @@ void calc_secret_shares(const char* decrypted_koefs, char * secret_shares,
result += ":"; result += ":";
} }
strncpy(secret_shares, result.c_str(), result.length() + 1); strncpy(secret_shares, result.c_str(), result.length() + 1);
//strncpy(secret_shares, decrypted_koefs, 3650); //strncpy(secret_shares, decrypted_coeffs, 3650);
} }
int calc_secret_share(const char* decrypted_koefs, char * s_share, int calc_secret_share(const char* decrypted_coeffs, char * s_share,
unsigned _t, unsigned _n, unsigned ind) { unsigned _t, unsigned _n, unsigned ind) {
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
char symbol = ':'; char symbol = ':';
std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_koefs, symbol); std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol);
if ( poly.size() != _t){ if ( poly.size() != _t){
return 1; return 1;
} }
...@@ -182,12 +182,12 @@ int calc_secret_share(const char* decrypted_koefs, char * s_share, ...@@ -182,12 +182,12 @@ int calc_secret_share(const char* decrypted_koefs, char * s_share,
} }
void calc_secret_shareG2_old(const char* decrypted_koefs, char * s_shareG2, void calc_secret_shareG2_old(const char* decrypted_coeffs, char * s_shareG2,
unsigned _t, unsigned ind){ unsigned _t, unsigned ind){
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
char symbol = ':'; char symbol = ':';
std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_koefs, symbol); std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol);
// if ( poly.size() != _t){ // if ( poly.size() != _t){
// //"t != poly.size()" + // //"t != poly.size()" +
// //strncpy(s_shareG2, std::to_string(poly.size()).c_str(), 18); // //strncpy(s_shareG2, std::to_string(poly.size()).c_str(), 18);
...@@ -200,7 +200,7 @@ void calc_secret_shareG2_old(const char* decrypted_koefs, char * s_shareG2, ...@@ -200,7 +200,7 @@ void calc_secret_shareG2_old(const char* decrypted_koefs, char * s_shareG2,
std::string secret_shareG2_str = ConvertG2ToString(secret_shareG2); std::string secret_shareG2_str = ConvertG2ToString(secret_shareG2);
strncpy(s_shareG2, secret_shareG2_str.c_str(), secret_shareG2_str.length() + 1); strncpy(s_shareG2, secret_shareG2_str.c_str(), secret_shareG2_str.length() + 1);
//strncpy(s_shareG2, decrypted_koefs, 320); //strncpy(s_shareG2, decrypted_coeffs, 320);
} }
int calc_secret_shareG2(const char* s_share, char * s_shareG2){ int calc_secret_shareG2(const char* s_share, char * s_shareG2){
...@@ -229,13 +229,13 @@ int calc_secret_shareG2(const char* s_share, char * s_shareG2){ ...@@ -229,13 +229,13 @@ int calc_secret_shareG2(const char* s_share, char * s_shareG2){
return 0; return 0;
} }
int calc_public_shares(const char* decrypted_koefs, char * public_shares, int calc_public_shares(const char* decrypted_coeffs, char * public_shares,
unsigned _t) { unsigned _t) {
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
// calculate for each node a list of public shares // calculate for each node a list of public shares
std::string result; std::string result;
char symbol = ':'; char symbol = ':';
std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_koefs, symbol); std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol);
if (poly.size() != _t){ if (poly.size() != _t){
return 1; return 1;
} }
......
...@@ -34,13 +34,13 @@ ...@@ -34,13 +34,13 @@
EXTERNC int gen_dkg_poly( char* secret, unsigned _t); EXTERNC int gen_dkg_poly( char* secret, unsigned _t);
EXTERNC void calc_secret_shares(const char* decrypted_koefs, char * secret_shares, EXTERNC void calc_secret_shares(const char* decrypted_coeffs, char * secret_shares,
unsigned _t, unsigned _n); unsigned _t, unsigned _n);
EXTERNC int calc_secret_share(const char* decrypted_koefs, char * s_share, EXTERNC int calc_secret_share(const char* decrypted_coeffs, char * s_share,
unsigned _t, unsigned _n, unsigned ind); unsigned _t, unsigned _n, unsigned ind);
EXTERNC int calc_public_shares(const char* decrypted_koefs, char * public_shares, EXTERNC int calc_public_shares(const char* decrypted_coeffs, char * public_shares,
unsigned _t); unsigned _t);
EXTERNC int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int ind); EXTERNC int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int ind);
......
...@@ -703,16 +703,16 @@ void trustedGetEncryptedSecretShare(int *err_status, char *err_string, uint8_t * ...@@ -703,16 +703,16 @@ void trustedGetEncryptedSecretShare(int *err_status, char *err_string, uint8_t *
//free(cypher); //free(cypher);
} }
void trustedComplaintResponse(int *err_status, char *err_string, uint8_t *encrypted_DHkey, uint8_t *encrypted_dkg_secret, void trustedComplaintResponse(int *err_status, char *err_string, uint8_t *encryptedDHKey, uint8_t *encrypted_dkg_secret,
uint32_t *dec_len, uint32_t *dec_len,
char *DH_key, char *s_shareG2, uint8_t _t, uint8_t _n, uint8_t ind1) { char *DH_key, char *s_shareG2, uint8_t _t, uint8_t _n, uint8_t ind1) {
uint32_t enc_len; uint32_t enc_len;
// sgx_status_t status = sgx_unseal_data( // sgx_status_t status = sgx_unseal_data(
// (const sgx_sealed_data_t *)encrypted_DHkey, NULL, 0, (uint8_t *)DH_key, &enc_len); // (const sgx_sealed_data_t *)encryptedDHKey, NULL, 0, (uint8_t *)DH_key, &enc_len);
// if (status != SGX_SUCCESS) { // if (status != SGX_SUCCESS) {
// snprintf(err_string, BUF_LEN,"sgx_unseal_data - encrypted_DHkey failed with status %d", status); // snprintf(err_string, BUF_LEN,"sgx_unseal_data - encryptedDHKey failed with status %d", status);
// return; // return;
// } // }
...@@ -1694,7 +1694,7 @@ void trustedCreateBlsKey_aes(int *err_status, char *err_string, const char *s_sh ...@@ -1694,7 +1694,7 @@ void trustedCreateBlsKey_aes(int *err_status, char *err_string, const char *s_sh
} }
void void
trustedGetBlsPubKey_aes(int *err_status, char *err_string, uint8_t *encrypted_key, uint64_t key_len, char *bls_pub_key) { trustedGetBlsPubKeyAES(int *err_status, char *err_string, uint8_t *encrypted_key, uint64_t key_len, char *bls_pub_key) {
char skey_hex[ECDSA_SKEY_LEN]; char skey_hex[ECDSA_SKEY_LEN];
......
This diff is collapsed.
...@@ -207,8 +207,8 @@ TEST_CASE("DKG gen test", "[dkg-gen]") { ...@@ -207,8 +207,8 @@ TEST_CASE("DKG gen test", "[dkg-gen]") {
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
} }
vector<libff::alt_bn128_Fr> SplitStringToFr(const char *koefs, const char symbol) { vector<libff::alt_bn128_Fr> SplitStringToFr(const char *coeffs, const char symbol) {
string str(koefs); string str(coeffs);
string delim; string delim;
delim.push_back(symbol); delim.push_back(symbol);
vector<libff::alt_bn128_Fr> tokens; vector<libff::alt_bn128_Fr> tokens;
...@@ -218,8 +218,8 @@ vector<libff::alt_bn128_Fr> SplitStringToFr(const char *koefs, const char symbol ...@@ -218,8 +218,8 @@ vector<libff::alt_bn128_Fr> SplitStringToFr(const char *koefs, const char symbol
if (pos == string::npos) pos = str.length(); if (pos == string::npos) pos = str.length();
string token = str.substr(prev, pos - prev); string token = str.substr(prev, pos - prev);
if (!token.empty()) { if (!token.empty()) {
libff::alt_bn128_Fr koef(token.c_str()); libff::alt_bn128_Fr coeff(token.c_str());
tokens.push_back(koef); tokens.push_back(coeff);
} }
prev = pos + delim.length(); prev = pos + delim.length();
} while (pos < str.length() && prev < str.length()); } while (pos < str.length() && prev < str.length());
...@@ -227,9 +227,9 @@ vector<libff::alt_bn128_Fr> SplitStringToFr(const char *koefs, const char symbol ...@@ -227,9 +227,9 @@ vector<libff::alt_bn128_Fr> SplitStringToFr(const char *koefs, const char symbol
return tokens; return tokens;
} }
vector<string> SplitStringTest(const char *koefs, const char symbol) { vector<string> SplitStringTest(const char *coeffs, const char symbol) {
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
string str(koefs); string str(coeffs);
string delim; string delim;
delim.push_back(symbol); delim.push_back(symbol);
vector<string> G2_strings; vector<string> G2_strings;
...@@ -239,8 +239,8 @@ vector<string> SplitStringTest(const char *koefs, const char symbol) { ...@@ -239,8 +239,8 @@ vector<string> SplitStringTest(const char *koefs, const char symbol) {
if (pos == string::npos) pos = str.length(); if (pos == string::npos) pos = str.length();
string token = str.substr(prev, pos - prev); string token = str.substr(prev, pos - prev);
if (!token.empty()) { if (!token.empty()) {
string koef(token.c_str()); string coeff(token.c_str());
G2_strings.push_back(koef); G2_strings.push_back(coeff);
} }
prev = pos + delim.length(); prev = pos + delim.length();
} while (pos < str.length() && prev < str.length()); } while (pos < str.length() && prev < str.length());
...@@ -250,15 +250,15 @@ vector<string> SplitStringTest(const char *koefs, const char symbol) { ...@@ -250,15 +250,15 @@ vector<string> SplitStringTest(const char *koefs, const char symbol) {
libff::alt_bn128_G2 VectStringToG2(const vector<string> &G2_str_vect) { libff::alt_bn128_G2 VectStringToG2(const vector<string> &G2_str_vect) {
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
libff::alt_bn128_G2 koef = libff::alt_bn128_G2::zero(); libff::alt_bn128_G2 coeff = libff::alt_bn128_G2::zero();
koef.X.c0 = libff::alt_bn128_Fq(G2_str_vect.at(0).c_str()); coeff.X.c0 = libff::alt_bn128_Fq(G2_str_vect.at(0).c_str());
koef.X.c1 = libff::alt_bn128_Fq(G2_str_vect.at(1).c_str()); coeff.X.c1 = libff::alt_bn128_Fq(G2_str_vect.at(1).c_str());
koef.Y.c0 = libff::alt_bn128_Fq(G2_str_vect.at(2).c_str()); coeff.Y.c0 = libff::alt_bn128_Fq(G2_str_vect.at(2).c_str());
koef.Y.c1 = libff::alt_bn128_Fq(G2_str_vect.at(3).c_str()); coeff.Y.c1 = libff::alt_bn128_Fq(G2_str_vect.at(3).c_str());
koef.Z.c0 = libff::alt_bn128_Fq::one(); coeff.Z.c0 = libff::alt_bn128_Fq::one();
koef.Z.c1 = libff::alt_bn128_Fq::zero(); coeff.Z.c1 = libff::alt_bn128_Fq::zero();
return koef; return coeff;
} }
TEST_CASE("DKG public shares test", "[dkg-pub-shares]") { TEST_CASE("DKG public shares test", "[dkg-pub-shares]") {
...@@ -297,11 +297,11 @@ TEST_CASE("DKG public shares test", "[dkg-pub-shares]") { ...@@ -297,11 +297,11 @@ TEST_CASE("DKG public shares test", "[dkg-pub-shares]") {
vector<string> G2_strings = splitString(public_shares.data(), ','); vector<string> G2_strings = splitString(public_shares.data(), ',');
vector<libff::alt_bn128_G2> pub_shares_G2; vector<libff::alt_bn128_G2> pub_shares_G2;
for (u_int64_t i = 0; i < G2_strings.size(); i++) { for (u_int64_t i = 0; i < G2_strings.size(); i++) {
vector<string> koef_str = splitString(G2_strings.at(i).c_str(), ':'); vector<string> coeff_str = splitString(G2_strings.at(i).c_str(), ':');
//libff::alt_bn128_G2 el = VectStringToG2(koef_str); //libff::alt_bn128_G2 el = VectStringToG2(coeff_str);
//cerr << "pub_share G2 " << i+1 << " : " << endl; //cerr << "pub_share G2 " << i+1 << " : " << endl;
//el.print_coordinates(); //el.print_coordinates();
pub_shares_G2.push_back(VectStringToG2(koef_str)); pub_shares_G2.push_back(VectStringToG2(coeff_str));
} }
vector<char> secret(BUF_LEN, 0); vector<char> secret(BUF_LEN, 0);
...@@ -809,7 +809,7 @@ void SendRPCRequest() { ...@@ -809,7 +809,7 @@ void SendRPCRequest() {
throw SGXException(INVALID_HEX, "Invalid hash"); throw SGXException(INVALID_HEX, "Invalid hash");
} }
map<size_t, shared_ptr<BLSPublicKeyShare>> koefs_pkeys_map; map<size_t, shared_ptr<BLSPublicKeyShare>> coeffs_pkeys_map;
for (int i = 0; i < t; i++) { for (int i = 0; i < t; i++) {
...@@ -1082,7 +1082,7 @@ TEST_CASE("AES_DKG test", "[aes-dkg]") { ...@@ -1082,7 +1082,7 @@ TEST_CASE("AES_DKG test", "[aes-dkg]") {
} }
map<size_t, shared_ptr<BLSPublicKeyShare>> koefs_pkeys_map; map<size_t, shared_ptr<BLSPublicKeyShare>> coeffs_pkeys_map;
for (int i = 0; i < t; i++) { for (int i = 0; i < t; i++) {
string endName = poly_names[i].substr(4); string endName = poly_names[i].substr(4);
...@@ -1108,12 +1108,12 @@ TEST_CASE("AES_DKG test", "[aes-dkg]") { ...@@ -1108,12 +1108,12 @@ TEST_CASE("AES_DKG test", "[aes-dkg]") {
BLSPublicKeyShare pubKey(make_shared<vector<string>>(pubKey_vect), t, n); BLSPublicKeyShare pubKey(make_shared<vector<string>>(pubKey_vect), t, n);
REQUIRE(pubKey.VerifySigWithHelper(hash_arr, make_shared<BLSSigShare>(sig), t, n)); REQUIRE(pubKey.VerifySigWithHelper(hash_arr, make_shared<BLSSigShare>(sig), t, n));
koefs_pkeys_map[i + 1] = make_shared<BLSPublicKeyShare>(pubKey); coeffs_pkeys_map[i + 1] = make_shared<BLSPublicKeyShare>(pubKey);
} }
shared_ptr<BLSSignature> commonSig = sigShareSet.merge(); shared_ptr<BLSSignature> commonSig = sigShareSet.merge();
BLSPublicKey common_public(make_shared<map<size_t, shared_ptr<BLSPublicKeyShare>>>(koefs_pkeys_map), t, n); BLSPublicKey common_public(make_shared<map<size_t, shared_ptr<BLSPublicKeyShare>>>(coeffs_pkeys_map), t, n);
REQUIRE(common_public.VerifySigWithHelper(hash_arr, commonSig, t, n)); REQUIRE(common_public.VerifySigWithHelper(hash_arr, commonSig, t, n));
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
......
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