Unverified Commit 05a5f2df authored by svetaro's avatar svetaro

SKALE-1512-add-DKG-to-SGX Add method getVerificationVector to server

parent af2844db
......@@ -83,7 +83,31 @@ bool hex2carray(const char * _hex, uint64_t *_bin_len,
}
bool hex2carray2(const char * _hex, uint64_t *_bin_len,
uint8_t* _bin, const int _max_length ) {
int len = strnlen(_hex, _max_length);//2 * BUF_LEN);
if (len == 0 && len % 2 == 1)
return false;
*_bin_len = len / 2;
for (int i = 0; i < len / 2; i++) {
int high = char2int((char)_hex[i * 2]);
int low = char2int((char)_hex[i * 2 + 1]);
if (high < 0 || low < 0) {
return false;
}
_bin[i] = (unsigned char) (high * 16 + low);
}
return true;
}
bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t _n, size_t _signerIndex,
......
......@@ -26,6 +26,8 @@ EXTERNC int char2int(char _input);
EXTERNC void carray2Hex(const unsigned char *d, int _len, char* _hexArray);
EXTERNC bool hex2carray(const char * _hex, uint64_t *_bin_len,
uint8_t* _bin );
EXTERNC bool hex2carray2(const char * _hex, uint64_t *_bin_len,
uint8_t* _bin, const int _max_length );
......
......@@ -7,24 +7,93 @@
#include "sgxwallet.h"
#include <iostream>
std::vector<std::string> SplitString(const char* koefs, const char symbol){
std::string str(koefs);
std::string delim;
delim.push_back(symbol);
std::vector<std::string> G2_strings;
size_t prev = 0, pos = 0;
do
{
pos = str.find(delim, prev);
if (pos == std::string::npos) pos = str.length();
std::string token = str.substr(prev, pos-prev);
if (!token.empty()) {
std::string koef(token.c_str());
G2_strings.push_back(koef);
}
prev = pos + delim.length();
}
while (pos < str.length() && prev < str.length());
return G2_strings;
}
std::string gen_dkg_poly( int _t){
char *errMsg = (char *)calloc(1024, 1);
int err_status = 0;
uint8_t* encrypted_dkg_secret = (uint8_t *)calloc(2000, 1);
uint8_t* encrypted_dkg_secret = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1);;
uint32_t enc_len = 0;
status = gen_dkg_secret (eid, &err_status, errMsg, encrypted_dkg_secret, &enc_len, _t);
char *hexEncrPoly = (char *) calloc(4*BUF_LEN, 1);
carray2Hex(encrypted_dkg_secret, enc_len, hexEncrPoly);
/* std::cerr << "encr raw poly: " << std::endl;
for ( int i = 0 ; i < 3050; i++)
printf(" %d ", encrypted_dkg_secret[i] );*/
char *hexEncrPoly = (char *) calloc(DKG_MAX_SEALED_LEN * 2 + 1, 1);//(4*BUF_LEN, 1);
carray2Hex(encrypted_dkg_secret, DKG_MAX_SEALED_LEN, hexEncrPoly);
std::string result(hexEncrPoly);
//std::cerr << "in DKGCrypto encr key x " << << std::endl;
std::cerr << "in DKGCrypto encr len is " << enc_len << std::endl;
free(errMsg);
free(encrypted_dkg_secret);
free(hexEncrPoly);
return result;
}
std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyHex, int n, int t){
char* errMsg1 = (char*) calloc(1024,1);
int err_status = 0;
// std::cerr << "got encr poly " << encryptedPolyHex << std::endl;
std::cerr << "got encr poly size " << strlen(encryptedPolyHex) << std::endl;
char* public_shares = (char*)calloc(10000, 1);
uint64_t enc_len = 0;
uint8_t* encr_dkg_poly = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1);
hex2carray2(encryptedPolyHex, &enc_len, encr_dkg_poly, 6100);
std::cerr << "enc len " << enc_len << std::endl;
/*std::cerr << "encr raw poly: " << std::endl;
for ( int i = 0 ; i < 3050; i++)
printf(" %d ", encr_dkg_poly[i] );*/
uint32_t len;
status = get_public_shares(eid, &err_status, errMsg1, encr_dkg_poly, len, public_shares, t, n);
std::cerr << "err msg " << errMsg1 << std::endl;
std::cerr << "public_shares:" << std::endl;
std::cerr << public_shares << std::endl;
printf("\nget_public_shares status: %d error %s \n\n", err_status, errMsg1);
std::vector <std::string> G2_strings = SplitString( public_shares, ',');
std::vector <std::vector <std::string>> pub_shares_vect;
for ( int i = 0; i < G2_strings.size(); i++){
std::vector <std::string> koef_str = SplitString(G2_strings.at(i).c_str(), ':');
pub_shares_vect.push_back(koef_str);
}
free(errMsg1);
free(public_shares);
free(encr_dkg_poly);
return pub_shares_vect;
}
\ No newline at end of file
......@@ -6,7 +6,12 @@
#define SGXD_DKGCRYPTO_H
#include <string>
#include <vector>
std::string gen_dkg_poly( int _t);
std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyHex, int n, int t);
std::vector<std::string> SplitString(const char* koefs, const char symbol);
#endif //SGXD_DKGCRYPTO_H
......@@ -263,10 +263,45 @@ Json::Value generateDKGPolyImpl(const std::string& polyName, int t) {
return result;
}
Json::Value getVerificationVectorImpl(const std::string& polyName, int n, int t) {
Json::Value result;
result["status"] = 0;
result["errorMessage"] = "";
std::vector <std::vector<std::string>> verifVector;
try {
std::shared_ptr<std::string> encr_poly_ptr = readFromDb(polyName, "DKGPoly:");
verifVector = get_verif_vect(encr_poly_ptr->c_str(), n, t);
std::cerr << "verif vect size " << verifVector.size() << std::endl;
} catch (RPCException &_e) {
std::cerr << " err str " << _e.errString << std::endl;
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
result["Verification Vector"] = "";
}
for ( int i = 0; i < t; i++){
std::vector<std::string> cur_coef = verifVector.at(i);
string num = std::to_string(i);
result["Verification Vector"][i][num]["X"]["c0"] = cur_coef.at(0);
result["Verification Vector"][i][num]["X"]["c1"] = cur_coef.at(1);
result["Verification Vector"][i][num]["Y"]["c0"] = cur_coef.at(2);
result["Verification Vector"][i][num]["Y"]["c1"] = cur_coef.at(3);
}
return result;
}
Json::Value SGXWalletServer::generateDKGPoly(const std::string& polyName, int t){
return generateDKGPolyImpl(polyName, t);
}
Json::Value SGXWalletServer::getVerificationVector(const std::string& polyName, int n, int t){
return getVerificationVectorImpl(polyName, n, t);
}
Json::Value SGXWalletServer::generateECDSAKey(const std::string &_keyName) {
return generateECDSAKeyImpl(_keyName);
}
......@@ -299,6 +334,17 @@ Json::Value SGXWalletServer::importECDSAKey(const std::string &key, const std::s
}
shared_ptr<string> readFromDb(const string & name, const string & prefix) {
auto dataStr = levelDb->readString(prefix + name);
if (dataStr == nullptr) {
throw RPCException(KEY_SHARE_DOES_NOT_EXIST, "Data with this name does not exists");
}
return dataStr;
}
shared_ptr<string> readKeyShare(const string &_keyShareName) {
auto keyShareStr = levelDb->readString("BLSKEYSHARE:" + _keyShareName);
......
......@@ -27,10 +27,12 @@ public:
virtual Json::Value getPublicECDSAKey(const std::string& keyName);
virtual Json::Value generateDKGPoly(const std::string& polyName, int t);
virtual Json::Value getVerificationVector(const std::string& polyName, int n, int t);
};
shared_ptr<string> readFromDb(const string & name, const string & prefix);
void writeKeyShare(const string &_keyShareName, const string &value, int index, int n, int t);
shared_ptr<std::string> readKeyShare(const string& _keyShare);
......@@ -50,5 +52,6 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string& keyName, const
Json::Value getPublicECDSAKeyImpl(const std::string& keyName);
Json::Value generateDKGPolyImpl(const std::string& polyName, int t);
Json::Value getVerificationVectorImpl(const std::string& polyName, int n, int t);
#endif //SGXWALLET_SGXWALLETSERVER_HPP
\ No newline at end of file
......@@ -18,7 +18,8 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
this->bindAndAddMethod(jsonrpc::Procedure("generateECDSAKey", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "keyName",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::generateECDSAKeyI);
this->bindAndAddMethod(jsonrpc::Procedure("getPublicECDSAKey", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "keyName",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::getPublicECDSAKeyI);
this->bindAndAddMethod(jsonrpc::Procedure("ecdsaSignMessageHash", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "base",jsonrpc::JSON_INTEGER,"keyName",jsonrpc::JSON_STRING,"messageHash",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::ecdsaSignMessageHashI);
this->bindAndAddMethod(jsonrpc::Procedure("generateDKGPoly", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "keyName",jsonrpc::JSON_STRING,"t",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::generateDKGPolyI);
this->bindAndAddMethod(jsonrpc::Procedure("generateDKGPoly", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING,"t",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::generateDKGPolyI);
this->bindAndAddMethod(jsonrpc::Procedure("getVerificationVector", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING,"n",jsonrpc::JSON_INTEGER,"t",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::getVerificationVectorI);
}
inline virtual void importBLSKeyShareI(const Json::Value &request, Json::Value &response)
......@@ -47,7 +48,11 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
}
inline virtual void generateDKGPolyI(const Json::Value &request, Json::Value &response)
{
response = this->generateDKGPoly(request["keyName"].asString(), request["t"].asInt());
response = this->generateDKGPoly(request["polyName"].asString(), request["t"].asInt());
}
inline virtual void getVerificationVectorI(const Json::Value &request, Json::Value &response)
{
response = this->getVerificationVector(request["polyName"].asString(), request["n"].asInt(),request["t"].asInt());
}
virtual Json::Value importBLSKeyShare(int index, const std::string& keyShare, const std::string& keyShareName, int n, int t) = 0;
virtual Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int n, int signerIndex, int t) = 0;
......@@ -55,7 +60,8 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
virtual Json::Value generateECDSAKey(const std::string& keyName) = 0;
virtual Json::Value getPublicECDSAKey(const std::string& keyName) = 0;
virtual Json::Value ecdsaSignMessageHash(int base, const std::string& keyName, const std::string& messageHash) = 0;
virtual Json::Value generateDKGPoly(const std::string& keyName, int t) = 0;
virtual Json::Value generateDKGPoly(const std::string& polyName, int t) = 0;
virtual Json::Value getVerificationVector(const std::string& polyName, int n, int t) = 0;
};
#endif //JSONRPC_CPP_STUB_ABSTRACTSTUBSERVER_H_
......@@ -112,10 +112,12 @@ void calc_secret_shares(const char* decrypted_koefs, char * secret_shares,
result += ":";
}
strncpy(secret_shares, result.c_str(), result.length());
//strncpy(secret_shares, decrypted_koefs, 3650);
}
void calc_public_shares(const char* decrypted_koefs, char * public_shares,
unsigned _t) {
libff::init_alt_bn128_params();
// calculate for each node a list of public shares
std::string result;
char symbol = ':';
......@@ -133,6 +135,7 @@ void calc_public_shares(const char* decrypted_koefs, char * public_shares,
result += ",";
}
strncpy(public_shares, result.c_str(), result.length());
//strncpy(public_shares, decrypted_koefs, 10000);
}
......@@ -430,32 +430,58 @@ void gen_dkg_secret (int *err_status, char *err_string, uint8_t *encrypted_dkg_s
free(dkg_secret);
}
void decrypt_dkg_secret (int *err_status, char* err_string, uint8_t* encrypted_dkg_secret, uint8_t* decrypted_dkg_secret, uint32_t enc_len){
void decrypt_dkg_secret (int *err_status, char* err_string, uint8_t* encrypted_dkg_secret, uint8_t* decrypted_dkg_secret, uint32_t* dec_len){
//uint32_t dec_size = DKG_BUFER_LENGTH;//sgx_get_encrypt_txt_len( ( sgx_sealed_data_t *)encrypted_dkg_secret);
uint32_t decr_len;
sgx_status_t status = sgx_unseal_data(
(const sgx_sealed_data_t *)encrypted_dkg_secret, NULL, 0, decrypted_dkg_secret, &enc_len);
(const sgx_sealed_data_t *)encrypted_dkg_secret, NULL, 0, decrypted_dkg_secret, &decr_len);
if (status != SGX_SUCCESS) {
snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status %d", status);
return;
}
*dec_len = decr_len;
}
void get_secret_shares(int *err_status, char* err_string, uint8_t* encrypted_dkg_secret, uint32_t enc_len, char* secret_shares,
void get_secret_shares(int *err_status, char* err_string, uint8_t* encrypted_dkg_secret, uint32_t* dec_len, char* secret_shares,
unsigned _t, unsigned _n){
char* decrypted_dkg_secret = (char*)malloc(DKG_MAX_SEALED_LEN);
decrypt_dkg_secret(err_status, err_string, (uint8_t*)encrypted_dkg_secret, decrypted_dkg_secret, enc_len);
calc_secret_shares(decrypted_dkg_secret, secret_shares, _t, _n);
char* decrypted_dkg_secret = (char*)malloc(DKG_BUFER_LENGTH);
//char decrypted_dkg_secret[DKG_MAX_SEALED_LEN];
uint32_t decr_len ;
//uint32_t* decr_len_test = (char*)malloc(1);
decrypt_dkg_secret(err_status, err_string, encrypted_dkg_secret, (uint8_t*)decrypted_dkg_secret, &decr_len);
//sgx_status_t status = sgx_unseal_data(
// (const sgx_sealed_data_t *)encrypted_dkg_secret, NULL, 0, (uint8_t*)decrypted_dkg_secret, &decr_len);
if (*err_status != 0) {
snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status %d", *err_status);
return;
}
*dec_len = decr_len;
// strncpy(err_string, decrypted_dkg_secret, 1024);
calc_secret_shares(decrypted_dkg_secret, secret_shares, _t, _n);
free(decrypted_dkg_secret);
}
void get_public_shares(int *err_status, char* err_string, uint8_t* encrypted_dkg_secret, uint32_t enc_len, char* public_shares,
unsigned _t, unsigned _n){
char* decrypted_dkg_secret = (char*)malloc(DKG_MAX_SEALED_LEN);
decrypt_dkg_secret(err_status, err_string, (uint8_t*)encrypted_dkg_secret, decrypted_dkg_secret, enc_len);
strncpy(err_string, decrypted_dkg_secret, 1024);
uint32_t decr_len ;
decrypt_dkg_secret(err_status, err_string, (uint8_t*)encrypted_dkg_secret, decrypted_dkg_secret, &decr_len);
if( *err_status != 0 ){
snprintf(err_string, BUF_LEN,"decrypt_dkg_secret failed with status %d", *err_status);
return;
}
//strncpy(err_string, decrypted_dkg_secret, 1024);
// strncpy(err_string, "before calc_public_shares ", 1024);
calc_public_shares(decrypted_dkg_secret, public_shares, _t);
free(decrypted_dkg_secret);
}
void ecdsa_sign1(int *err_status, char *err_string, uint8_t *encrypted_key, uint32_t dec_len,
......
......@@ -63,30 +63,30 @@ enclave {
public void gen_dkg_secret (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[out, count = 3650] uint8_t* encrypted_dkg_secret,
[out, count = 3050] uint8_t* encrypted_dkg_secret,
[user_check] uint32_t * enc_len,
size_t _t);
public void decrypt_dkg_secret (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[in, count = 3650] uint8_t* encrypted_dkg_secret,
[out, count = 3650] uint8_t* decrypted_dkg_secret,
uint32_t enc_len);
[in, count = 3050] uint8_t* encrypted_dkg_secret,
[out, count = 2490] uint8_t* decrypted_dkg_secret,
[user_check] uint32_t* dec_len);
public void get_secret_shares (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[in, count = 3650] uint8_t* encrypted_dkg_secret,
uint32_t enc_len,
[out, count = 3650] char* secret_shares,
[in, count = 3050] uint8_t* encrypted_dkg_secret,
[user_check] uint32_t* dec_len,
[out, count = 2490] char* secret_shares,
unsigned _t,
unsigned _n);
public void get_public_shares (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[in, count = 3650] uint8_t* decrypted_dkg_secret,
[in, count = 3050] uint8_t* decrypted_dkg_secret,
uint32_t enc_len,
[out, count = 10000] char* public_shares,
unsigned _t,
......
......@@ -26,8 +26,8 @@
#define ADD_ENTROPY_SIZE 32
#define DKG_BUFER_LENGTH 3060
#define DKG_MAX_SEALED_LEN 3650
#define DKG_BUFER_LENGTH 2490//3060
#define DKG_MAX_SEALED_LEN 3050
#define ECDSA_SKEY_LEN 65
#define ECDSA_SKEY_BASE 16
......
......@@ -89,12 +89,27 @@
{
"name": "generateDKGPoly",
"params": {
"keyName": "key1",
"polyName": "key1",
"t": 3
},
"returns": {
"status": 0,
"errorMessage": "12345"
}
},
{
"name": "getVerificationVector",
"params": {
"polyName": "key1",
"n": 3,
"t": 3
},
"returns": {
"status": 0,
"errorMessage": "12345",
"Verification Vector": [{},{}]
}
}
]
\ No newline at end of file
......@@ -83,10 +83,10 @@ class StubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value generateDKGPoly(const std::string& keyName, int t) throw (jsonrpc::JsonRpcException)
Json::Value generateDKGPoly(const std::string& polyName, int t) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["keyName"] = keyName;
p["polyName"] = polyName;
p["t"] = t;
Json::Value result = this->CallMethod("generateDKGPoly",p);
if (result.isObject())
......@@ -94,6 +94,18 @@ class StubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value getVerificationVector(const std::string& polyName, int n, int t) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["polyName"] = polyName;
p["n"] = n;
p["t"] = t;
Json::Value result = this->CallMethod("getVerificationVector",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
};
#endif //JSONRPC_CPP_STUB_STUBCLIENT_H_
......@@ -56,6 +56,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "BLSCrypto.h"
#include "ServerInit.h"
#include "DKGCrypto.h"
#include "RPCException.h"
#include "LevelDB.h"
......@@ -273,15 +274,18 @@ TEST_CASE( "DKG gen test", "[dkg-gen]" ) {
printf("gen_dkg_secret completed with status: %d %s \n", err_status, errMsg);
printf("\n Length: %d \n", enc_len);
char* secret = (char*)calloc(DKG_MAX_SEALED_LEN, sizeof(char));
char* secret = (char*)calloc(DKG_BUFER_LENGTH, sizeof(char));
char* errMsg1 = (char*) calloc(1024,1);
status = decrypt_dkg_secret(eid, &err_status, errMsg1, encrypted_dkg_secret, (uint8_t*)secret, enc_len);
uint32_t dec_len;
status = decrypt_dkg_secret(eid, &err_status, errMsg1, encrypted_dkg_secret, (uint8_t*)secret, &dec_len);
REQUIRE(status == SGX_SUCCESS);
printf("\ndecrypt_dkg_secret completed with status: %d %s \n", err_status, errMsg1);
printf("decrypted secret %s \n\n", secret);
printf ("secret length %d \n", strlen(secret));
printf ("decr length %d \n", dec_len);
free(errMsg);
free(errMsg1);
......@@ -313,7 +317,7 @@ std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* koefs, const char s
return tokens;
}
std::vector<std::string> SplitString(const char* koefs, const char symbol){
std::vector<std::string> SplitStringTest(const char* koefs, const char symbol){
libff::init_alt_bn128_params();
std::string str(koefs);
std::string delim;
......@@ -352,9 +356,11 @@ libff::alt_bn128_G2 VectStringToG2(const std::vector<std::string>& G2_str_vect){
TEST_CASE( "DKG secret shares test", "[dkg-s_shares]" ) {
libff::init_alt_bn128_params();
//init_all();
init_enclave();
libff::init_alt_bn128_params();
uint8_t* encrypted_dkg_secret = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1);
char* errMsg = (char*) calloc(1024,1);
......@@ -367,40 +373,45 @@ libff::alt_bn128_G2 VectStringToG2(const std::vector<std::string>& G2_str_vect){
REQUIRE(status == SGX_SUCCESS);
printf("gen_dkg_secret completed with status: %d %s \n", err_status, errMsg);
printf("\n Length: %d \n", enc_len);
/* printf("encr_dkg_secret: \n");
for ( int i = 0 ; i < enc_len; i++)
printf(" %d ", encrypted_dkg_secret[i]);*/
char* errMsg1 = (char*) calloc(1024,1);
char colon = ':';
char* secret_shares = (char*)calloc(DKG_MAX_SEALED_LEN, 1);
status = get_secret_shares(eid, &err_status, errMsg1, encrypted_dkg_secret, enc_len, secret_shares, t, n);
char* secret_shares = (char*)calloc(DKG_BUFER_LENGTH, sizeof(char));
uint32_t dec_len = enc_len;
// status = decrypt_dkg_secret(eid, &err_status, errMsg1, encrypted_dkg_secret, (uint8_t*)secret_shares, &dec_len);
status = get_secret_shares(eid, &err_status, errMsg1, encrypted_dkg_secret, &dec_len, secret_shares, t, n);
REQUIRE(status == SGX_SUCCESS);
printf("\nget_secret_shares status: %d %s \n", err_status, errMsg1);
printf("secret shares %s \n\n", secret_shares);
std::vector <libff::alt_bn128_Fr> s_shares = SplitStringToFr( secret_shares, colon);
char* secret = (char*)calloc(DKG_MAX_SEALED_LEN, sizeof(char));
status = decrypt_dkg_secret(eid, &err_status, errMsg1, encrypted_dkg_secret, (uint8_t*)secret, enc_len);
REQUIRE(status == SGX_SUCCESS);
// printf("\ndecrypt_dkg_secret completed with status: %d %s \n", err_status, errMsg1);
signatures::Dkg dkg_obj(t,n);
std::vector < libff::alt_bn128_Fr> poly = SplitStringToFr((char*)secret, colon);
std::vector < libff::alt_bn128_Fr> s_shares_dkg = dkg_obj.SecretKeyContribution(SplitStringToFr((char*)secret, colon));
printf("calculated secret length %d : \n", s_shares_dkg.size());
for ( int i = 0; i < s_shares_dkg.size(); i++){
libff::alt_bn128_Fr cur_share = s_shares_dkg.at(i);
mpz_t(sshare);
mpz_init(sshare);
cur_share.as_bigint().to_mpz(sshare);
char arr[mpz_sizeinbase (sshare, 10) + 2];
char* share_str = mpz_get_str(arr, 10, sshare);
printf(" %s \n", share_str);
mpz_clear(sshare);
}
REQUIRE(s_shares == s_shares_dkg);
char* secret = (char*)calloc(DKG_BUFER_LENGTH, sizeof(char));
status = decrypt_dkg_secret(eid, &err_status, errMsg1, encrypted_dkg_secret, (uint8_t*)secret, &dec_len);
REQUIRE(status == SGX_SUCCESS);
//printf("\ndecrypt_dkg_secret completed with status: %d %s \n", err_status, errMsg1);
signatures::Dkg dkg_obj(t,n);
std::vector < libff::alt_bn128_Fr> poly = SplitStringToFr((char*)secret, colon);
std::vector < libff::alt_bn128_Fr> s_shares_dkg = dkg_obj.SecretKeyContribution(SplitStringToFr((char*)secret, colon));
printf("calculated secret length %d : \n", s_shares_dkg.size());
for ( int i = 0; i < s_shares_dkg.size(); i++){
libff::alt_bn128_Fr cur_share = s_shares_dkg.at(i);
mpz_t(sshare);
mpz_init(sshare);
cur_share.as_bigint().to_mpz(sshare);
char arr[mpz_sizeinbase (sshare, 10) + 2];
char* share_str = mpz_get_str(arr, 10, sshare);
printf(" %s \n", share_str);
mpz_clear(sshare);
}
REQUIRE(s_shares == s_shares_dkg);
free(errMsg);
free(errMsg1);
......@@ -413,6 +424,7 @@ libff::alt_bn128_G2 VectStringToG2(const std::vector<std::string>& G2_str_vect){
TEST_CASE( "DKG public shares test", "[dkg-pub_shares]" ) {
//init_all();
libff::init_alt_bn128_params();
init_enclave();
uint8_t* encrypted_dkg_secret = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1);
......@@ -424,7 +436,7 @@ TEST_CASE( "DKG public shares test", "[dkg-pub_shares]" ) {
status = gen_dkg_secret (eid, &err_status, errMsg, encrypted_dkg_secret, &enc_len, n);
REQUIRE(status == SGX_SUCCESS);
// printf("gen_dkg_public completed with status: %d %s \n", err_status, errMsg);
//printf("gen_dkg_public completed with status: %d %s \n", err_status, errMsg);
char* errMsg1 = (char*) calloc(1024,1);
......@@ -433,20 +445,22 @@ TEST_CASE( "DKG public shares test", "[dkg-pub_shares]" ) {
char* public_shares = (char*)calloc(10000, 1);
status = get_public_shares(eid, &err_status, errMsg1, encrypted_dkg_secret, enc_len, public_shares, t, n);
REQUIRE(status == SGX_SUCCESS);
//printf("\nget_public_shares status: %d error %s \n\n", err_status, errMsg1);
printf("\nget_public_shares status: %d error %s \n\n", err_status, errMsg1);
printf(" LEN: %d \n", strlen(public_shares));
printf(" result: %s \n", public_shares);
std::vector <std::string> G2_strings = SplitString( public_shares, ',');
std::vector <libff::alt_bn128_G2> pub_shares_G2;
for ( int i = 0; i < G2_strings.size(); i++){
std::vector <std::string> koef_str = SplitString(G2_strings.at(i).c_str(), ':');
libff::alt_bn128_G2 el = VectStringToG2(koef_str);
// std::cerr << "pub_share G2 " << i+1 << " : " << std::endl;
// el.print_coordinates();
//std::cerr << "pub_share G2 " << i+1 << " : " << std::endl;
//el.print_coordinates();
pub_shares_G2.push_back(VectStringToG2(koef_str));
}
char* secret = (char*)calloc(DKG_MAX_SEALED_LEN, sizeof(char));
status = decrypt_dkg_secret(eid, &err_status, errMsg1, encrypted_dkg_secret, (uint8_t*)secret, enc_len);
status = decrypt_dkg_secret(eid, &err_status, errMsg1, encrypted_dkg_secret, (uint8_t*)secret, &enc_len);
REQUIRE(status == SGX_SUCCESS);
printf("\ndecrypt_dkg_secret completed with status: %d %s \n", err_status, errMsg1);
......@@ -624,11 +638,10 @@ using namespace std;
TEST_CASE("API test", "[api_test]") {
cerr << "API test started" << endl;
init_all();
//HttpServer httpserver(1025);
//SGXWalletServer s(httpserver,
// JSONRPC_SERVER_V1); // hybrid server (json-rpc 1.0 & 2.0)
// s.StartListening();
// JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
// s.StartListening();
cerr << "Server inited" << endl;
HttpClient client("http://localhost:1025");
StubClient c(client, JSONRPC_CLIENT_V2);
......@@ -639,8 +652,9 @@ TEST_CASE("API test", "[api_test]") {
// cout << c.generateECDSAKey("known_key1") << endl;
//cout<<c.getPublicECDSAKey("test_key");
//cout << c.ecdsaSignMessageHash(16, "known_key1","0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db" );
cout << c.blsSignMessageHash(TEST_BLS_KEY_NAME, "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db", 2,2,1 );
//cout << c.generateDKGPoly("poly", 3);
// cout << c.blsSignMessageHash(TEST_BLS_KEY_NAME, "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db", 2,2,1 );
// cout << c.generateDKGPoly("polyy", 5);
cout << c.getVerificationVector("polyy", 5, 5);
} catch (JsonRpcException &e) {
cerr << e.what() << endl;
}
......
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