SKALE-3009 return vector

parent a0d87319
...@@ -75,21 +75,22 @@ int char2int(char _input) { ...@@ -75,21 +75,22 @@ int char2int(char _input) {
return -1; return -1;
} }
void carray2Hex(const unsigned char *d, uint64_t _len, vector<char>& _hexArray) { vector<char> carray2Hex(const unsigned char *d, uint64_t _len) {
CHECK_STATE(d); CHECK_STATE(d);
vector<char> _hexArray( 2 * _len + 1);
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'};
CHECK_STATE(_hexArray.size() > 2 * _len);
for (uint64_t j = 0; j < _len; j++) { for (uint64_t j = 0; j < _len; j++) {
_hexArray[j * 2] = hexval[((d[j] >> 4) & 0xF)]; _hexArray[j * 2] = hexval[((d[j] >> 4) & 0xF)];
_hexArray[j * 2 + 1] = hexval[(d[j]) & 0x0F]; _hexArray[j * 2 + 1] = hexval[(d[j]) & 0x0F];
} }
_hexArray[_len * 2] = 0; _hexArray[_len * 2] = 0;
return _hexArray;
} }
...@@ -262,9 +263,7 @@ string encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key ...@@ -262,9 +263,7 @@ string encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key
HANDLE_TRUSTED_FUNCTION_ERROR(status, *errStatus, errMsg.data()); HANDLE_TRUSTED_FUNCTION_ERROR(status, *errStatus, errMsg.data());
vector<char> resultBuf(2 * BUF_LEN + 1, 0); vector<char> resultBuf = carray2Hex(encryptedKey->data(), encryptedLen);
carray2Hex(encryptedKey->data(), encryptedLen, resultBuf);
return string(resultBuf.begin(), resultBuf.end()); return string(resultBuf.begin(), resultBuf.end());
} }
...@@ -39,7 +39,7 @@ EXTERNC bool bls_sign(const char* encryptedKeyHex, const char* hashHex, size_t t ...@@ -39,7 +39,7 @@ EXTERNC bool bls_sign(const char* encryptedKeyHex, const char* hashHex, size_t t
EXTERNC int char2int(char _input); EXTERNC int char2int(char _input);
EXTERNC void carray2Hex(const unsigned char *d, uint64_t , std::vector<char>& _hexArray); EXTERNC std::vector<char> carray2Hex(const unsigned char *d, uint64_t _len);
EXTERNC bool hex2carray(const char * _hex, uint64_t *_bin_len, EXTERNC bool hex2carray(const char * _hex, uint64_t *_bin_len,
uint8_t* _bin, uint64_t _max_length ); uint8_t* _bin, uint64_t _max_length );
......
...@@ -144,9 +144,8 @@ string gen_dkg_poly(int _t) { ...@@ -144,9 +144,8 @@ string gen_dkg_poly(int _t) {
uint64_t length = enc_len;; uint64_t length = enc_len;;
vector<char> hexEncrPoly(BUF_LEN, 0);
CHECK_STATE(encrypted_dkg_secret.size() >= length); CHECK_STATE(encrypted_dkg_secret.size() >= length);
carray2Hex(encrypted_dkg_secret.data(), length, hexEncrPoly); vector<char> hexEncrPoly = carray2Hex(encrypted_dkg_secret.data(), length);
string result(hexEncrPoly.data()); string result(hexEncrPoly.data());
return result; return result;
...@@ -271,7 +270,7 @@ getSecretShares(const string &_polyName, const char *_encryptedPolyHex, const ve ...@@ -271,7 +270,7 @@ getSecretShares(const string &_polyName, const char *_encryptedPolyHex, const ve
result += string(currentShare.data()); result += string(currentShare.data());
spdlog::debug("dec len is {}", decLen); spdlog::debug("dec len is {}", decLen);
carray2Hex(encryptedSkey.data(), decLen, hexEncrKey); hexEncrKey = carray2Hex(encryptedSkey.data(), decLen);
string dhKeyName = "DKG_DH_KEY_" + _polyName + "_" + to_string(i) + ":"; string dhKeyName = "DKG_DH_KEY_" + _polyName + "_" + to_string(i) + ":";
spdlog::debug("hexEncr DH Key: { }", hexEncrKey.data()); spdlog::debug("hexEncr DH Key: { }", hexEncrKey.data());
...@@ -351,9 +350,7 @@ bool createBLSShare(const string &blsKeyName, const char *s_shares, const char * ...@@ -351,9 +350,7 @@ bool createBLSShare(const string &blsKeyName, const char *s_shares, const char *
HANDLE_TRUSTED_FUNCTION_ERROR(status, errStatus, errMsg.data()); HANDLE_TRUSTED_FUNCTION_ERROR(status, errStatus, errMsg.data());
vector<char> hexBLSKey(2 * BUF_LEN, 0); vector<char> hexBLSKey = carray2Hex(encr_bls_key, enc_bls_len);
carray2Hex(encr_bls_key, enc_bls_len, hexBLSKey);
SGXWalletServer::writeDataToDB(blsKeyName, hexBLSKey.data()); SGXWalletServer::writeDataToDB(blsKeyName, hexBLSKey.data());
......
...@@ -69,18 +69,14 @@ vector <string> genECDSAKey() { ...@@ -69,18 +69,14 @@ vector <string> genECDSAKey() {
vector <string> keys(3); vector <string> keys(3);
vector<char> hexEncrKey(BUF_LEN * 2, 0); vector<char> hexEncrKey = carray2Hex(encr_pr_key.data(), enc_len);
carray2Hex(encr_pr_key.data(), enc_len, hexEncrKey);
keys.at(0) = hexEncrKey.data(); keys.at(0) = hexEncrKey.data();
keys.at(1) = string(pub_key_x.data()) + string(pub_key_y.data()); keys.at(1) = string(pub_key_x.data()) + string(pub_key_y.data());
vector<unsigned char> randBuffer(32, 0); vector<unsigned char> randBuffer(32, 0);
fillRandomBuffer(randBuffer); fillRandomBuffer(randBuffer);
vector<char> rand_str(BUF_LEN, 0); vector<char> rand_str = carray2Hex(randBuffer.data(), 32);
carray2Hex(randBuffer.data(), 32, rand_str);
keys.at(2) = rand_str.data(); keys.at(2) = rand_str.data();
......
...@@ -71,9 +71,7 @@ void create_test_key() { ...@@ -71,9 +71,7 @@ void create_test_key() {
HANDLE_TRUSTED_FUNCTION_ERROR(status, errStatus, errMsg.data()); HANDLE_TRUSTED_FUNCTION_ERROR(status, errStatus, errMsg.data());
vector<char> hexEncrKey(2 * enc_len + 1, 0); vector<char> hexEncrKey = carray2Hex(encrypted_key, enc_len);
carray2Hex(encrypted_key, enc_len, hexEncrKey);
LevelDB::getLevelDb()->writeDataUnique("TEST_KEY", hexEncrKey.data()); LevelDB::getLevelDb()->writeDataUnique("TEST_KEY", hexEncrKey.data());
} }
...@@ -167,9 +165,7 @@ void gen_SEK() { ...@@ -167,9 +165,7 @@ void gen_SEK() {
throw SGXException(-1, "strnlen(SEK,33) != 32"); throw SGXException(-1, "strnlen(SEK,33) != 32");
} }
vector<char> hexEncrKey(2 * enc_len + 1, 0); vector<char> hexEncrKey = carray2Hex(encrypted_SEK.data(), enc_len);
carray2Hex(encrypted_SEK.data(), enc_len, hexEncrKey);
spdlog::info(string("Encrypted storage encryption key:") + hexEncrKey.data()); spdlog::info(string("Encrypted storage encryption key:") + hexEncrKey.data());
...@@ -281,9 +277,7 @@ void enter_SEK() { ...@@ -281,9 +277,7 @@ void enter_SEK() {
auto encrypted_SEK = check_and_set_SEK(sek); auto encrypted_SEK = check_and_set_SEK(sek);
vector<char> hexEncrKey(BUF_LEN, 0); vector<char> hexEncrKey = carray2Hex(encrypted_SEK->data(), encrypted_SEK->size());
carray2Hex(encrypted_SEK->data(), encrypted_SEK->size(), hexEncrKey);
spdlog::info("Got sealed storage encryption key."); spdlog::info("Got sealed storage encryption key.");
......
...@@ -529,7 +529,7 @@ int xorDecryptDH(char *key, const char *cypher, vector<char>& message) { ...@@ -529,7 +529,7 @@ int xorDecryptDH(char *key, const char *cypher, vector<char>& message) {
msg_bin[i] = cypher_bin[i] ^ key_bin[i]; msg_bin[i] = cypher_bin[i] ^ key_bin[i];
} }
carray2Hex((unsigned char*) msg_bin, 32, message); message = carray2Hex((unsigned char*) msg_bin, 32);
ret = 0; ret = 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