Unverified Commit 91168a5e authored by svetaro's avatar svetaro

SKALE-2003 Add gen_dkg_poly_aes method

parent e45107a8
...@@ -706,11 +706,21 @@ Json::Value MultG2Impl(const std::string& x){ ...@@ -706,11 +706,21 @@ Json::Value MultG2Impl(const std::string& x){
Json::Value IsPolyExistsImpl(const std::string& polyName){ Json::Value IsPolyExistsImpl(const std::string& polyName){
Json::Value result; Json::Value result;
try {
std::shared_ptr<std::string> poly_str_ptr = levelDb->readString(polyName); std::shared_ptr<std::string> poly_str_ptr = levelDb->readString(polyName);
result["IsExist"] = true; result["IsExist"] = true;
result["status"] = 0;
result["errorMessage"] = "";
if (poly_str_ptr == nullptr){ if (poly_str_ptr == nullptr){
result["IsExist"] = false; result["IsExist"] = false;
result["status"] = 0;
result["errorMessage"] = "";
}
} catch (RPCException &_e) {
std::cerr << " err str " << _e.errString << std::endl;
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
result["IsExist"] = false;
} }
return result; return result;
......
...@@ -1276,8 +1276,29 @@ void bls_sign_message_aes(int *err_status, char *err_string, uint8_t *encrypted_ ...@@ -1276,8 +1276,29 @@ void bls_sign_message_aes(int *err_status, char *err_string, uint8_t *encrypted_
*err_status = -1; *err_status = -1;
return; return;
} }
}
void gen_dkg_secret_aes (int *err_status, char *err_string, uint8_t *encrypted_dkg_secret, uint32_t* enc_len, size_t _t){
char* dkg_secret = (char*)calloc(DKG_BUFER_LENGTH, 1);
if (gen_dkg_poly(dkg_secret, _t) != 0 ){
*err_status = - 1;
return;
}
snprintf(err_string, BUF_LEN,"poly is %s ", dkg_secret);
int status = AES_encrypt(dkg_secret, encrypted_dkg_secret);
if(status != SGX_SUCCESS) {
snprintf(err_string, BUF_LEN,"SGX AES encrypt DKG poly failed");
*err_status = status;
return;
}
*enc_len = strlen(dkg_secret) + SGX_AESGCM_MAC_SIZE + SGX_AESGCM_IV_SIZE;
free(dkg_secret);
} }
...@@ -213,6 +213,7 @@ enclave { ...@@ -213,6 +213,7 @@ enclave {
uint32_t enc_len, uint32_t enc_len,
[out, count = 1024] char* key ); [out, count = 1024] char* key );
public void bls_sign_message_aes ( public void bls_sign_message_aes (
[user_check] int *err_status, [user_check] int *err_status,
[out, count = 1024] char* err_string, [out, count = 1024] char* err_string,
...@@ -221,6 +222,16 @@ enclave { ...@@ -221,6 +222,16 @@ enclave {
[in, count = 1024] char* hashX , [in, count = 1024] char* hashX ,
[in, count = 1024] char* hashY , [in, count = 1024] char* hashY ,
[out, count = 1024] char* signature); [out, count = 1024] char* signature);
public void gen_dkg_secret_aes (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[out, count = 3050] uint8_t* encrypted_dkg_secret,
[user_check] uint32_t * enc_len,
size_t _t);
}; };
......
...@@ -1217,7 +1217,40 @@ TEST_CASE("IsPolyExists test", "[is_poly_test]") { ...@@ -1217,7 +1217,40 @@ TEST_CASE("IsPolyExists test", "[is_poly_test]") {
cout << polyDoesNotExist << std::endl; cout << polyDoesNotExist << std::endl;
REQUIRE(!polyDoesNotExist["IsExist"].asBool()); REQUIRE(!polyDoesNotExist["IsExist"].asBool());
}
TEST_CASE("AES_DKG test", "[aes_dkg]") {
is_sgx_https = 0;
DEBUG_PRINT = 1;
std::cerr << "test started" << std::endl;
init_all(false, false);
cerr << "Server inited" << endl;
HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2);
cerr << "Client inited" << endl;
reset_db();
int n = 4, t = 4;
Json::Value EthKeys[n];
Json::Value VerifVects[n];
Json::Value pubEthKeys;
Json::Value secretShares[n];
Json::Value pubBLSKeys[n];
Json::Value BLSSigShares[n];
std::vector<std::string> pubShares(n);
std::vector<std::string> poly_names(n);
for (uint8_t i = 0; i < n; i++) {
EthKeys[i] = c.generateECDSAKey();
std::string polyName =
"POLY:SCHAIN_ID:1:NODE_ID:" + std::to_string(i) + ":DKG_ID:0";
cout << c.generateDKGPoly(polyName, t);
// poly_names[i] = polyName;
// VerifVects[i] = c.getVerificationVector(polyName, t, n);
// cout << "VV " << i << " " << VerifVects[i] << std::endl;
// pubEthKeys.append(EthKeys[i]["PublicKey"]);
}
} }
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