Unverified Commit 1b12bcfd authored by svetaro's avatar svetaro

SKALE-1795 GetPublicBLSKey fixed

parent 93b8db50
...@@ -165,7 +165,7 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr( ...@@ -165,7 +165,7 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
// strncpy(signature, "8175162913343900215959836578795929492705714455632345516427532159927644835012:15265825550804683171644566522808807137117748565649051208189914766494241035855", 1024); // strncpy(signature, "8175162913343900215959836578795929492705714455632345516427532159927644835012:15265825550804683171644566522808807137117748565649051208189914766494241035855", 1024);
printf("---: %s\n", signature); printf("sig is: %s\n", signature);
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
...@@ -301,6 +301,7 @@ std::shared_ptr<BLSSigShare> BLSPrivateKeyShareSGX::signWithHelperSGX( ...@@ -301,6 +301,7 @@ std::shared_ptr<BLSSigShare> BLSPrivateKeyShareSGX::signWithHelperSGX(
std::string signature = signWithHelperSGXstr(hash_byte_arr, _signerIndex); std::string signature = signWithHelperSGXstr(hash_byte_arr, _signerIndex);
auto sig = make_shared<string>(signature); auto sig = make_shared<string>(signature);
//BLSSigShare* sig_test = new BLSSigShare(sig, _signerIndex, requiredSigners, totalSigners); //BLSSigShare* sig_test = new BLSSigShare(sig, _signerIndex, requiredSigners, totalSigners);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <memory> #include <memory>
#include "SGXWalletServer.hpp" #include "SGXWalletServer.hpp"
#include "RPCException.h"
#include <../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp> #include <../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include <../trusted_libff/libff/algebra/fields/fp.hpp> #include <../trusted_libff/libff/algebra/fields/fp.hpp>
...@@ -128,22 +129,25 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted ...@@ -128,22 +129,25 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted
uint32_t dec_len; uint32_t dec_len;
char cur_share[193]; char cur_share[193];
char s_shareG2[320];
std::string pub_keyB = publicKeys.at(i);//publicKeys.substr(128*i, 128*i + 128); std::string pub_keyB = publicKeys.at(i);//publicKeys.substr(128*i, 128*i + 128);
std::cerr << "pub_keyB is " << pub_keyB << std::endl; std::cerr << "pub_keyB is " << pub_keyB << std::endl;
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;
get_encr_sshare(eid, &err_status, errMsg1, encrypted_skey, &dec_len, get_encr_sshare(eid, &err_status, errMsg1, encrypted_skey, &dec_len,
cur_share, pubKeyB, t, n, i + 1 ); cur_share, s_shareG2, pubKeyB, t, n, i + 1 );
result += cur_share; result += cur_share;
uint32_t enc_len = BUF_LEN; uint32_t enc_len = BUF_LEN;
carray2Hex(encrypted_skey, enc_len, hexEncrKey); carray2Hex(encrypted_skey, enc_len, hexEncrKey);
//std::cerr << "hexEncrKey: " << hexEncrKey << std::endl;
std::string name = "DKG_DH_KEY_" + polyName + "_" + std::to_string(i) + ":"; std::string name = "DKG_DH_KEY_" + polyName + "_" + std::to_string(i) + ":";
//writeDataToDB(name, hexEncrKey); std::cerr << "name to write to db is " << name << std::endl;
std::cerr << "hexEncrKey: " << hexEncrKey << std::endl;
// writeDataToDB(name, hexEncrKey);
std::cerr << errMsg1 << std::endl << std::endl; std::cerr << errMsg1 << std::endl << std::endl;
//std::cerr << "iteration " << i <<" result length is " << result.length() << std::endl ; //std::cerr << "iteration " << i <<" result length is " << result.length() << std::endl ;
...@@ -197,9 +201,10 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const ...@@ -197,9 +201,10 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const
uint8_t encr_bls_key[BUF_LEN]; uint8_t encr_bls_key[BUF_LEN];
uint8_t encr_key[BUF_LEN]; uint8_t encr_key[BUF_LEN];
hex2carray(encryptedKeyHex, &dec_key_len, encr_key); hex2carray(encryptedKeyHex, &dec_key_len, encr_key);
uint32_t enc_bls_len = 0;
//std::cerr << " key hex is " << encryptedKeyHex << std::endl; create_bls_key(eid, &err_status, errMsg1, s_shares, encr_key, dec_key_len, encr_bls_key, &enc_bls_len);
create_bls_key(eid, &err_status, errMsg1, s_shares, encr_key, dec_key_len, encr_bls_key);
std::cerr << "er msg is " << errMsg1 << std::endl; std::cerr << "er msg is " << errMsg1 << std::endl;
if ( err_status != 0){ if ( err_status != 0){
...@@ -207,16 +212,19 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const ...@@ -207,16 +212,19 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const
} }
else { else {
char *hexBLSKey = (char *) calloc(2 * BUF_LEN, 1); char *hexBLSKey = (char *) calloc(2 * BUF_LEN, 1);
uint32_t enc_len = BUF_LEN;
carray2Hex(encr_bls_key, enc_len, hexBLSKey); std::cerr << "enc_bls_len " << enc_bls_len << std::endl;
writeDataToDB(BLSKeyName, hexBLSKey); carray2Hex(encr_bls_key, enc_bls_len, hexBLSKey);
writeDataToDB(BLSKeyName, hexBLSKey);
std::cerr << "hexBLSKey length is " << strlen(hexBLSKey) << std::endl;
std::cerr << "bls key " << BLSKeyName << " is " << hexBLSKey << std::endl;
free(hexBLSKey); free(hexBLSKey);
return true; return true;
} }
} }
std::string GetBLSPubKey(const char * encryptedKeyHex){ std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){
char* errMsg1 = (char*) calloc(1024,1); char* errMsg1 = (char*) calloc(1024,1);
int err_status = 0; int err_status = 0;
...@@ -224,11 +232,18 @@ std::string GetBLSPubKey(const char * encryptedKeyHex){ ...@@ -224,11 +232,18 @@ std::string GetBLSPubKey(const char * encryptedKeyHex){
uint8_t encr_bls_key[BUF_LEN]; uint8_t encr_bls_key[BUF_LEN];
uint8_t encr_key[BUF_LEN]; uint8_t encr_key[BUF_LEN];
hex2carray(encryptedKeyHex, &dec_key_len, encr_key); hex2carray(encryptedKeyHex, &dec_key_len, encr_key);
// for ( int i = 0; i < BUF_LEN; i++ )
// std::cerr << encr_key[i] << " ";
char pub_key[320]; char pub_key[320];
std::cerr << "dec_key_len is " << dec_key_len << std::endl;
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);
std::cerr << "errMsg1 is " << errMsg1 << std::endl;
std::string result = pub_key; std::vector<std::string> pub_key_vect = SplitString(pub_key, ':');
std::cerr << "pub key is" << std::endl;
for ( int i = 0; i < 4; i++)
std::cerr << pub_key_vect.at(i) << std::endl;
return pub_key_vect;
} }
std::pair<std::string, std::string> response_to_complaint(const std::string& polyName, const char* encryptedPolyHex, int n, int t, int ind){ std::pair<std::string, std::string> response_to_complaint(const std::string& polyName, const char* encryptedPolyHex, int n, int t, int ind){
...@@ -241,10 +256,11 @@ std::pair<std::string, std::string> response_to_complaint(const std::string& pol ...@@ -241,10 +256,11 @@ std::pair<std::string, std::string> response_to_complaint(const std::string& pol
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);
hex2carray2(encryptedPolyHex, &enc_len, encr_dkg_poly, 6100); hex2carray2(encryptedPolyHex, &enc_len, encr_dkg_poly, 6100);
status = set_encrypted_dkg_poly(eid, &err_status, errMsg1, encr_dkg_poly);
std::string DH_key_name = polyName + "_" + std::to_string(ind) + ":"; std::string DH_key_name = polyName + "_" + std::to_string(ind) + ":";
std::shared_ptr<std::string> hexEncrKey_ptr = readFromDb(DH_key_name, "DKG_DH_KEY_"); std::shared_ptr<std::string> hexEncrKey_ptr = readFromDb(DH_key_name, "DKG_DH_KEY_");
std::cerr << "encr DH key is " << hexEncrKey_ptr << std::endl;
char *hexEncrKey = (char *) calloc(2 * BUF_LEN, 1); char *hexEncrKey = (char *) calloc(2 * BUF_LEN, 1);
...@@ -255,25 +271,25 @@ std::pair<std::string, std::string> response_to_complaint(const std::string& pol ...@@ -255,25 +271,25 @@ std::pair<std::string, std::string> response_to_complaint(const std::string& pol
uint32_t dec_len; uint32_t dec_len;
char decrpyted_DHkey[ECDSA_SKEY_LEN]; char decrpyted_DHkey[ECDSA_SKEY_LEN];
char s_shareG2[257]; char s_shareG2[320];//[257];
status = complaint_response(eid, &err_status, errMsg1, encrypted_DHkey, encr_dkg_poly, &dec_len, status = complaint_response(eid, &err_status, errMsg1, encrypted_DHkey, encr_dkg_poly, &dec_len,
decrpyted_DHkey, s_shareG2, t, n, ind); decrpyted_DHkey, s_shareG2, t, n, ind);
std::pair<std::string, std::string> result; std::pair<std::string, std::string> result;
result.first = decrpyted_DHkey; result.first = decrpyted_DHkey;
result.second = s_shareG2; result.second = s_shareG2;
//std::cerr << errMsg1 << std::endl << std::endl; std::cerr << errMsg1 << std::endl << std::endl;
//std::cerr << "iteration " << i <<" result length is " << result.length() << std::endl ; //std::cerr << "iteration " << i <<" result length is " << result.length() << std::endl ;
//std::cerr << "iteration " << i <<" share length is " << strlen(cur_share) << std::endl; //std::cerr << "iteration " << i <<" share length is " << strlen(cur_share) << std::endl;
//std::cerr << "iteration " << i <<" share is " << cur_share << std::endl; //std::cerr << "iteration " << i <<" share is " << cur_share << std::endl;
//result += '\0';
free(encr_dkg_poly); free(encr_dkg_poly);
free(errMsg1); free(errMsg1);
free(hexEncrKey); free(hexEncrKey);
return result; return result;
} }
\ No newline at end of file
...@@ -22,8 +22,7 @@ std::pair<std::string, std::string> response_to_complaint(const std::string& pol ...@@ -22,8 +22,7 @@ std::pair<std::string, std::string> response_to_complaint(const std::string& pol
bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const char * encryptedKeyHex); bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const char * encryptedKeyHex);
std::string GetBLSPubKey(const char * encryptedKeyHex); std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex);
#endif //SGXD_DKGCRYPTO_H #endif //SGXD_DKGCRYPTO_H
...@@ -115,7 +115,7 @@ Json::Value blsSignMessageHashImpl(const std::string &keyShareName, const std::s ...@@ -115,7 +115,7 @@ Json::Value blsSignMessageHashImpl(const std::string &keyShareName, const std::s
try { try {
value = readKeyShare(keyShareName); value = readFromDb(keyShareName);
} catch (RPCException _e) { } catch (RPCException _e) {
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
...@@ -174,7 +174,8 @@ Json::Value generateECDSAKeyImpl() { ...@@ -174,7 +174,8 @@ Json::Value generateECDSAKeyImpl() {
throw RPCException(UNKNOWN_ERROR, ""); throw RPCException(UNKNOWN_ERROR, "");
} }
// std::cerr << "write encr key" << keys.at(0) << std::endl; // std::cerr << "write encr key" << keys.at(0) << std::endl;
std::string keyName = "tmp_NEK:" + keys.at(2); std::cerr << "encr key length is" << keys.at(0).length() << std::endl;
std::string keyName = "NEK:" + keys.at(2);
//writeECDSAKey(keyName, keys.at(0)); //writeECDSAKey(keyName, keys.at(0));
writeDataToDB(keyName, keys.at(0)); writeDataToDB(keyName, keys.at(0));
...@@ -409,7 +410,6 @@ Json::Value DKGVerificationImpl(const std::string& publicShares, const std::stri ...@@ -409,7 +410,6 @@ Json::Value DKGVerificationImpl(const std::string& publicShares, const std::stri
Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::string& EthKeyName, const std::string& polyName, const std::string & SecretShare, int t, int n){ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::string& EthKeyName, const std::string& polyName, const std::string & SecretShare, int t, int n){
std::cerr << "CreateBLSPrivateKeyImpl entered" << std::endl; std::cerr << "CreateBLSPrivateKeyImpl entered" << std::endl;
std::cerr << " enter DKGVerificationImpl" << std::endl;
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
...@@ -422,7 +422,7 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s ...@@ -422,7 +422,7 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s
return result; return result;
} }
std::vector<std::string> sshares_vect; std::vector<std::string> sshares_vect;
//std::cerr << "sshares are " << std::endl; std::cerr << "sshares are " << SecretShare << std::endl;
char sshares[192 * n + 1]; char sshares[192 * n + 1];
for ( int i = 0; i < n ; i++){ for ( int i = 0; i < n ; i++){
std::string cur_share = SecretShare.substr(192*i, 192*i + 192); std::string cur_share = SecretShare.substr(192*i, 192*i + 192);
...@@ -469,8 +469,12 @@ Json::Value GetBLSPublicKeyShareImpl(const std::string & BLSKeyName){ ...@@ -469,8 +469,12 @@ Json::Value GetBLSPublicKeyShareImpl(const std::string & BLSKeyName){
try { try {
std::shared_ptr<std::string> encryptedKeyHex_ptr = readFromDb(BLSKeyName, ""); std::shared_ptr<std::string> encryptedKeyHex_ptr = readFromDb(BLSKeyName, "");
std::string public_key = GetBLSPubKey(encryptedKeyHex_ptr->c_str()); std::cerr << "encr_bls_key_share is " << *encryptedKeyHex_ptr << std::endl;
result["BLSPublicKeyShare"] = public_key; std::cerr << "length is " << encryptedKeyHex_ptr->length()<< std::endl;
std::vector<std::string> public_key_vect = GetBLSPubKey(encryptedKeyHex_ptr->c_str());
for ( uint8_t i = 0; i < 4; i++) {
result["BLSPublicKeyShare"][i] = public_key_vect.at(i);
}
} catch (RPCException &_e) { } catch (RPCException &_e) {
std::cerr << " err str " << _e.errString << std::endl; std::cerr << " err str " << _e.errString << std::endl;
...@@ -487,6 +491,7 @@ Json::Value ComplaintResponseImpl(const std::string& polyName, int n, int t, int ...@@ -487,6 +491,7 @@ Json::Value ComplaintResponseImpl(const std::string& polyName, int n, int t, int
result["errorMessage"] = ""; result["errorMessage"] = "";
try { try {
std::shared_ptr<std::string> encr_poly_ptr = readFromDb(polyName, "DKGPoly:"); std::shared_ptr<std::string> encr_poly_ptr = readFromDb(polyName, "DKGPoly:");
std::cerr << "encr_poly is " << *encr_poly_ptr << std::endl;
std::pair<std::string, std::string> response = response_to_complaint(polyName, encr_poly_ptr->c_str(), n, t, ind); std::pair<std::string, std::string> response = response_to_complaint(polyName, encr_poly_ptr->c_str(), n, t, ind);
result["share*G2"] = response.second; result["share*G2"] = response.second;
...@@ -622,7 +627,7 @@ void writeKeyShare(const string &_keyShareName, const string &value, int index, ...@@ -622,7 +627,7 @@ void writeKeyShare(const string &_keyShareName, const string &value, int index,
auto key = "BLSKEYSHARE:" + _keyShareName; auto key = "BLSKEYSHARE:" + _keyShareName;
if (levelDb->readString(_keyShareName) != nullptr) { if (levelDb->readString(_keyShareName) != nullptr) {
throw new RPCException(KEY_SHARE_ALREADY_EXISTS, "Key share with this name already exists"); throw RPCException(KEY_SHARE_ALREADY_EXISTS, "Key share with this name already exists");
} }
levelDb->writeString(key, value); levelDb->writeString(key, value);
...@@ -648,7 +653,7 @@ void writeECDSAKey(const string &_keyName, const string &value) { ...@@ -648,7 +653,7 @@ void writeECDSAKey(const string &_keyName, const string &value) {
auto key = "ECDSAKEY:" + _keyName; auto key = "ECDSAKEY:" + _keyName;
if (levelDb->readString(_keyName) != nullptr) { if (levelDb->readString(_keyName) != nullptr) {
throw new RPCException(KEY_SHARE_ALREADY_EXISTS, "Key with this name already exists"); throw RPCException(KEY_SHARE_ALREADY_EXISTS, "Key with this name already exists");
} }
levelDb->writeString(key, value); levelDb->writeString(key, value);
...@@ -664,7 +669,7 @@ void writeDKGPoly(const string &_polyName, const string &value) { ...@@ -664,7 +669,7 @@ void writeDKGPoly(const string &_polyName, const string &value) {
auto key = "DKGPoly:" + _polyName; auto key = "DKGPoly:" + _polyName;
if (levelDb->readString(_polyName) != nullptr) { if (levelDb->readString(_polyName) != nullptr) {
throw new RPCException(KEY_SHARE_ALREADY_EXISTS, "Poly with this name already exists"); throw RPCException(KEY_SHARE_ALREADY_EXISTS, "Poly with this name already exists");
} }
levelDb->writeString(key, value); levelDb->writeString(key, value);
...@@ -681,7 +686,7 @@ void writeDataToDB(const string & Name, const string &value) { ...@@ -681,7 +686,7 @@ void writeDataToDB(const string & Name, const string &value) {
if (levelDb->readString(Name) != nullptr) { if (levelDb->readString(Name) != nullptr) {
std::cerr << "name " << Name << " already exists" << std::endl; std::cerr << "name " << Name << " already exists" << std::endl;
throw new RPCException(KEY_SHARE_ALREADY_EXISTS, "Data with this name already exists"); throw RPCException(KEY_SHARE_ALREADY_EXISTS, "Data with this name already exists");
} }
levelDb->writeString(key, value); levelDb->writeString(key, value);
......
//
// Created by kladko on 11/19/19.
//
std::vector<std::string> BLSutils::SplitString(std::string& str, const std::string& delim){
std::vector<std::string> tokens;
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()) tokens.push_back(token);
prev = pos + delim.length();
} while (pos < str.length() && prev < str.length());
return tokens;
}
bool checkPolyName (std::string polyName){
}
\ No newline at end of file
//
// Created by kladko on 11/19/19.
//
#ifndef SGXD_SERVERDATACHECKER_H
#define SGXD_SERVERDATACHECKER_H
#endif // SGXD_SERVERDATACHECKER_H
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "BLSCrypto.h" #include "BLSCrypto.h"
#include "ServerInit.h" #include "ServerInit.h"
#include <iostream>
...@@ -42,6 +42,7 @@ void init_daemon() { ...@@ -42,6 +42,7 @@ void init_daemon() {
static std::string dbName("./" WALLETDB_NAME); static std::string dbName("./" WALLETDB_NAME);
levelDb = new LevelDB(dbName); levelDb = new LevelDB(dbName);
} }
...@@ -63,6 +64,8 @@ void init_enclave() { ...@@ -63,6 +64,8 @@ void init_enclave() {
} }
#endif #endif
std::cerr << "SGX_DEBUG_FLAG = " << SGX_DEBUG_FLAG << std::endl;
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);
......
...@@ -27,8 +27,9 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -27,8 +27,9 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
this->bindAndAddMethod(jsonrpc::Procedure("DKGVerification", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "publicShares",jsonrpc::JSON_STRING, "EthKeyName",jsonrpc::JSON_STRING, "SecretShare",jsonrpc::JSON_STRING,"t",jsonrpc::JSON_INTEGER, "n",jsonrpc::JSON_INTEGER, "index",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::DKGVerificationI); this->bindAndAddMethod(jsonrpc::Procedure("DKGVerification", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "publicShares",jsonrpc::JSON_STRING, "EthKeyName",jsonrpc::JSON_STRING, "SecretShare",jsonrpc::JSON_STRING,"t",jsonrpc::JSON_INTEGER, "n",jsonrpc::JSON_INTEGER, "index",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::DKGVerificationI);
this->bindAndAddMethod(jsonrpc::Procedure("CreateBLSPrivateKey", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "BLSKeyName",jsonrpc::JSON_STRING, "EthKeyName",jsonrpc::JSON_STRING, "polyName", jsonrpc::JSON_STRING, "SecretShare",jsonrpc::JSON_STRING,"t", jsonrpc::JSON_INTEGER,"n",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::CreateBLSPrivateKeyI); this->bindAndAddMethod(jsonrpc::Procedure("CreateBLSPrivateKey", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "BLSKeyName",jsonrpc::JSON_STRING, "EthKeyName",jsonrpc::JSON_STRING, "polyName", jsonrpc::JSON_STRING, "SecretShare",jsonrpc::JSON_STRING,"t", jsonrpc::JSON_INTEGER,"n",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::CreateBLSPrivateKeyI);
this->bindAndAddMethod(jsonrpc::Procedure("GetBLSPublicKeyShare", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "BLSKeyName",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::GetBLSPublicKeyShareI); this->bindAndAddMethod(jsonrpc::Procedure("GetBLSPublicKeyShare", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "BLSKeyName",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::GetBLSPublicKeyShareI);
this->bindAndAddMethod(jsonrpc::Procedure("ComplaintResponse", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING, "n",jsonrpc::JSON_INTEGER,"t",jsonrpc::JSON_INTEGER, "ind",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::ComplaintResponseI);
} }
inline virtual void importBLSKeyShareI(const Json::Value &request, Json::Value &response) inline virtual void importBLSKeyShareI(const Json::Value &request, Json::Value &response)
{ {
...@@ -36,7 +37,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -36,7 +37,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
} }
inline virtual void blsSignMessageHashI(const Json::Value &request, Json::Value &response) inline virtual void blsSignMessageHashI(const Json::Value &request, Json::Value &response)
{ {
response = this->blsSignMessageHash(request["keyShareName"].asString(), request["messageHash"].asString(), request["n"].asInt(), request["signerIndex"].asInt(), request["t"].asInt()); response = this->blsSignMessageHash(request["keyShareName"].asString(), request["messageHash"].asString(), request["n"].asInt(), request["t"].asInt(), request["signerIndex"].asInt());
} }
inline virtual void importECDSAKeyI(const Json::Value &request, Json::Value &response) inline virtual void importECDSAKeyI(const Json::Value &request, Json::Value &response)
{ {
...@@ -83,6 +84,10 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -83,6 +84,10 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
{ {
response = this->GetBLSPublicKeyShare(request["BLSKeyName"].asString()); response = this->GetBLSPublicKeyShare(request["BLSKeyName"].asString());
} }
inline virtual void ComplaintResponseI(const Json::Value &request, Json::Value &response)
{
response = this->ComplaintResponse( request["polyName"].asString(), request["n"].asInt(), request["t"].asInt(),request["ind"].asInt());
}
virtual Json::Value importBLSKeyShare(int index, const std::string& keyShare, const std::string& keyShareName, int n, int t) = 0; 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; virtual Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int n, int signerIndex, int t) = 0;
...@@ -98,6 +103,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -98,6 +103,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
virtual Json::Value DKGVerification( const std::string& publicShares, const std::string& EthKeyName, const std::string& SecretShare, int t, int n, int index) = 0; virtual Json::Value DKGVerification( const std::string& publicShares, const std::string& EthKeyName, const std::string& SecretShare, int t, int n, int index) = 0;
virtual Json::Value CreateBLSPrivateKey(const std::string & BLSKeyName, const std::string& EthKeyName, const std::string& polyName, const std::string & SecretShare, int t, int n) = 0; virtual Json::Value CreateBLSPrivateKey(const std::string & BLSKeyName, const std::string& EthKeyName, const std::string& polyName, const std::string & SecretShare, int t, int n) = 0;
virtual Json::Value GetBLSPublicKeyShare(const std::string & BLSKeyName) = 0; virtual Json::Value GetBLSPublicKeyShare(const std::string & BLSKeyName) = 0;
virtual Json::Value ComplaintResponse(const std::string& polyName, int n, int t, int ind) = 0;
}; };
#endif //JSONRPC_CPP_STUB_ABSTRACTSTUBSERVER_H_ #endif //JSONRPC_CPP_STUB_ABSTRACTSTUBSERVER_H_
...@@ -61,9 +61,15 @@ std::string *stringFromG1(libff::alt_bn128_G1 *_g1) { ...@@ -61,9 +61,15 @@ std::string *stringFromG1(libff::alt_bn128_G1 *_g1) {
} }
libff::alt_bn128_Fr *keyFromString(const char *_keyString) { libff::alt_bn128_Fr *keyFromString(const char *_keyStringHex) {
mpz_t skey;
mpz_init(skey);
mpz_set_str(skey, _keyStringHex, 16);
return new libff::alt_bn128_Fr(_keyString); char skey_dec[mpz_sizeinbase (skey, 10) + 2];
char * skey_str = mpz_get_str(skey_dec, 10, skey);
return new libff::alt_bn128_Fr(skey_dec);
} }
......
...@@ -104,15 +104,16 @@ void gen_dkg_poly( char* secret, unsigned _t ){ ...@@ -104,15 +104,16 @@ void gen_dkg_poly( char* secret, unsigned _t ){
libff::alt_bn128_Fr PolynomialValue(const std::vector<libff::alt_bn128_Fr>& pol, libff::alt_bn128_Fr point, unsigned _t) { libff::alt_bn128_Fr PolynomialValue(const std::vector<libff::alt_bn128_Fr>& pol, libff::alt_bn128_Fr point, unsigned _t) {
libff::alt_bn128_Fr value = libff::alt_bn128_Fr::zero(); libff::alt_bn128_Fr value = libff::alt_bn128_Fr::zero();
libff::alt_bn128_Fr pow = libff::alt_bn128_Fr::one(); libff::alt_bn128_Fr pow = libff::alt_bn128_Fr::one();
for (size_t i = 0; i < _t; ++i) { for (unsigned i = 0; i < pol.size(); ++i) {
if (i == _t - 1 && pol[i] == libff::alt_bn128_Fr::zero()) { // if (i == _t - 1 && pol[i] == libff::alt_bn128_Fr::zero()) {
//snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status // //snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status
} // }
value += pol[i] * pow; value += pol[i] * pow;
pow *= point; pow *= point;
} }
return value; return value;
...@@ -149,11 +150,16 @@ void calc_secret_share(const char* decrypted_koefs, char * s_share, ...@@ -149,11 +150,16 @@ void calc_secret_share(const char* decrypted_koefs, char * s_share,
} }
void calc_secret_shareG2(const char* decrypted_koefs, char * s_shareG2, void calc_secret_shareG2_old(const char* decrypted_koefs, char * s_shareG2,
unsigned _t, unsigned ind){ unsigned _t, unsigned ind){
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
char symbol = ':'; char symbol = ':';
std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_koefs, symbol); std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_koefs, symbol);
// if ( poly.size() != _t){
// //"t != poly.size()" +
// //strncpy(s_shareG2, std::to_string(poly.size()).c_str(), 18);
// }
libff::alt_bn128_Fr secret_share = PolynomialValue(poly, libff::alt_bn128_Fr(ind), _t); libff::alt_bn128_Fr secret_share = PolynomialValue(poly, libff::alt_bn128_Fr(ind), _t);
...@@ -161,7 +167,27 @@ void calc_secret_shareG2(const char* decrypted_koefs, char * s_shareG2, ...@@ -161,7 +167,27 @@ void calc_secret_shareG2(const char* decrypted_koefs, char * s_shareG2,
std::string secret_shareG2_str = ConvertG2ToString(secret_shareG2); std::string secret_shareG2_str = ConvertG2ToString(secret_shareG2);
strncpy(s_shareG2, secret_shareG2_str.c_str(), secret_shareG2_str.length()); strncpy(s_shareG2, secret_shareG2_str.c_str(), secret_shareG2_str.length() + 1);
//strncpy(s_shareG2, decrypted_koefs, 320);
}
void calc_secret_shareG2(const char* s_share, char * s_shareG2){
libff::init_alt_bn128_params();
mpz_t share;
mpz_init(share);
mpz_set_str(share, s_share, 16);
char arr[mpz_sizeinbase (share, 10) + 2];
char * share_str = mpz_get_str(arr, 10, share);
libff::alt_bn128_Fr secret_share(share_str);
libff::alt_bn128_G2 secret_shareG2 = secret_share * libff::alt_bn128_G2::one();
std::string secret_shareG2_str = ConvertG2ToString(secret_shareG2);
strncpy(s_shareG2, secret_shareG2_str.c_str(), secret_shareG2_str.length() + 1);
} }
void calc_public_shares(const char* decrypted_koefs, char * public_shares, void calc_public_shares(const char* decrypted_koefs, char * public_shares,
...@@ -238,11 +264,6 @@ int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int in ...@@ -238,11 +264,6 @@ int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int in
char * tmp = mpz_get_str(arr, 10, decr_secret_share); char * tmp = mpz_get_str(arr, 10, decr_secret_share);
libff::alt_bn128_Fr sshare(tmp); libff::alt_bn128_Fr sshare(tmp);
// strncpy(public_shares, tmp, strlen(tmp)); // strncpy(public_shares, tmp, strlen(tmp));
// std::string res = ConvertHexToDec("fe43567238abcdef98760"); // std::string res = ConvertHexToDec("fe43567238abcdef98760");
// strncpy(public_shares, res.c_str(), res.length()); // strncpy(public_shares, res.c_str(), res.length());
...@@ -273,8 +294,18 @@ int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int in ...@@ -273,8 +294,18 @@ int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int in
} }
void calc_bls_public_key(char* skey, char* pub_key){ void calc_bls_public_key(char* skey_hex, char* pub_key){
libff::alt_bn128_Fr bls_skey(skey); libff::init_alt_bn128_params();
mpz_t skey;
mpz_init(skey);
mpz_set_str(skey, skey_hex, 16);
char skey_dec[mpz_sizeinbase (skey, 10) + 2];
char * skey_str = mpz_get_str(skey_dec, 10, skey);
libff::alt_bn128_Fr bls_skey(skey_dec);
libff::alt_bn128_G2 public_key = bls_skey * libff::alt_bn128_G2::one(); libff::alt_bn128_G2 public_key = bls_skey * libff::alt_bn128_G2::one();
public_key.to_affine_coordinates(); public_key.to_affine_coordinates();
......
...@@ -28,7 +28,9 @@ EXTERNC int Verification ( char * public_shares, mpz_t decr_secret_share, int _t ...@@ -28,7 +28,9 @@ EXTERNC int Verification ( char * public_shares, mpz_t decr_secret_share, int _t
EXTERNC void calc_bls_public_key(char* skey, char* pub_key); EXTERNC void calc_bls_public_key(char* skey, char* pub_key);
EXTERNC void calc_secret_shareG2(const char* public_shares, char * s_shareG2, EXTERNC void calc_secret_shareG2_old(const char* public_shares, char * s_shareG2,
unsigned _t, unsigned ind); unsigned _t, unsigned ind);
EXTERNC void calc_secret_shareG2(const char* s_share, char * s_shareG2);
#endif //SGXD_DKGUTILS_H #endif //SGXD_DKGUTILS_H
...@@ -332,7 +332,6 @@ void decrypt_key(int *err_status, char *err_string, uint8_t *encrypted_key, ...@@ -332,7 +332,6 @@ void decrypt_key(int *err_status, char *err_string, uint8_t *encrypted_key,
init(); init();
uint32_t decLen; uint32_t decLen;
*err_status = -9; *err_status = -9;
...@@ -345,9 +344,10 @@ void decrypt_key(int *err_status, char *err_string, uint8_t *encrypted_key, ...@@ -345,9 +344,10 @@ void decrypt_key(int *err_status, char *err_string, uint8_t *encrypted_key,
return; return;
} }
//snprintf(err_string, BUF_LEN, "decr key is %s", key);
if (decLen != MAX_KEY_LENGTH) { if (decLen > MAX_KEY_LENGTH) {
snprintf(err_string, BUF_LEN, "decLen != MAX_KEY_LENGTH"); snprintf(err_string, BUF_LEN, "wrong decLen");//"decLen != MAX_KEY_LENGTH");
return; return;
} }
...@@ -364,12 +364,14 @@ void decrypt_key(int *err_status, char *err_string, uint8_t *encrypted_key, ...@@ -364,12 +364,14 @@ void decrypt_key(int *err_status, char *err_string, uint8_t *encrypted_key,
// check that key is padded with 0s // check that key is padded with 0s
for (int i = keyLen; i < MAX_KEY_LENGTH; i++) { // for (int i = keyLen; i < MAX_KEY_LENGTH; i++) {
if (key[i] != 0) { // if (key[i] != 0) {
snprintf(err_string, BUF_LEN, "Unpadded key"); // snprintf(err_string, BUF_LEN, "Unpadded key");
return; // return;
} // }
} // }
//strncpy(key, "2f993bb09f16c402a27dae868c02791bca7fcf564f1c9e2ba50b142b843a4b60", BUF_LEN);
*err_status = 0; *err_status = 0;
return; return;
...@@ -392,9 +394,12 @@ void bls_sign_message(int *err_status, char *err_string, uint8_t *encrypted_key, ...@@ -392,9 +394,12 @@ void bls_sign_message(int *err_status, char *err_string, uint8_t *encrypted_key,
decrypt_key(err_status, err_string, encrypted_key, enc_len, key); decrypt_key(err_status, err_string, encrypted_key, enc_len, key);
if (*err_status != 0) { if (*err_status != 0) {
strncpy(signature, err_string, BUF_LEN);
return; return;
} }
enclave_sign(key, _hashX, _hashY, sig); enclave_sign(key, _hashX, _hashY, sig);
strncpy(signature, sig, BUF_LEN); strncpy(signature, sig, BUF_LEN);
...@@ -435,7 +440,7 @@ void decrypt_dkg_secret (int *err_status, char* err_string, uint8_t* encrypted_d ...@@ -435,7 +440,7 @@ void decrypt_dkg_secret (int *err_status, char* err_string, uint8_t* encrypted_d
(const sgx_sealed_data_t *)encrypted_dkg_secret, NULL, 0, decrypted_dkg_secret, &decr_len); (const sgx_sealed_data_t *)encrypted_dkg_secret, NULL, 0, decrypted_dkg_secret, &decr_len);
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status %d", status); snprintf(err_string, BUF_LEN,"sgx_unseal_data - encrypted_dkg_secret failed with status %d", status);
return; return;
} }
...@@ -455,7 +460,7 @@ void get_secret_shares(int *err_status, char* err_string, uint8_t* encrypted_dkg ...@@ -455,7 +460,7 @@ void get_secret_shares(int *err_status, char* err_string, uint8_t* encrypted_dkg
// (const sgx_sealed_data_t *)encrypted_dkg_secret, NULL, 0, (uint8_t*)decrypted_dkg_secret, &decr_len); // (const sgx_sealed_data_t *)encrypted_dkg_secret, NULL, 0, (uint8_t*)decrypted_dkg_secret, &decr_len);
if (*err_status != 0) { if (*err_status != 0) {
snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status %d", *err_status); snprintf(err_string, BUF_LEN,"sgx_unseal_data - encrypted_dkg_secret failed with status %d", *err_status);
return; return;
} }
...@@ -493,7 +498,7 @@ void ecdsa_sign1(int *err_status, char *err_string, uint8_t *encrypted_key, uint ...@@ -493,7 +498,7 @@ void ecdsa_sign1(int *err_status, char *err_string, uint8_t *encrypted_key, uint
(const sgx_sealed_data_t *)encrypted_key, NULL, 0, skey, &dec_len); (const sgx_sealed_data_t *)encrypted_key, NULL, 0, skey, &dec_len);
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status %d", status); snprintf(err_string, BUF_LEN,"sgx_unseal_data failed - encrypted_key with status %d", status);
return; return;
} }
...@@ -561,14 +566,14 @@ void set_encrypted_dkg_poly(int *err_status, char *err_string, uint8_t* encrypte ...@@ -561,14 +566,14 @@ void set_encrypted_dkg_poly(int *err_status, char *err_string, uint8_t* encrypte
(const sgx_sealed_data_t *)encrypted_poly, NULL, 0, Decrypted_dkg_poly, &decr_len); (const sgx_sealed_data_t *)encrypted_poly, NULL, 0, Decrypted_dkg_poly, &decr_len);
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status %d", status); snprintf(err_string, BUF_LEN,"sgx_unseal_data - encrypted_poly failed with status %d", status);
return; return;
} }
} }
void get_encr_sshare(int *err_status, char *err_string, uint8_t *encrypted_skey, uint32_t* dec_len, void get_encr_sshare(int *err_status, char *err_string, uint8_t *encrypted_skey, uint32_t* dec_len,
char* result_str, char* pub_keyB, uint8_t _t, uint8_t _n, uint8_t ind ){ char* result_str, char * s_shareG2, char* pub_keyB, uint8_t _t, uint8_t _n, uint8_t ind ){
char skey[ECDSA_SKEY_LEN]; char skey[ECDSA_SKEY_LEN];
char *pub_key_x = (char *)calloc(1024, 1); char *pub_key_x = (char *)calloc(1024, 1);
...@@ -583,7 +588,7 @@ void get_encr_sshare(int *err_status, char *err_string, uint8_t *encrypted_skey, ...@@ -583,7 +588,7 @@ void get_encr_sshare(int *err_status, char *err_string, uint8_t *encrypted_skey,
(const sgx_sealed_data_t *)encrypted_skey, NULL, 0, (uint8_t *)skey, &enc_len); (const sgx_sealed_data_t *)encrypted_skey, NULL, 0, (uint8_t *)skey, &enc_len);
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status %d", status); snprintf(err_string, BUF_LEN,"sgx_unseal_data failed - encrypted_skey with status %d", status);
return; return;
} }
snprintf(err_string, BUF_LEN,"unsealed random skey is %s\n", skey); snprintf(err_string, BUF_LEN,"unsealed random skey is %s\n", skey);
...@@ -599,6 +604,8 @@ void get_encr_sshare(int *err_status, char *err_string, uint8_t *encrypted_skey, ...@@ -599,6 +604,8 @@ void get_encr_sshare(int *err_status, char *err_string, uint8_t *encrypted_skey,
calc_secret_share(Decrypted_dkg_poly, s_share, _t, _n, ind); calc_secret_share(Decrypted_dkg_poly, s_share, _t, _n, ind);
snprintf(err_string + 88, BUF_LEN,"\nsecret share is %s", s_share); snprintf(err_string + 88, BUF_LEN,"\nsecret share is %s", s_share);
calc_secret_shareG2(s_share, s_shareG2);
char* cypher = (char *)malloc(65); char* cypher = (char *)malloc(65);
xor_encrypt(common_key, s_share, cypher); xor_encrypt(common_key, s_share, cypher);
//snprintf(err_string, BUF_LEN ,"cypher is %s length is %d", cypher, strlen(cypher)); //snprintf(err_string, BUF_LEN ,"cypher is %s length is %d", cypher, strlen(cypher));
...@@ -623,22 +630,27 @@ void complaint_response(int *err_status, char *err_string, uint8_t *encrypted_DH ...@@ -623,22 +630,27 @@ void complaint_response(int *err_status, char *err_string, uint8_t *encrypted_DH
uint32_t enc_len; uint32_t enc_len;
sgx_status_t status = sgx_unseal_data( // sgx_status_t status = sgx_unseal_data(
(const sgx_sealed_data_t *)encrypted_DHkey, NULL, 0, (uint8_t *)DH_key, &enc_len); // (const sgx_sealed_data_t *)encrypted_DHkey, NULL, 0, (uint8_t *)DH_key, &enc_len);
if (status != SGX_SUCCESS) { // if (status != SGX_SUCCESS) {
snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status %d", status); // snprintf(err_string, BUF_LEN,"sgx_unseal_data - encrypted_DHkey failed with status %d", status);
return; // return;
} // }
char* decrypted_dkg_secret = (char*)malloc(DKG_BUFER_LENGTH); char* decrypted_dkg_secret = (char*)malloc(DKG_BUFER_LENGTH);
uint32_t decr_len; uint32_t decr_len;
decrypt_dkg_secret(err_status, err_string, encrypted_dkg_secret, (uint8_t*)decrypted_dkg_secret, &decr_len); decrypt_dkg_secret(err_status, err_string, encrypted_dkg_secret, (uint8_t*)decrypted_dkg_secret, &decr_len);
if (*err_status != 0) { if (*err_status != 0) {
snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status %d", *err_status); snprintf(err_string, BUF_LEN,"sgx_unseal_data - encrypted_dkg_secret failed with status %d", *err_status);
return; return;
} }
calc_secret_shareG2(decrypted_dkg_secret, s_shareG2, _t, ind1); calc_secret_shareG2_old(decrypted_dkg_secret, s_shareG2, _t, ind1);
//snprintf(err_string, BUF_LEN,"poly:%s", decrypted_dkg_secret);
// snprintf(err_string, BUF_LEN,"what the fuck");
//snprintf(err_string, BUF_LEN,"s_shareG2:%s", s_shareG2);
free(decrypted_dkg_secret); free(decrypted_dkg_secret);
} }
...@@ -686,7 +698,7 @@ void dkg_verification(int *err_status, char* err_string, const char * public_sha ...@@ -686,7 +698,7 @@ void dkg_verification(int *err_status, char* err_string, const char * public_sha
} }
void create_bls_key(int *err_status, char* err_string, const char* s_shares, void create_bls_key(int *err_status, char* err_string, const char* s_shares,
uint8_t* encrypted_key, uint64_t key_len, uint8_t * encr_bls_key){ uint8_t* encrypted_key, uint64_t key_len, uint8_t * encr_bls_key, uint32_t *enc_bls_key_len){
//uint32_t dec_len = 625; //uint32_t dec_len = 625;
char skey[ECDSA_SKEY_LEN]; char skey[ECDSA_SKEY_LEN];
...@@ -762,18 +774,19 @@ void create_bls_key(int *err_status, char* err_string, const char* s_shares, ...@@ -762,18 +774,19 @@ void create_bls_key(int *err_status, char* err_string, const char* s_shares,
mpz_mod(bls_key, sum, q); mpz_mod(bls_key, sum, q);
char key_share[mpz_sizeinbase(bls_key, 10) + 2]; char key_share[mpz_sizeinbase(bls_key, 16) + 2];
char *key = mpz_get_str(key_share, 10, bls_key); char *key = mpz_get_str(key_share, 16, bls_key);
snprintf(err_string, BUF_LEN,"bls private key is %s", key_share); snprintf(err_string, BUF_LEN,"bls private key is %s", key_share);
uint32_t sealedLen = sgx_calc_sealed_data_size(0, ECDSA_SKEY_LEN); uint32_t sealedLen = sgx_calc_sealed_data_size(0, ECDSA_SKEY_LEN);
status = sgx_seal_data(0, NULL, ECDSA_SKEY_LEN, (uint8_t *)key_share, sealedLen,(sgx_sealed_data_t*)encr_bls_key); status = sgx_seal_data(0, NULL, ECDSA_SKEY_LEN, (uint8_t *)key_share, sealedLen,(sgx_sealed_data_t*)encr_bls_key);
if( status != SGX_SUCCESS) { if( status != SGX_SUCCESS) {
snprintf(err_string, BUF_LEN,"seal bls private key failed with status %d ", status); snprintf(err_string, BUF_LEN,"seal bls private key failed with status %d ", status);
return; return;
} }
*enc_bls_key_len = sealedLen;
//snprintf(err_string, BUF_LEN,"sshare is %s", decr_sshare); //snprintf(err_string, BUF_LEN,"sshare is %s", decr_sshare);
//snprintf(err_string, BUF_LEN,"encr_share is %s", encr_sshare); //snprintf(err_string, BUF_LEN,"encr_share is %s", encr_sshare);
//snprintf(err_string, BUF_LEN,"common_key is %s", common_key); //snprintf(err_string, BUF_LEN,"common_key is %s", common_key);
...@@ -793,18 +806,18 @@ void create_bls_key(int *err_status, char* err_string, const char* s_shares, ...@@ -793,18 +806,18 @@ void create_bls_key(int *err_status, char* err_string, const char* s_shares,
void get_bls_pub_key(int *err_status, char* err_string, uint8_t* encrypted_key, uint64_t key_len, char* bls_pub_key){ void get_bls_pub_key(int *err_status, char* err_string, uint8_t* encrypted_key, uint64_t key_len, char* bls_pub_key){
char skey[ECDSA_SKEY_LEN]; char skey_hex[ECDSA_SKEY_LEN];
sgx_status_t status = sgx_unseal_data( uint32_t len = key_len;
(const sgx_sealed_data_t *)encrypted_key, NULL, 0, (uint8_t *)skey, &key_len);
sgx_status_t status = sgx_unseal_data(
(const sgx_sealed_data_t *)encrypted_key, NULL, 0, (uint8_t *)skey_hex, &len);
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status %d", status); snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status %d", status);
return; return;
} }
calc_bls_public_key(skey, bls_pub_key); calc_bls_public_key(skey_hex, bls_pub_key);
} }
......
...@@ -113,6 +113,7 @@ enclave { ...@@ -113,6 +113,7 @@ enclave {
[out, count = 1024] uint8_t *encrypted_skey, [out, count = 1024] uint8_t *encrypted_skey,
[user_check] uint32_t* dec_len, [user_check] uint32_t* dec_len,
[out, count = 193] char* result_str, [out, count = 193] char* result_str,
[out, count = 320] char* s_shareG2,
[in, count = 129] char* pub_keyB, [in, count = 129] char* pub_keyB,
uint8_t _t, uint8_t _t,
uint8_t _n, uint8_t _n,
...@@ -135,7 +136,8 @@ enclave { ...@@ -135,7 +136,8 @@ enclave {
[in, count = 6145] const char* s_shares, [in, count = 6145] const char* s_shares,
[in, count = 1024] uint8_t* encrypted_key, [in, count = 1024] uint8_t* encrypted_key,
uint64_t key_len, uint64_t key_len,
[out, count = 1024] uint8_t * encr_bls_key); [out, count = 1024] uint8_t * encr_bls_key,
[user_check] uint32_t *enc_bls_key_len);
public void get_bls_pub_key( public void get_bls_pub_key(
[user_check]int *err_status, [user_check]int *err_status,
...@@ -151,7 +153,7 @@ enclave { ...@@ -151,7 +153,7 @@ enclave {
[in, count = 3050] uint8_t *encrypted_dkg_secret, [in, count = 3050] uint8_t *encrypted_dkg_secret,
[user_check] uint32_t* dec_len, [user_check] uint32_t* dec_len,
[out, count = 65] char* DH_key, [out, count = 65] char* DH_key,
[out, count = 257] char* s_shareG2, [out, count = 320] char* s_shareG2,
uint8_t _t, uint8_t _t,
uint8_t _n, uint8_t _n,
uint8_t ind1); uint8_t ind1);
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#define COULD_NOT_ACCESS_DATABASE -9 #define COULD_NOT_ACCESS_DATABASE -9
#define NULL_DATABASE -10 #define NULL_DATABASE -10
#define WALLETDB_NAME "sgxwallet.db" #define WALLETDB_NAME "sgxwallet.db" //"test_sgxwallet.db"//
#define ENCLAVE_NAME "secure_enclave.signed.so" #define ENCLAVE_NAME "secure_enclave.signed.so"
......
...@@ -98,7 +98,7 @@ ...@@ -98,7 +98,7 @@
{ {
"name": "generateDKGPoly", "name": "generateDKGPoly",
"params": { "params": {
"polyName": "key1", "polyName": "POLY:SCHAIN_ID :NODE_ID :DKG_ID",
"t": 3 "t": 3
}, },
"returns": { "returns": {
...@@ -176,7 +176,7 @@ ...@@ -176,7 +176,7 @@
"returns": { "returns": {
"status": 0, "status": 0,
"errorMessage": "12345", "errorMessage": "12345",
"BLSPublicKeyShare": "123" "BLSPublicKeyShare": []
} }
}, },
......
...@@ -26,7 +26,7 @@ class StubClient : public jsonrpc::Client ...@@ -26,7 +26,7 @@ class StubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int n, int signerIndex, int t) throw (jsonrpc::JsonRpcException) Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int n, int t, int signerIndex) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
p["keyShareName"] = keyShareName; p["keyShareName"] = keyShareName;
...@@ -173,6 +173,20 @@ class StubClient : public jsonrpc::Client ...@@ -173,6 +173,20 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value ComplaintResponse(const std::string& polyName, int n, int t, int ind) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["polyName"] = polyName;
p["n"] = n;
p["t"] = t;
p["ind"] = ind;
Json::Value result = this->CallMethod("ComplaintResponse",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
}; };
#endif //JSONRPC_CPP_STUB_STUBCLIENT_H_ #endif //JSONRPC_CPP_STUB_STUBCLIENT_H_
This diff is collapsed.
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include <sgx_tgmp.h> #include <sgx_tgmp.h>
namespace libff { namespace libff {
template<mp_size_t n> class bigint; template<mp_size_t n> class bigint;
......
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