SKALE-3009 use vector instead of char

parent 5fe6054f
...@@ -75,14 +75,15 @@ int char2int(char _input) { ...@@ -75,14 +75,15 @@ int char2int(char _input) {
return -1; return -1;
} }
void carray2Hex(const unsigned char *d, uint64_t _len, char *_hexArray) { void carray2Hex(const unsigned char *d, uint64_t _len, vector<char>& _hexArray) {
CHECK_STATE(d); CHECK_STATE(d);
CHECK_STATE(_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'};
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];
...@@ -163,8 +164,7 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz ...@@ -163,8 +164,7 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
CHECK_STATE(_hashHex); CHECK_STATE(_hashHex);
CHECK_STATE(_sig); CHECK_STATE(_sig);
auto hash = make_shared < array < uint8_t, auto hash = make_shared < array < uint8_t, 32 >> ();
32 >> ();
uint64_t binLen; uint64_t binLen;
...@@ -262,9 +262,9 @@ string encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key ...@@ -262,9 +262,9 @@ 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());
SAFE_CHAR_BUF(resultBuf, 2 * BUF_LEN + 1); vector<char> resultBuf(2 * BUF_LEN + 1, 0);
carray2Hex(encryptedKey->data(), encryptedLen, resultBuf); carray2Hex(encryptedKey->data(), encryptedLen, resultBuf);
return string(resultBuf); return string(resultBuf.begin(), resultBuf.end());
} }
...@@ -33,12 +33,13 @@ ...@@ -33,12 +33,13 @@
#include "stddef.h" #include "stddef.h"
#include "stdint.h" #include "stdint.h"
#include <string> #include <string>
#include <vector>
EXTERNC bool bls_sign(const char* encryptedKeyHex, const char* hashHex, size_t t, size_t n, char* _sig); EXTERNC bool bls_sign(const char* encryptedKeyHex, const char* hashHex, size_t t, size_t n, char* _sig);
EXTERNC int char2int(char _input); EXTERNC int char2int(char _input);
EXTERNC void carray2Hex(const unsigned char *d, uint64_t , char* _hexArray); EXTERNC void carray2Hex(const unsigned char *d, uint64_t , std::vector<char>& _hexArray);
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 );
......
...@@ -146,7 +146,7 @@ string gen_dkg_poly(int _t) { ...@@ -146,7 +146,7 @@ string gen_dkg_poly(int _t) {
vector<char> hexEncrPoly(BUF_LEN, 0); 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.data()); carray2Hex(encrypted_dkg_secret.data(), length, hexEncrPoly);
string result(hexEncrPoly.data()); string result(hexEncrPoly.data());
return result; return result;
...@@ -271,7 +271,7 @@ getSecretShares(const string &_polyName, const char *_encryptedPolyHex, const ve ...@@ -271,7 +271,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.data()); carray2Hex(encryptedSkey.data(), decLen, 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.data()); spdlog::debug("hexEncr DH Key: { }", hexEncrKey.data());
...@@ -351,11 +351,11 @@ bool createBLSShare(const string &blsKeyName, const char *s_shares, const char * ...@@ -351,11 +351,11 @@ 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());
SAFE_CHAR_BUF(hexBLSKey, 2 * BUF_LEN) vector<char> hexBLSKey(2 * BUF_LEN, 0);
carray2Hex(encr_bls_key, enc_bls_len, hexBLSKey); carray2Hex(encr_bls_key, enc_bls_len, hexBLSKey);
SGXWalletServer::writeDataToDB(blsKeyName, hexBLSKey); SGXWalletServer::writeDataToDB(blsKeyName, hexBLSKey.data());
return true; return true;
......
...@@ -71,7 +71,7 @@ vector <string> genECDSAKey() { ...@@ -71,7 +71,7 @@ vector <string> genECDSAKey() {
vector<char> hexEncrKey(BUF_LEN * 2, 0); vector<char> hexEncrKey(BUF_LEN * 2, 0);
carray2Hex(encr_pr_key.data(), enc_len, hexEncrKey.data()); 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());
...@@ -80,7 +80,7 @@ vector <string> genECDSAKey() { ...@@ -80,7 +80,7 @@ vector <string> genECDSAKey() {
vector<char> rand_str(BUF_LEN, 0); vector<char> rand_str(BUF_LEN, 0);
carray2Hex(randBuffer.data(), 32, rand_str.data()); carray2Hex(randBuffer.data(), 32, rand_str);
keys.at(2) = rand_str.data(); keys.at(2) = rand_str.data();
......
...@@ -73,7 +73,7 @@ void create_test_key() { ...@@ -73,7 +73,7 @@ void create_test_key() {
vector<char> hexEncrKey(2 * enc_len + 1, 0); vector<char> hexEncrKey(2 * enc_len + 1, 0);
carray2Hex(encrypted_key, enc_len, hexEncrKey.data()); carray2Hex(encrypted_key, enc_len, hexEncrKey);
LevelDB::getLevelDb()->writeDataUnique("TEST_KEY", hexEncrKey.data()); LevelDB::getLevelDb()->writeDataUnique("TEST_KEY", hexEncrKey.data());
} }
...@@ -169,7 +169,7 @@ void gen_SEK() { ...@@ -169,7 +169,7 @@ void gen_SEK() {
vector<char> hexEncrKey(2 * enc_len + 1, 0); vector<char> hexEncrKey(2 * enc_len + 1, 0);
carray2Hex(encrypted_SEK.data(), enc_len, hexEncrKey.data()); 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());
...@@ -283,7 +283,7 @@ void enter_SEK() { ...@@ -283,7 +283,7 @@ void enter_SEK() {
vector<char> hexEncrKey(BUF_LEN, 0); vector<char> hexEncrKey(BUF_LEN, 0);
carray2Hex(encrypted_SEK->data(), encrypted_SEK->size(), hexEncrKey.data()); carray2Hex(encrypted_SEK->data(), encrypted_SEK->size(), hexEncrKey);
spdlog::info("Got sealed storage encryption key."); spdlog::info("Got sealed storage encryption key.");
......
...@@ -493,7 +493,7 @@ int sessionKeyRecoverDH(const char *skey_str, const char *sshare, char *common_k ...@@ -493,7 +493,7 @@ int sessionKeyRecoverDH(const char *skey_str, const char *sshare, char *common_k
return ret; return ret;
} }
int xorDecryptDH(char *key, const char *cypher, char *message) { int xorDecryptDH(char *key, const char *cypher, vector<char>& message) {
int ret = -1; int ret = -1;
...@@ -505,7 +505,7 @@ int xorDecryptDH(char *key, const char *cypher, char *message) { ...@@ -505,7 +505,7 @@ int xorDecryptDH(char *key, const char *cypher, char *message) {
return ret; return ret;
} }
if (!message) { if (!message.data()) {
return ret; return ret;
} }
......
...@@ -80,6 +80,6 @@ public: ...@@ -80,6 +80,6 @@ public:
int sessionKeyRecoverDH(const char *skey_str, const char *sshare, char *common_key); int sessionKeyRecoverDH(const char *skey_str, const char *sshare, char *common_key);
int xorDecryptDH(char *key, const char *cypher, char *message); int xorDecryptDH(char *key, const char *cypher, vector<char>& message);
#endif //SGXWALLET_TESTW_H #endif //SGXWALLET_TESTW_H
...@@ -658,7 +658,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") { ...@@ -658,7 +658,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
string shareG2 = complaintResponse["share*G2"].asString(); string shareG2 = complaintResponse["share*G2"].asString();
string secretShare = secretShares[1]["secretShare"].asString().substr(0, 192); string secretShare = secretShares[1]["secretShare"].asString().substr(0, 192);
SAFE_CHAR_BUF(message, 32) vector<char> message (65, 0);
SAFE_CHAR_BUF(encr_sshare, BUF_LEN) SAFE_CHAR_BUF(encr_sshare, BUF_LEN)
strncpy(encr_sshare, pubEthKeys[0].asString().c_str(), 128); strncpy(encr_sshare, pubEthKeys[0].asString().c_str(), 128);
...@@ -673,7 +673,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") { ...@@ -673,7 +673,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
mpz_t hex_share; mpz_t hex_share;
mpz_init(hex_share); mpz_init(hex_share);
mpz_set_str(hex_share, message, 16); mpz_set_str(hex_share, message.data(), 16);
libff::alt_bn128_Fr share(hex_share); libff::alt_bn128_Fr share(hex_share);
libff::alt_bn128_G2 decrypted_share_G2 = share * libff::alt_bn128_G2::one(); libff::alt_bn128_G2 decrypted_share_G2 = share * libff::alt_bn128_G2::one();
......
...@@ -43,7 +43,6 @@ testList = ["[first-run]", ...@@ -43,7 +43,6 @@ testList = ["[first-run]",
"[bls-key-encrypt]", "[bls-key-encrypt]",
"[dkg-aes-gen]", "[dkg-aes-gen]",
"[dkg-aes-encr-sshares]", "[dkg-aes-encr-sshares]",
"[dkg-verify]",
"[dkg-api]", "[dkg-api]",
"[dkg-bls]", "[dkg-bls]",
"[dkg-poly-exists]", "[dkg-poly-exists]",
......
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