Unverified Commit a2fdbcb7 authored by kladko's avatar kladko

SKALE-2341 Added tags for older commits

parent 4e26af8b
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
#include "common.h" #include "common.h"
std::string *FqToString(libff::alt_bn128_Fq*_fq) { std::string *FqToString(libff::alt_bn128_Fq *_fq) {
mpz_t t; mpz_t t;
mpz_init(t); mpz_init(t);
...@@ -81,8 +81,7 @@ int char2int(char _input) { ...@@ -81,8 +81,7 @@ int char2int(char _input) {
} }
void carray2Hex(const unsigned char *d, int _len, char *_hexArray) {
void carray2Hex(const unsigned char *d, int _len, char* _hexArray) {
char hexval[16] = {'0', '1', '2', '3', '4', '5', '6', '7', char hexval[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
...@@ -97,8 +96,8 @@ void carray2Hex(const unsigned char *d, int _len, char* _hexArray) { ...@@ -97,8 +96,8 @@ void carray2Hex(const unsigned char *d, int _len, char* _hexArray) {
} }
bool hex2carray(const char * _hex, uint64_t *_bin_len, bool hex2carray(const char *_hex, uint64_t *_bin_len,
uint8_t* _bin ) { uint8_t *_bin) {
int len = strnlen(_hex, 2 * BUF_LEN); int len = strnlen(_hex, 2 * BUF_LEN);
...@@ -109,8 +108,8 @@ bool hex2carray(const char * _hex, uint64_t *_bin_len, ...@@ -109,8 +108,8 @@ bool hex2carray(const char * _hex, uint64_t *_bin_len,
*_bin_len = len / 2; *_bin_len = len / 2;
for (int i = 0; i < len / 2; i++) { for (int i = 0; i < len / 2; i++) {
int high = char2int((char)_hex[i * 2]); int high = char2int((char) _hex[i * 2]);
int low = char2int((char)_hex[i * 2 + 1]); int low = char2int((char) _hex[i * 2 + 1]);
if (high < 0 || low < 0) { if (high < 0 || low < 0) {
return false; return false;
...@@ -123,8 +122,8 @@ bool hex2carray(const char * _hex, uint64_t *_bin_len, ...@@ -123,8 +122,8 @@ bool hex2carray(const char * _hex, uint64_t *_bin_len,
} }
bool hex2carray2(const char * _hex, uint64_t *_bin_len, bool hex2carray2(const char *_hex, uint64_t *_bin_len,
uint8_t* _bin, const int _max_length ) { uint8_t *_bin, const int _max_length) {
int len = strnlen(_hex, _max_length);//2 * BUF_LEN); int len = strnlen(_hex, _max_length);//2 * BUF_LEN);
...@@ -135,8 +134,8 @@ bool hex2carray2(const char * _hex, uint64_t *_bin_len, ...@@ -135,8 +134,8 @@ bool hex2carray2(const char * _hex, uint64_t *_bin_len,
*_bin_len = len / 2; *_bin_len = len / 2;
for (int i = 0; i < len / 2; i++) { for (int i = 0; i < len / 2; i++) {
int high = char2int((char)_hex[i * 2]); int high = char2int((char) _hex[i * 2]);
int low = char2int((char)_hex[i * 2 + 1]); int low = char2int((char) _hex[i * 2 + 1]);
if (high < 0 || low < 0) { if (high < 0 || low < 0) {
return false; return false;
...@@ -149,8 +148,8 @@ bool hex2carray2(const char * _hex, uint64_t *_bin_len, ...@@ -149,8 +148,8 @@ bool hex2carray2(const char * _hex, uint64_t *_bin_len,
} }
bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t _n, size_t _signerIndex, bool sign(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, size_t _n, size_t _signerIndex,
char* _sig) { char *_sig) {
//cerr << "ENTER SIGN" << endl; //cerr << "ENTER SIGN" << endl;
...@@ -160,7 +159,7 @@ bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t ...@@ -160,7 +159,7 @@ bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t
uint64_t binLen; uint64_t binLen;
if (!hex2carray(_hashHex, &binLen, hash->data())){ if (!hex2carray(_hashHex, &binLen, hash->data())) {
throw RPCException(INVALID_HEX, "Invalid hash"); throw RPCException(INVALID_HEX, "Invalid hash");
} }
// assert(binLen == hash->size()); // assert(binLen == hash->size());
...@@ -190,8 +189,8 @@ bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t ...@@ -190,8 +189,8 @@ bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t
return true; return true;
} }
bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t _n, size_t _signerIndex, bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, size_t _n, size_t _signerIndex,
char* _sig) { char *_sig) {
//cerr << "ENTER SIGN" << endl; //cerr << "ENTER SIGN" << endl;
...@@ -201,7 +200,7 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz ...@@ -201,7 +200,7 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
uint64_t binLen; uint64_t binLen;
if (!hex2carray(_hashHex, &binLen, hash->data())){ if (!hex2carray(_hashHex, &binLen, hash->data())) {
throw RPCException(INVALID_HEX, "Invalid hash"); throw RPCException(INVALID_HEX, "Invalid hash");
} }
// assert(binLen == hash->size()); // assert(binLen == hash->size());
...@@ -227,14 +226,14 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz ...@@ -227,14 +226,14 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
int errStatus = 0; int errStatus = 0;
string* xStr = FqToString(&(hash_with_hint.first.X)); string *xStr = FqToString(&(hash_with_hint.first.X));
if (xStr == nullptr) { if (xStr == nullptr) {
std::cerr << "Null xStr" << std::endl; std::cerr << "Null xStr" << std::endl;
BOOST_THROW_EXCEPTION(runtime_error("Null xStr")); BOOST_THROW_EXCEPTION(runtime_error("Null xStr"));
} }
string* yStr = FqToString(&(hash_with_hint.first.Y)); string *yStr = FqToString(&(hash_with_hint.first.Y));
if (yStr == nullptr) { if (yStr == nullptr) {
std::cerr << "Null yStr" << std::endl; std::cerr << "Null yStr" << std::endl;
...@@ -247,7 +246,7 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz ...@@ -247,7 +246,7 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
char xStrArg[BUF_LEN]; char xStrArg[BUF_LEN];
char yStrArg[BUF_LEN]; char yStrArg[BUF_LEN];
char signature [BUF_LEN]; char signature[BUF_LEN];
memset(xStrArg, 0, BUF_LEN); memset(xStrArg, 0, BUF_LEN);
memset(yStrArg, 0, BUF_LEN); memset(yStrArg, 0, BUF_LEN);
...@@ -273,7 +272,7 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz ...@@ -273,7 +272,7 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
cerr <<"SGX enclave call to bls_sign_message failed:" << status << std::endl; cerr << "SGX enclave call to bls_sign_message failed:" << status << std::endl;
BOOST_THROW_EXCEPTION(runtime_error("SGX enclave call to bls_sign_message failed")); BOOST_THROW_EXCEPTION(runtime_error("SGX enclave call to bls_sign_message failed"));
} }
...@@ -303,18 +302,17 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz ...@@ -303,18 +302,17 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
return true; return true;
} }
bool bls_sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t _n, size_t _signerIndex, bool bls_sign(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, size_t _n, size_t _signerIndex,
char* _sig) { char *_sig) {
if (!encryptKeys){ if (!encryptKeys) {
return sign(_encryptedKeyHex, _hashHex, _t, _n, _signerIndex, _sig); return sign(_encryptedKeyHex, _hashHex, _t, _n, _signerIndex, _sig);
} } else {
else{
return sign_aes(_encryptedKeyHex, _hashHex, _t, _n, _signerIndex, _sig); return sign_aes(_encryptedKeyHex, _hashHex, _t, _n, _signerIndex, _sig);
} }
} }
char* encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key) { char *encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key) {
auto keyArray = make_shared<vector<char>>(BUF_LEN, 0); auto keyArray = make_shared<vector<char>>(BUF_LEN, 0);
auto encryptedKey = make_shared<vector<uint8_t>>(BUF_LEN, 0); auto encryptedKey = make_shared<vector<uint8_t>>(BUF_LEN, 0);
auto errMsg = make_shared<vector<char>>(BUF_LEN, 0); auto errMsg = make_shared<vector<char>>(BUF_LEN, 0);
...@@ -326,10 +324,9 @@ char* encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key) ...@@ -326,10 +324,9 @@ char* encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key)
//status = encrypt_key(eid, errStatus, errMsg, keyArray, encryptedKey, &encryptedLen); //status = encrypt_key(eid, errStatus, errMsg, keyArray, encryptedKey, &encryptedLen);
status = encrypt_key_aes(eid, errStatus, errMsg->data(), keyArray->data(), encryptedKey->data(), &encryptedLen); status = encrypt_key_aes(eid, errStatus, errMsg->data(), keyArray->data(), encryptedKey->data(), &encryptedLen);
if (printDebugInfo) { spdlog::debug("errStatus is {}", *errStatus);
spdlog::debug("errStatus is {}",*errStatus); spdlog::debug(" errMsg is ", errMsg->data());
spdlog::debug(" errMsg is ", errMsg->data() );
}
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
......
...@@ -36,24 +36,22 @@ ...@@ -36,24 +36,22 @@
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "common.h" #include "common.h"
vector<string> SplitString(const char* koefs, const char symbol){ vector<string> SplitString(const char *koefs, const char symbol) {
string str(koefs); string str(koefs);
string delim; string delim;
delim.push_back(symbol); delim.push_back(symbol);
vector<string> G2_strings; vector<string> G2_strings;
size_t prev = 0, pos = 0; size_t prev = 0, pos = 0;
do do {
{
pos = str.find(delim, prev); pos = str.find(delim, prev);
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 koef(token.c_str());
G2_strings.push_back(koef); G2_strings.push_back(koef);
} }
prev = pos + delim.length(); prev = pos + delim.length();
} } while (pos < str.length() && prev < str.length());
while (pos < str.length() && prev < str.length());
return G2_strings; return G2_strings;
} }
...@@ -65,9 +63,9 @@ string ConvertToString(T field_elem, int base = 10) { ...@@ -65,9 +63,9 @@ string ConvertToString(T field_elem, int base = 10) {
field_elem.as_bigint().to_mpz(t); field_elem.as_bigint().to_mpz(t);
char arr[mpz_sizeinbase (t, base) + 2]; char arr[mpz_sizeinbase(t, base) + 2];
char * tmp = mpz_get_str(arr, base, t); char *tmp = mpz_get_str(arr, base, t);
mpz_clear(t); mpz_clear(t);
string output = tmp; string output = tmp;
...@@ -75,7 +73,7 @@ string ConvertToString(T field_elem, int base = 10) { ...@@ -75,7 +73,7 @@ string ConvertToString(T field_elem, int base = 10) {
return output; return output;
} }
string gen_dkg_poly( int _t){ string gen_dkg_poly(int _t) {
vector<char> errMsg(1024, 0); vector<char> errMsg(1024, 0);
int err_status = 0; int err_status = 0;
...@@ -84,27 +82,25 @@ string gen_dkg_poly( int _t){ ...@@ -84,27 +82,25 @@ string gen_dkg_poly( int _t){
uint32_t enc_len = 0; uint32_t enc_len = 0;
if (!encryptKeys) if (!encryptKeys)
status = gen_dkg_secret (eid, &err_status, errMsg.data(), encrypted_dkg_secret.data(), &enc_len, _t); status = gen_dkg_secret(eid, &err_status, errMsg.data(), encrypted_dkg_secret.data(), &enc_len, _t);
else else
status = gen_dkg_secret_aes (eid, &err_status, errMsg.data(), encrypted_dkg_secret.data(), &enc_len, _t); status = gen_dkg_secret_aes(eid, &err_status, errMsg.data(), encrypted_dkg_secret.data(), &enc_len, _t);
if ( err_status != 0){ if (err_status != 0) {
throw RPCException(-666, errMsg.data() ) ; throw RPCException(-666, errMsg.data());
} }
if (printDebugInfo) {
spdlog::debug("gen_dkg_secret, status {}", err_status, " err msg ", errMsg.data()); spdlog::debug("gen_dkg_secret, status {}", err_status, " err msg ", errMsg.data());
spdlog::debug("in DKGCrypto encr len is {}", enc_len); spdlog::debug("in DKGCrypto encr len is {}", enc_len);
}
uint64_t length = DKG_MAX_SEALED_LEN; uint64_t length = DKG_MAX_SEALED_LEN;
if (encryptKeys){ if (encryptKeys) {
length = enc_len; length = enc_len;
} }
//vector<char> hexEncrPoly(DKG_MAX_SEALED_LEN * 2 + 1, 0);//(4*BUF_LEN, 1); //vector<char> hexEncrPoly(DKG_MAX_SEALED_LEN * 2 + 1, 0);//(4*BUF_LEN, 1);
vector<char> hexEncrPoly(2 * length + 1, 0); vector<char> hexEncrPoly(2 * length + 1, 0);
assert( encrypted_dkg_secret.size() >= length); assert(encrypted_dkg_secret.size() >= length);
//carray2Hex(encrypted_dkg_secret.data(), DKG_MAX_SEALED_LEN, hexEncrPoly.data()); //carray2Hex(encrypted_dkg_secret.data(), DKG_MAX_SEALED_LEN, hexEncrPoly.data());
carray2Hex(encrypted_dkg_secret.data(), length, hexEncrPoly.data()); carray2Hex(encrypted_dkg_secret.data(), length, hexEncrPoly.data());
string result(hexEncrPoly.data()); string result(hexEncrPoly.data());
...@@ -112,39 +108,34 @@ string gen_dkg_poly( int _t){ ...@@ -112,39 +108,34 @@ string gen_dkg_poly( int _t){
return result; return result;
} }
vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int n){ vector<vector<string>> get_verif_vect(const char *encryptedPolyHex, int t, int n) {
char* errMsg1 = (char*) calloc(1024,1); char *errMsg1 = (char *) calloc(1024, 1);
//char errMsg1[BUF_LEN]; //char errMsg1[BUF_LEN];
int err_status = 0; int err_status = 0;
if (printDebugInfo) {
// cerr << "got encr poly " << encryptedPolyHex << endl; // cerr << "got encr poly " << encryptedPolyHex << endl;
spdlog::debug("got encr poly size {}", char_traits<char>::length(encryptedPolyHex)); spdlog::debug("got encr poly size {}", char_traits<char>::length(encryptedPolyHex));
}
char* public_shares = (char*)calloc(10000, 1);
char *public_shares = (char *) calloc(10000, 1);
memset(public_shares, 0, 10000); memset(public_shares, 0, 10000);
// char public_shares[10000]; // char public_shares[10000];
uint64_t enc_len = 0; uint64_t enc_len = 0;
uint8_t* encr_dkg_poly = (uint8_t*) calloc(DKG_MAX_SEALED_LEN * 2, 1); uint8_t *encr_dkg_poly = (uint8_t *) calloc(DKG_MAX_SEALED_LEN * 2, 1);
memset(encr_dkg_poly, 0, DKG_MAX_SEALED_LEN * 2); memset(encr_dkg_poly, 0, DKG_MAX_SEALED_LEN * 2);
//uint8_t encr_dkg_poly[DKG_MAX_SEALED_LEN]; //uint8_t encr_dkg_poly[DKG_MAX_SEALED_LEN];
if (!hex2carray2(encryptedPolyHex, &enc_len, encr_dkg_poly, 6100)){ if (!hex2carray2(encryptedPolyHex, &enc_len, encr_dkg_poly, 6100)) {
throw RPCException(INVALID_HEX, "Invalid encryptedPolyHex"); throw RPCException(INVALID_HEX, "Invalid encryptedPolyHex");
} }
if (printDebugInfo) {
//cerr << "hex_encr_poly is " << encryptedPolyHex << std::endl; //cerr << "hex_encr_poly is " << encryptedPolyHex << std::endl;
spdlog::debug("hex_encr_poly length is {}", strlen(encryptedPolyHex)); spdlog::debug("hex_encr_poly length is {}", strlen(encryptedPolyHex));
spdlog::debug("enc len {}", enc_len); spdlog::debug("enc len {}", enc_len);
// cerr << "encr raw poly: " << endl;
// for ( int i = 0 ; i < 3050; i++)
// printf(" %d ", encr_dkg_poly[i] );
}
uint32_t len = 0; uint32_t len = 0;
...@@ -154,25 +145,21 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int ...@@ -154,25 +145,21 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
status = get_public_shares_aes(eid, &err_status, errMsg1, encr_dkg_poly, enc_len, public_shares, t, n); status = get_public_shares_aes(eid, &err_status, errMsg1, encr_dkg_poly, enc_len, public_shares, t, n);
} }
if ( err_status != 0){ if (err_status != 0) {
throw RPCException(-666, errMsg1 ); throw RPCException(-666, errMsg1);
} }
if (printDebugInfo) {
spdlog::debug("err msg is {}", errMsg1); spdlog::debug("err msg is {}", errMsg1);
spdlog::debug("public_shares:"); spdlog::debug("public_shares:");
spdlog::debug("{}", public_shares); spdlog::debug("{}", public_shares);;
// cerr << "public_shares:" << endl;
// cerr << public_shares << endl;
spdlog::debug("get_public_shares status: {}", err_status); spdlog::debug("get_public_shares status: {}", err_status);
//printf("\nget_public_shares status: %d error %s \n\n", err_status, errMsg1);
}
vector <string> G2_strings = SplitString( public_shares, ','); vector<string> G2_strings = SplitString(public_shares, ',');
vector <vector <string>> pub_shares_vect; vector<vector<string>> pub_shares_vect;
for ( uint64_t i = 0; i < G2_strings.size(); i++){ for (uint64_t i = 0; i < G2_strings.size(); i++) {
vector <string> koef_str = SplitString(G2_strings.at(i).c_str(), ':'); vector<string> koef_str = SplitString(G2_strings.at(i).c_str(), ':');
pub_shares_vect.push_back(koef_str); pub_shares_vect.push_back(koef_str);
} }
...@@ -183,7 +170,8 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int ...@@ -183,7 +170,8 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
return pub_shares_vect; return pub_shares_vect;
} }
string get_secret_shares(const string& polyName, const char* encryptedPolyHex, const vector<string>& publicKeys, int t, int n){ string get_secret_shares(const string &polyName, const char *encryptedPolyHex, const vector<string> &publicKeys, int t,
int n) {
//char* errMsg1 = (char*) calloc(1024,1); //char* errMsg1 = (char*) calloc(1024,1);
char errMsg1[BUF_LEN]; char errMsg1[BUF_LEN];
int err_status = 0; int err_status = 0;
...@@ -194,7 +182,7 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c ...@@ -194,7 +182,7 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
// uint8_t* encr_dkg_poly = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1); // uint8_t* encr_dkg_poly = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1);
uint8_t encr_dkg_poly[DKG_MAX_SEALED_LEN]; uint8_t encr_dkg_poly[DKG_MAX_SEALED_LEN];
memset(encr_dkg_poly, 0, DKG_MAX_SEALED_LEN); memset(encr_dkg_poly, 0, DKG_MAX_SEALED_LEN);
if(!hex2carray2(encryptedPolyHex, &enc_len, encr_dkg_poly, 6100)){ if (!hex2carray2(encryptedPolyHex, &enc_len, encr_dkg_poly, 6100)) {
throw RPCException(INVALID_HEX, "Invalid encryptedPolyHex"); throw RPCException(INVALID_HEX, "Invalid encryptedPolyHex");
} }
...@@ -205,14 +193,14 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c ...@@ -205,14 +193,14 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
else else
status = set_encrypted_dkg_poly_aes(eid, &err_status, errMsg1, encr_dkg_poly, &enc_len); status = set_encrypted_dkg_poly_aes(eid, &err_status, errMsg1, encr_dkg_poly, &enc_len);
if ( status != SGX_SUCCESS || err_status != 0){ if (status != SGX_SUCCESS || err_status != 0) {
throw RPCException(-666, errMsg1 ); throw RPCException(-666, errMsg1);
} }
string result; string result;
//char *hexEncrKey = (char *) calloc(2 * BUF_LEN, 1); //char *hexEncrKey = (char *) calloc(2 * BUF_LEN, 1);
for ( int i = 0; i < n; i++){ for (int i = 0; i < n; i++) {
uint8_t encryptedSkey[BUF_LEN]; uint8_t encryptedSkey[BUF_LEN];
memset(encryptedSkey, 0, BUF_LEN); memset(encryptedSkey, 0, BUF_LEN);
uint32_t dec_len; uint32_t dec_len;
...@@ -226,53 +214,41 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c ...@@ -226,53 +214,41 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
char pubKeyB[129]; char pubKeyB[129];
strncpy(pubKeyB, pub_keyB.c_str(), 128); strncpy(pubKeyB, pub_keyB.c_str(), 128);
pubKeyB[128] = 0; pubKeyB[128] = 0;
if (printDebugInfo) {
spdlog::debug("pubKeyB is {}", pub_keyB); spdlog::debug("pubKeyB is {}", pub_keyB);
}
if (!encryptKeys) if (!encryptKeys)
get_encr_sshare(eid, &err_status, errMsg1, encryptedSkey, &dec_len, get_encr_sshare(eid, &err_status, errMsg1, encryptedSkey, &dec_len,
cur_share, s_shareG2, pubKeyB, t, n, i + 1 ); cur_share, s_shareG2, pubKeyB, t, n, i + 1);
else else
get_encr_sshare_aes(eid, &err_status, errMsg1, encryptedSkey, &dec_len, get_encr_sshare_aes(eid, &err_status, errMsg1, encryptedSkey, &dec_len,
cur_share, s_shareG2, pubKeyB, t, n, i + 1 ); cur_share, s_shareG2, pubKeyB, t, n, i + 1);
if (err_status != 0){ if (err_status != 0) {
throw RPCException(-666, errMsg1); throw RPCException(-666, errMsg1);
} }
if (printDebugInfo) {
spdlog::debug("cur_share is {}", cur_share); spdlog::debug("cur_share is {}", cur_share);
}
result += cur_share; result += cur_share;
//uint32_t enc_len = BUF_LEN;
if (printDebugInfo) {
spdlog::debug("dec len is {}", dec_len); spdlog::debug("dec len is {}", dec_len);
}
carray2Hex(encryptedSkey, dec_len, hexEncrKey); carray2Hex(encryptedSkey, dec_len, hexEncrKey);
string dhKeyName = "DKG_DH_KEY_" + polyName + "_" + to_string(i) + ":"; string dhKeyName = "DKG_DH_KEY_" + polyName + "_" + to_string(i) + ":";
spdlog::debug("hexEncr DH Key: { }" , hexEncrKey); spdlog::debug("hexEncr DH Key: { }", hexEncrKey);
SGXWalletServer::writeDataToDB(dhKeyName, hexEncrKey); SGXWalletServer::writeDataToDB(dhKeyName, hexEncrKey);
string shareG2_name = "shareG2_" + polyName + "_" + to_string(i) + ":"; string shareG2_name = "shareG2_" + polyName + "_" + to_string(i) + ":";
if (printDebugInfo) {
spdlog::debug("name to write to db is {}", dhKeyName); spdlog::debug("name to write to db is {}", dhKeyName);
spdlog::debug("name to write to db is {}", shareG2_name); spdlog::debug("name to write to db is {}", shareG2_name);
spdlog::debug("s_shareG2: {}", s_shareG2); spdlog::debug("s_shareG2: {}", s_shareG2);
}
SGXWalletServer::writeDataToDB(shareG2_name, s_shareG2); SGXWalletServer::writeDataToDB(shareG2_name, s_shareG2);
if (printDebugInfo) {
spdlog::debug("errMsg: {}", errMsg1); spdlog::debug("errMsg: {}", errMsg1);
// cerr << "iteration " << i <<" result length is " << result.length() << endl ;
// cerr << "iteration " << i <<" share length is " << strlen(cur_share) << endl;
// cerr << "iteration " << i <<" share is " << cur_share << endl;
}
} }
//result += '\0'; //result += '\0';
...@@ -283,28 +259,28 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c ...@@ -283,28 +259,28 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
return result; return result;
} }
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) {
//char* errMsg1 = (char*) calloc(1024,1); //char* errMsg1 = (char*) calloc(1024,1);
char errMsg1[BUF_LEN]; char errMsg1[BUF_LEN];
int err_status = 0; int err_status = 0;
uint64_t dec_key_len ; uint64_t dec_key_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, &dec_key_len, encr_key)) {
throw RPCException(INVALID_HEX, "Invalid encryptedPolyHex"); throw RPCException(INVALID_HEX, "Invalid encryptedPolyHex");
} }
int result; int result;
if (printDebugInfo) {
cerr << "encryptedKeyHex " << encryptedKeyHex << endl; cerr << "encryptedKeyHex " << encryptedKeyHex << endl;
cerr << "dec_key_len " << dec_key_len << endl; cerr << "dec_key_len " << dec_key_len << endl;
cerr << "encr_sshare length is " << strlen(encr_sshare) << endl; cerr << "encr_sshare length is " << strlen(encr_sshare) << endl;
//cerr << "public shares " << publicShares << endl; //cerr << "public shares " << publicShares << endl;
spdlog::debug("publicShares length is {}", char_traits<char>::length(publicShares)); spdlog::debug("publicShares length is {}", char_traits<char>::length(publicShares));
}
char pshares[8193]; char pshares[8193];
memset(pshares, 0, 8193); memset(pshares, 0, 8193);
strncpy(pshares, publicShares, strlen(publicShares) ); strncpy(pshares, publicShares, strlen(publicShares));
if (!encryptKeys) if (!encryptKeys)
...@@ -312,34 +288,32 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char ...@@ -312,34 +288,32 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
else else
dkg_verification_aes(eid, &err_status, errMsg1, pshares, encr_sshare, encr_key, dec_key_len, t, ind, &result); dkg_verification_aes(eid, &err_status, errMsg1, pshares, encr_sshare, encr_key, dec_key_len, t, ind, &result);
if (result == 2){ if (result == 2) {
throw RPCException(INVALID_HEX, "Invalid public shares"); throw RPCException(INVALID_HEX, "Invalid public shares");
} }
if (printDebugInfo) {
spdlog::debug("errMsg1: {}", errMsg1); spdlog::debug("errMsg1: {}", errMsg1);
spdlog::debug("result is: {}", result); spdlog::debug("result is: {}", result);
}
//free(errMsg1); //free(errMsg1);
return result; return result;
} }
bool CreateBLSShare( const string& blsKeyName, const char * s_shares, const char * encryptedKeyHex){ bool CreateBLSShare(const string &blsKeyName, const char *s_shares, const char *encryptedKeyHex) {
if (printDebugInfo) {
spdlog::debug("ENTER CreateBLSShare"); spdlog::debug("ENTER CreateBLSShare");
}
// char* errMsg1 = (char*) calloc(1024,1); // char* errMsg1 = (char*) calloc(1024,1);
char errMsg1[BUF_LEN]; char errMsg1[BUF_LEN];
int err_status = 0; int err_status = 0;
uint64_t dec_key_len ; uint64_t dec_key_len;
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, &dec_key_len, encr_key)) {
throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex"); throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex");
} }
...@@ -351,13 +325,12 @@ bool CreateBLSShare( const string& blsKeyName, const char * s_shares, const char ...@@ -351,13 +325,12 @@ bool CreateBLSShare( const string& blsKeyName, const char * s_shares, const char
else else
create_bls_key_aes(eid, &err_status, errMsg1, s_shares, encr_key, dec_key_len, encr_bls_key, &enc_bls_len); create_bls_key_aes(eid, &err_status, errMsg1, s_shares, encr_key, dec_key_len, encr_bls_key, &enc_bls_len);
//cerr << "AFTER create_bls_key IN ENCLAVE er msg is " << errMsg1 << endl; //cerr << "AFTER create_bls_key IN ENCLAVE er msg is " << errMsg1 << endl;
if ( err_status != 0){ if (err_status != 0) {
//spdlog::info("ERROR IN ENCLAVE with status {}", err_status); //spdlog::info("ERROR IN ENCLAVE with status {}", err_status);
spdlog::error(errMsg1); spdlog::error(errMsg1);
spdlog::error("status {}", err_status); spdlog::error("status {}", err_status);
throw RPCException(ERROR_IN_ENCLAVE, "Create BLS private key failed in enclave"); throw RPCException(ERROR_IN_ENCLAVE, "Create BLS private key failed in enclave");
} } else {
else {
//char *hexBLSKey = (char *) calloc(2 * BUF_LEN, 1); //char *hexBLSKey = (char *) calloc(2 * BUF_LEN, 1);
char hexBLSKey[2 * BUF_LEN]; char hexBLSKey[2 * BUF_LEN];
...@@ -366,89 +339,84 @@ bool CreateBLSShare( const string& blsKeyName, const char * s_shares, const char ...@@ -366,89 +339,84 @@ bool CreateBLSShare( const string& blsKeyName, const char * s_shares, const char
carray2Hex(encr_bls_key, enc_bls_len, hexBLSKey); carray2Hex(encr_bls_key, enc_bls_len, hexBLSKey);
// cerr << "BEFORE WRITE BLS KEY TO DB" << endl; // cerr << "BEFORE WRITE BLS KEY TO DB" << endl;
SGXWalletServer::writeDataToDB(blsKeyName, hexBLSKey); SGXWalletServer::writeDataToDB(blsKeyName, hexBLSKey);
if (printDebugInfo) {
spdlog::debug("hexBLSKey length is {}", char_traits<char>::length(hexBLSKey)); spdlog::debug("hexBLSKey length is {}", char_traits<char>::length(hexBLSKey));
spdlog::debug("bls key {}", blsKeyName, " is ", hexBLSKey ); spdlog::debug("bls key {}", blsKeyName, " is ", hexBLSKey);
}
//free(hexBLSKey); //free(hexBLSKey);
return true; return true;
} }
} }
vector<string> GetBLSPubKey(const char * encryptedKeyHex){ vector<string> GetBLSPubKey(const char *encryptedKeyHex) {
//char* errMsg1 = (char*) calloc(1024,1); //char* errMsg1 = (char*) calloc(1024,1);
char errMsg1[BUF_LEN]; char errMsg1[BUF_LEN];
int err_status = 0; int err_status = 0;
uint64_t dec_key_len ; uint64_t dec_key_len;
uint8_t encr_key[BUF_LEN]; uint8_t encr_key[BUF_LEN];
if (!hex2carray(encryptedKeyHex, &dec_key_len, encr_key)){ if (!hex2carray(encryptedKeyHex, &dec_key_len, encr_key)) {
throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex"); throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex");
} }
char pub_key[320]; char pub_key[320];
if (printDebugInfo) {
spdlog::debug("dec_key_len is {}", dec_key_len); spdlog::debug("dec_key_len is {}", dec_key_len);
}
if (!encryptKeys) if (!encryptKeys)
get_bls_pub_key(eid, &err_status, errMsg1, encr_key, dec_key_len, pub_key); get_bls_pub_key(eid, &err_status, errMsg1, encr_key, dec_key_len, pub_key);
else else
get_bls_pub_key_aes(eid, &err_status, errMsg1, encr_key, dec_key_len, pub_key); get_bls_pub_key_aes(eid, &err_status, errMsg1, encr_key, dec_key_len, pub_key);
if ( err_status != 0){ if (err_status != 0) {
std::cerr << errMsg1 << " status is " << err_status << std::endl; std::cerr << errMsg1 << " status is " << err_status << std::endl;
throw RPCException(ERROR_IN_ENCLAVE, "Failed to get BLS public key in enclave"); throw RPCException(ERROR_IN_ENCLAVE, "Failed to get BLS public key in enclave");
} }
vector<string> pub_key_vect = SplitString(pub_key, ':'); vector<string> pub_key_vect = SplitString(pub_key, ':');
if (printDebugInfo) {
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("{}", pub_key_vect.at(i));
}
return pub_key_vect; return pub_key_vect;
} }
string decrypt_DHKey(const string& polyName, int ind){ string decrypt_DHKey(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> hexEncrKey_ptr = SGXWalletServer::readFromDb(DH_key_name, "DKG_DH_KEY_");
if (printDebugInfo) {
spdlog::debug("encr DH key is {}", *hexEncrKey_ptr); spdlog::debug("encr DH key is {}", *hexEncrKey_ptr);
}
vector<char> hexEncrKey(2 * BUF_LEN, 0); vector<char> hexEncrKey(2 * BUF_LEN, 0);
uint64_t DH_enc_len = 0; uint64_t DH_enc_len = 0;
uint8_t encrypted_DHkey[BUF_LEN]; uint8_t encrypted_DHkey[BUF_LEN];
if (!hex2carray(hexEncrKey_ptr->c_str(), &DH_enc_len, encrypted_DHkey)){ if (!hex2carray(hexEncrKey_ptr->c_str(), &DH_enc_len, encrypted_DHkey)) {
throw RPCException(INVALID_HEX, "Invalid hexEncrKey"); throw RPCException(INVALID_HEX, "Invalid hexEncrKey");
} }
if (printDebugInfo) {
spdlog::debug("encr DH key length is {}", DH_enc_len); spdlog::debug("encr DH key length is {}", DH_enc_len);
spdlog::debug("hex encr DH key length is {}", hexEncrKey_ptr->length()); spdlog::debug("hex encr DH key length is {}", hexEncrKey_ptr->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(), encrypted_DHkey, DH_enc_len, 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(), encrypted_DHkey, DH_enc_len, DHKey);
if (err_status != 0){ if (err_status != 0) {
throw RPCException(/*ERROR_IN_ENCLAVE*/ err_status, "decrypt key failed in enclave"); throw RPCException(/*ERROR_IN_ENCLAVE*/ err_status, "decrypt key failed in enclave");
} }
return DHKey; return DHKey;
} }
vector<string> mult_G2(const string& x){ vector<string> mult_G2(const string &x) {
vector<string> result(4); vector<string> result(4);
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
libff::alt_bn128_Fr el(x.c_str()); libff::alt_bn128_Fr el(x.c_str());
......
...@@ -61,13 +61,10 @@ std::vector<std::string> genECDSAKey() { ...@@ -61,13 +61,10 @@ std::vector<std::string> genECDSAKey() {
throw RPCException(status, errMsg); throw RPCException(status, errMsg);
} }
std::vector<std::string> keys(3); std::vector<std::string> keys(3);
if (printDebugInfo) {
std::cerr << "account key is " << errMsg << std::endl; std::cerr << "account key is " << errMsg << std::endl;
std::cerr << "enc_len is " << enc_len << std::endl; std::cerr << "enc_len is " << enc_len << std::endl;
// std::cerr << "enc_key is " << std::endl;
// for(int i = 0 ; i < 1024; i++)
// std::cerr << (int)encr_pr_key[i] << " " ;
}
char *hexEncrKey = (char *) calloc(BUF_LEN * 2, 1); char *hexEncrKey = (char *) calloc(BUF_LEN * 2, 1);
carray2Hex(encr_pr_key, enc_len, hexEncrKey); carray2Hex(encr_pr_key, enc_len, hexEncrKey);
keys.at(0) = hexEncrKey; keys.at(0) = hexEncrKey;
...@@ -77,10 +74,8 @@ std::vector<std::string> genECDSAKey() { ...@@ -77,10 +74,8 @@ std::vector<std::string> genECDSAKey() {
unsigned long seed = randGen(); unsigned long seed = randGen();
if (printDebugInfo) {
spdlog::debug("seed is {}", seed); spdlog::debug("seed is {}", seed);
std::cerr << "strlen is " << strlen(hexEncrKey) << std::endl; std::cerr << "strlen is " << strlen(hexEncrKey) << std::endl;
}
gmp_randstate_t state; gmp_randstate_t state;
gmp_randinit_default(state); gmp_randinit_default(state);
...@@ -133,13 +128,12 @@ std::string getECDSAPubKey(const char *_encryptedKeyHex) { ...@@ -133,13 +128,12 @@ std::string getECDSAPubKey(const char *_encryptedKeyHex) {
} }
string pubKey = string(pubKeyX.data()) + string(pubKeyY.data());//concatPubKeyWith0x(pub_key_x, pub_key_y);// string pubKey = string(pubKeyX.data()) + string(pubKeyY.data());//concatPubKeyWith0x(pub_key_x, pub_key_y);//
if (printDebugInfo) {
spdlog::debug("enc_len is {}", enc_len); spdlog::debug("enc_len is {}", enc_len);
spdlog::debug("pubkey is {}", pubKey); spdlog::debug("pubkey is {}", pubKey);
spdlog::debug("pubkey length is {}", pubKey.length()); spdlog::debug("pubkey length is {}", pubKey.length());
spdlog::debug("err str is {}", errMsg.data()); spdlog::debug("err str is {}", errMsg.data());
spdlog::debug("err status is {}", err_status); spdlog::debug("err status is {}", err_status);
}
return pubKey; return pubKey;
} }
......
...@@ -62,10 +62,10 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) { ...@@ -62,10 +62,10 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) {
auto status = db->Get(readOptions, _key, &*result); auto status = db->Get(readOptions, _key, &*result);
if (printDebugInfo) {
spdlog::debug("key to read from db: {}",_key ); spdlog::debug("key to read from db: {}",_key );
//std::cerr << "key to read from db: " << _key << std::endl; //std::cerr << "key to read from db: " << _key << std::endl;
}
throwExceptionOnError(status); throwExceptionOnError(status);
...@@ -83,10 +83,10 @@ void LevelDB::writeString(const string &_key, const string &_value) { ...@@ -83,10 +83,10 @@ void LevelDB::writeString(const string &_key, const string &_value) {
throwExceptionOnError(status); throwExceptionOnError(status);
if (printDebugInfo) {
spdlog::debug("written key: {}",_key ); spdlog::debug("written key: {}",_key );
// std::cerr << "written key " << _key << std::endl; // std::cerr << "written key " << _key << std::endl;
}
} }
...@@ -100,10 +100,9 @@ void LevelDB::deleteDHDKGKey (const string &_key) { ...@@ -100,10 +100,9 @@ void LevelDB::deleteDHDKGKey (const string &_key) {
throwExceptionOnError(status); throwExceptionOnError(status);
if (printDebugInfo) {
spdlog::debug("key deleted: {}",full_key ); spdlog::debug("key deleted: {}",full_key );
//std::cerr << "key deleted " << full_key << std::endl; //std::cerr << "key deleted " << full_key << std::endl;
}
} }
void LevelDB::deleteTempNEK(const string &_key){ void LevelDB::deleteTempNEK(const string &_key){
...@@ -130,10 +129,9 @@ void LevelDB::deleteKey(const string &_key){ ...@@ -130,10 +129,9 @@ void LevelDB::deleteKey(const string &_key){
throwExceptionOnError(status); throwExceptionOnError(status);
if (printDebugInfo) {
spdlog::debug("key deleted: {}",_key ); spdlog::debug("key deleted: {}",_key );
// std::cerr << "key deleted " << _key << std::endl; // std::cerr << "key deleted " << _key << std::endl;
}
} }
...@@ -219,10 +217,9 @@ void LevelDB::writeDataUnique(const string & Name, const string &value) { ...@@ -219,10 +217,9 @@ void LevelDB::writeDataUnique(const string & Name, const string &value) {
} }
writeString(key, value); writeString(key, value);
if (printDebugInfo) {
spdlog::debug("{}",Name, " is written to db"); spdlog::debug("{}",Name, " is written to db");
//std::cerr << Name << " is written to db " << std::endl;
}
} }
......
...@@ -231,8 +231,6 @@ void init_SEK(){ ...@@ -231,8 +231,6 @@ void init_SEK(){
gen_SEK(); gen_SEK();
} }
else{ else{
if (printDebugInfo)
spdlog::info("going to set SEK from db" );
set_SEK(encr_SEK_ptr); set_SEK(encr_SEK_ptr);
} }
} }
......
...@@ -77,9 +77,8 @@ void initEnclave() { ...@@ -77,9 +77,8 @@ void initEnclave() {
} }
#endif #endif
if (printDebugInfo) {
spdlog::debug("SGX_DEBUG_FLAG = {}", SGX_DEBUG_FLAG); spdlog::debug("SGX_DEBUG_FLAG = {}", SGX_DEBUG_FLAG);
}
status = sgx_create_enclave_search(ENCLAVE_NAME, SGX_DEBUG_FLAG, &token, status = sgx_create_enclave_search(ENCLAVE_NAME, SGX_DEBUG_FLAG, &token,
&updated, &eid, 0); &updated, &eid, 0);
......
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