Unverified Commit 11f0cfb2 authored by kladko's avatar kladko

Merge branch 'develop' into bug/SKALE-3170-backup-key

parents 890023df 6726b20e
...@@ -59,10 +59,10 @@ std::string *FqToString(libff::alt_bn128_Fq *_fq) { ...@@ -59,10 +59,10 @@ std::string *FqToString(libff::alt_bn128_Fq *_fq) {
char arr[mpz_sizeinbase(t, 10) + 2]; char arr[mpz_sizeinbase(t, 10) + 2];
char *tmp = mpz_get_str(arr, 10, t); mpz_get_str(arr, 10, t);
mpz_clear(t); mpz_clear(t);
return new std::string(tmp); return new std::string(arr);
} }
int char2int(char _input) { int char2int(char _input) {
...@@ -155,8 +155,7 @@ bool sign(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, size_t ...@@ -155,8 +155,7 @@ bool sign(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, size_t
return true; return true;
} }
bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, size_t _n, size_t _signerIndex, bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, size_t _n, char *_sig) {
char *_sig) {
auto hash = make_shared<array<uint8_t, 32>>(); auto hash = make_shared<array<uint8_t, 32>>();
uint64_t binLen; uint64_t binLen;
...@@ -240,15 +239,15 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz ...@@ -240,15 +239,15 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
return true; return true;
} }
bool bls_sign(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, size_t _n, size_t _signerIndex, bool bls_sign(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, size_t _n, char *_sig) {
char *_sig) { return sign_aes(_encryptedKeyHex, _hashHex, _t, _n, _sig);
return sign_aes(_encryptedKeyHex, _hashHex, _t, _n, _signerIndex, _sig);
} }
std::string encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key) { std::string encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key) {
auto keyArray = make_shared<vector<char>>(BUF_LEN, 0); auto keyArray = make_shared<vector<char>>(BUF_LEN, 0);
auto encryptedKey = make_shared<vector<uint8_t>>(BUF_LEN, 0); auto encryptedKey = make_shared<vector<uint8_t>>(BUF_LEN, 0);
auto errMsg = make_shared<vector<char>>(BUF_LEN, 0); auto errMsg = make_shared<vector<char>>(BUF_LEN, 0);
strncpy(keyArray->data(), _key, BUF_LEN); strncpy(keyArray->data(), _key, BUF_LEN);
*errStatus = -1; *errStatus = -1;
...@@ -265,7 +264,7 @@ std::string encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char ...@@ -265,7 +264,7 @@ std::string encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
*errStatus = -1; *errStatus = -1;
return nullptr; return "";
} }
std::string result(2 * BUF_LEN, '\0'); std::string result(2 * BUF_LEN, '\0');
......
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
#include "stdint.h" #include "stdint.h"
#include <string> #include <string>
EXTERNC bool bls_sign(const char* encryptedKeyHex, const char* hashHex, size_t t, size_t n, EXTERNC bool bls_sign(const char* encryptedKeyHex, const char* hashHex, size_t t, size_t n, char* _sig);
size_t signerIndex, char* _sig);
EXTERNC int char2int(char _input); EXTERNC int char2int(char _input);
......
...@@ -30,8 +30,6 @@ ...@@ -30,8 +30,6 @@
#include "SGXWalletServer.hpp" #include "SGXWalletServer.hpp"
#include "SGXException.h" #include "SGXException.h"
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include "third_party/spdlog/spdlog.h" #include "third_party/spdlog/spdlog.h"
#include "common.h" #include "common.h"
...@@ -65,14 +63,65 @@ template<class T> string ConvertToString(T field_elem, int base = 10) { ...@@ -65,14 +63,65 @@ template<class T> string ConvertToString(T field_elem, int base = 10) {
char arr[mpz_sizeinbase(t, base) + 2]; char arr[mpz_sizeinbase(t, base) + 2];
char *tmp = mpz_get_str(arr, base, t); mpz_get_str(arr, base, t);
mpz_clear(t); mpz_clear(t);
string output = tmp; string output = arr;
return output; return output;
} }
string convertHexToDec(const string& hex_str) {
mpz_t dec;
mpz_init(dec);
string ret = "";
try {
if (mpz_set_str(dec, hex_str.c_str(), 16) == -1) {
mpz_clear(dec);
return ret;
}
char arr[mpz_sizeinbase(dec, 10) + 2];
mpz_get_str(arr, 10, dec);
ret = arr;
} catch (exception &e) {
mpz_clear(dec);
throw SGXException(INCORRECT_STRING_CONVERSION, e.what());
} catch (...) {
mpz_clear(dec);
throw SGXException(UNKNOWN_ERROR, "");
}
return ret;
}
string convertG2ToString(const libff::alt_bn128_G2& elem, int base, const string& delim) {
string result = "";
try {
result += ConvertToString(elem.X.c0);
result += delim;
result += ConvertToString(elem.X.c1);
result += delim;
result += ConvertToString(elem.Y.c0);
result += delim;
result += ConvertToString(elem.Y.c1);
return result;
} catch (exception &e) {
throw SGXException(INCORRECT_STRING_CONVERSION, e.what());
return result;
} catch (...) {
throw SGXException(UNKNOWN_ERROR, "");
return result;
}
return result;
}
string gen_dkg_poly(int _t) { string gen_dkg_poly(int _t) {
vector<char> errMsg(1024, 0); vector<char> errMsg(1024, 0);
int errStatus = 0; int errStatus = 0;
...@@ -318,6 +367,55 @@ vector<string> GetBLSPubKey(const char *encryptedKeyHex) { ...@@ -318,6 +367,55 @@ vector<string> GetBLSPubKey(const char *encryptedKeyHex) {
return pubKeyVect; return pubKeyVect;
} }
vector<string> calculateAllBlsPublicKeys(const vector<string>& public_shares) {
size_t n = public_shares.size();
size_t t = public_shares[0].length() / 256;
uint64_t share_length = 256;
uint8_t coord_length = 64;
vector<libff::alt_bn128_G2> public_keys(n, libff::alt_bn128_G2::zero());
vector<libff::alt_bn128_G2> public_values(t, libff::alt_bn128_G2::zero());
for (size_t i = 0; i < n; ++i) {
for (size_t j = 0; j < t; ++j) {
libff::alt_bn128_G2 public_share;
uint64_t pos0 = share_length * j;
string x_c0_str = convertHexToDec(public_shares[i].substr(pos0, coord_length));
string x_c1_str = convertHexToDec(public_shares[i].substr(pos0 + coord_length, coord_length));
string y_c0_str = convertHexToDec(public_shares[i].substr(pos0 + 2 * coord_length, coord_length));
string y_c1_str = convertHexToDec(public_shares[i].substr(pos0 + 3 * coord_length, coord_length));
if (x_c0_str == "" || x_c1_str == "" || y_c0_str == "" || y_c1_str == "") {
return {};
}
public_share.X.c0 = libff::alt_bn128_Fq(x_c0_str.c_str());
public_share.X.c1 = libff::alt_bn128_Fq(x_c1_str.c_str());
public_share.Y.c0 = libff::alt_bn128_Fq(y_c0_str.c_str());
public_share.Y.c1 = libff::alt_bn128_Fq(y_c1_str.c_str());
public_share.Z = libff::alt_bn128_Fq2::one();
public_values[j] = public_values[j] + public_share;
}
}
for (size_t i = 0; i < n; ++i) {
for (size_t j = 0; j < t; ++j) {
public_keys[i] = public_keys[i] + libff::power(libff::alt_bn128_Fr(i + 1), j) * public_values[j];
}
public_keys[i].to_affine_coordinates();
}
vector<string> result(n);
for (size_t i = 0; i < n; ++i) {
result[i] = convertG2ToString(public_keys[i]);
}
return result;
}
string decryptDHKey(const string &polyName, int ind) { string decryptDHKey(const string &polyName, int ind) {
vector<char> errMsg1(1024, 0); vector<char> errMsg1(1024, 0);
int errStatus = 0; int errStatus = 0;
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
using namespace std; using namespace std;
string gen_dkg_poly( int _t); string gen_dkg_poly( int _t);
...@@ -47,6 +49,12 @@ vector<string> GetBLSPubKey(const char * encryptedKeyHex); ...@@ -47,6 +49,12 @@ vector<string> GetBLSPubKey(const char * encryptedKeyHex);
vector<string> mult_G2(const string& x); vector<string> mult_G2(const string& x);
string convertHexToDec(const string& hex_str);
string convertG2ToString(const libff::alt_bn128_G2& elem, int base = 10, const string& delim = ":");
vector<string> calculateAllBlsPublicKeys(const vector<string>& public_shares);
bool TestCreateBLSShare( const char * s_shares); bool TestCreateBLSShare( const char * s_shares);
#endif //SGXD_DKGCRYPTO_H #endif //SGXD_DKGCRYPTO_H
...@@ -143,7 +143,15 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) { ...@@ -143,7 +143,15 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
} }
} }
httpServer = make_shared<HttpServer>(BASE_PORT, certPath, keyPath, rootCAPath, _checkCerts, 64);
int numThreads = 64;
#if SGX_MODE == SIM
numThreads = 16;
#endif
httpServer = make_shared<HttpServer>(BASE_PORT, certPath, keyPath, rootCAPath, _checkCerts, numThreads);
server = make_shared<SGXWalletServer>(*httpServer, server = make_shared<SGXWalletServer>(*httpServer,
JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0) JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
...@@ -169,7 +177,7 @@ int SGXWalletServer::initHttpServer() { //without ssl ...@@ -169,7 +177,7 @@ int SGXWalletServer::initHttpServer() { //without ssl
} }
Json::Value Json::Value
SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int t, int n, int _index) { SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName) {
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result); INIT_RESULT(result);
...@@ -178,6 +186,10 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k ...@@ -178,6 +186,10 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
string encryptedKeyShareHex; string encryptedKeyShareHex;
try { try {
if (!checkName(_keyShareName, "BLS_KEY")) {
throw SGXException(INVALID_BLS_NAME, "Invalid BLS key name");
}
encryptedKeyShareHex = encryptBLSKeyShare2Hex(&errStatus, (char *) errMsg.data(), _keyShare.c_str()); encryptedKeyShareHex = encryptBLSKeyShare2Hex(&errStatus, (char *) errMsg.data(), _keyShare.c_str());
if (errStatus != 0) { if (errStatus != 0) {
...@@ -190,15 +202,14 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k ...@@ -190,15 +202,14 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
result["encryptedKeyShare"] = encryptedKeyShareHex; result["encryptedKeyShare"] = encryptedKeyShareHex;
writeKeyShare(_keyShareName, encryptedKeyShareHex, _index, n, t); writeKeyShare(_keyShareName, encryptedKeyShareHex);
} HANDLE_SGX_EXCEPTION(result) } HANDLE_SGX_EXCEPTION(result)
RETURN_SUCCESS(result); RETURN_SUCCESS(result);
} }
Json::Value Json::Value
SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const string &_messageHash, int t, int n, SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const string &_messageHash, int t, int n) {
int _signerIndex) {
spdlog::trace("Entering {}", __FUNCTION__); spdlog::trace("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -214,6 +225,11 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin ...@@ -214,6 +225,11 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
if (!checkName(_keyShareName, "BLS_KEY")) { if (!checkName(_keyShareName, "BLS_KEY")) {
throw SGXException(INVALID_POLY_NAME, "Invalid BLSKey name"); throw SGXException(INVALID_POLY_NAME, "Invalid BLSKey name");
} }
if (!check_n_t(t, n)) {
throw SGXException(INVALID_DKG_PARAMS, "Invalid t/n parameters");
}
string hashTmp = _messageHash; string hashTmp = _messageHash;
if (hashTmp[0] == '0' && (hashTmp[1] == 'x' || hashTmp[1] == 'X')) { if (hashTmp[0] == '0' && (hashTmp[1] == 'x' || hashTmp[1] == 'X')) {
hashTmp.erase(hashTmp.begin(), hashTmp.begin() + 2); hashTmp.erase(hashTmp.begin(), hashTmp.begin() + 2);
...@@ -227,7 +243,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin ...@@ -227,7 +243,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
} }
value = readFromDb(_keyShareName); value = readFromDb(_keyShareName);
if (!bls_sign(value->c_str(), _messageHash.c_str(), t, n, _signerIndex, signature.data())) { if (!bls_sign(value->c_str(), _messageHash.c_str(), t, n, signature.data())) {
throw SGXException(-1, "Could not sign data "); throw SGXException(-1, "Could not sign data ");
} }
} HANDLE_SGX_EXCEPTION(result) } HANDLE_SGX_EXCEPTION(result)
...@@ -239,12 +255,6 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin ...@@ -239,12 +255,6 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
} }
Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_key, const string &_keyName) {
INIT_RESULT(result)
result["encryptedKey"] = "";
RETURN_SUCCESS(result)
}
Json::Value SGXWalletServer::generateECDSAKeyImpl() { Json::Value SGXWalletServer::generateECDSAKeyImpl() {
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -272,34 +282,6 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() { ...@@ -272,34 +282,6 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() {
RETURN_SUCCESS(result); RETURN_SUCCESS(result);
} }
Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &_keyName, const string &_tempKeyName) {
spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result)
result["encryptedKey"] = "";
try {
string prefix = _tempKeyName.substr(0, 8);
if (prefix != "tmp_NEK:") {
throw SGXException(UNKNOWN_ERROR, "invalid temp key name");
}
prefix = _keyName.substr(0, 12);
if (prefix != "NEK_NODE_ID:") {
throw SGXException(UNKNOWN_ERROR, "invalid key name");
}
string postfix = _keyName.substr(12, _keyName.length());
if (!isStringDec(postfix)) {
throw SGXException(UNKNOWN_ERROR, "invalid key name");
}
shared_ptr <string> encryptedKey = readFromDb(_tempKeyName);
writeDataToDB(_keyName, *encryptedKey);
LevelDB::getLevelDb()->deleteTempNEK(_tempKeyName);
} HANDLE_SGX_EXCEPTION(result)
RETURN_SUCCESS(result);
}
Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_keyName, const string &_messageHash) { Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_keyName, const string &_messageHash) {
spdlog::trace("Entering {}", __FUNCTION__); spdlog::trace("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -336,7 +318,6 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_ ...@@ -336,7 +318,6 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
throw SGXException(INVALID_ECSDA_SIGNATURE, "Invalid ecdsa signature"); throw SGXException(INVALID_ECSDA_SIGNATURE, "Invalid ecdsa signature");
} }
result["signature_v"] = signatureVector.at(0); result["signature_v"] = signatureVector.at(0);
result["signature_r"] = signatureVector.at(1); result["signature_r"] = signatureVector.at(1);
result["signature_s"] = signatureVector.at(2); result["signature_s"] = signatureVector.at(2);
...@@ -462,7 +443,7 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, co ...@@ -462,7 +443,7 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, co
if (!checkECDSAKeyName(_ethKeyName)) { if (!checkECDSAKeyName(_ethKeyName)) {
throw SGXException(INVALID_ECDSA_KEY_NAME, "Invalid ECDSA key name"); throw SGXException(INVALID_ECDSA_KEY_NAME, "Invalid ECDSA key name");
} }
if (!check_n_t(_t, _n) || _index > _n || _index < 0) { if (!check_n_t(_t, _n) || _index >= _n || _index < 0) {
throw SGXException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t "); throw SGXException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t ");
} }
if (!checkHex(_secretShare, SECRET_SHARE_NUM_BYTES)) { if (!checkHex(_secretShare, SECRET_SHARE_NUM_BYTES)) {
...@@ -506,8 +487,6 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string ...@@ -506,8 +487,6 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
} }
vector <string> sshares_vect; vector <string> sshares_vect;
shared_ptr <string> encryptedKeyHex_ptr = readFromDb(_ethKeyName); shared_ptr <string> encryptedKeyHex_ptr = readFromDb(_ethKeyName);
bool res = CreateBLSShare(_blsKeyName, _secretShare.c_str(), encryptedKeyHex_ptr->c_str()); bool res = CreateBLSShare(_blsKeyName, _secretShare.c_str(), encryptedKeyHex_ptr->c_str());
...@@ -549,6 +528,52 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName) ...@@ -549,6 +528,52 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName)
RETURN_SUCCESS(result); RETURN_SUCCESS(result);
} }
Json::Value SGXWalletServer::calculateAllBLSPublicKeysImpl(const Json::Value& publicShares, int t, int n) {
spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result)
try {
if (!check_n_t(t, n)) {
throw SGXException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t ");
}
if (!publicShares.isArray()) {
throw SGXException(INVALID_DKG_PARAMS, "Invalid public shares format");
}
if (publicShares.size() != (uint64_t) n) {
throw SGXException(INVALID_DKG_PARAMS, "Invalid length of public shares");
}
for (int i = 0; i < n; ++i) {
if (!publicShares[i].isString()) {
throw SGXException(INVALID_DKG_PARAMS, "Invalid public shares parts format");
}
if (publicShares[i].asString().length() != (uint64_t) 256 * t) {
throw SGXException(INVALID_DKG_PARAMS, "Invalid length of public shares parts");
}
}
vector<string> public_shares(n);
for (int i = 0; i < n; ++i) {
public_shares[i] = publicShares[i].asString();
}
vector<string> public_keys = calculateAllBlsPublicKeys(public_shares);
if (public_keys.size() != n) {
throw SGXException(UNKNOWN_ERROR, "");
}
for (int i = 0; i < n; ++i) {
result["publicKeys"][i] = public_keys[i];
}
} HANDLE_SGX_EXCEPTION(result)
RETURN_SUCCESS(result);
}
Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int _ind) { Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int _ind) {
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -557,6 +582,7 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int ...@@ -557,6 +582,7 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int
if (!checkName(_polyName, "POLY")) { if (!checkName(_polyName, "POLY")) {
throw SGXException(INVALID_POLY_NAME, "Invalid polynomial name"); throw SGXException(INVALID_POLY_NAME, "Invalid polynomial name");
} }
string shareG2_name = "shareG2_" + _polyName + "_" + to_string(_ind) + ":"; string shareG2_name = "shareG2_" + _polyName + "_" + to_string(_ind) + ":";
shared_ptr <string> shareG2_ptr = readFromDb(shareG2_name); shared_ptr <string> shareG2_ptr = readFromDb(shareG2_name);
...@@ -662,12 +688,12 @@ Json::Value SGXWalletServer::getBLSPublicKeyShare(const string &blsKeyName) { ...@@ -662,12 +688,12 @@ Json::Value SGXWalletServer::getBLSPublicKeyShare(const string &blsKeyName) {
return getBLSPublicKeyShareImpl(blsKeyName); return getBLSPublicKeyShareImpl(blsKeyName);
} }
Json::Value SGXWalletServer::generateECDSAKey() { Json::Value SGXWalletServer::calculateAllBLSPublicKeys(const Json::Value& publicShares, int t, int n) {
return generateECDSAKeyImpl(); return calculateAllBLSPublicKeysImpl(publicShares, t, n);
} }
Json::Value SGXWalletServer::renameECDSAKey(const string &_keyName, const string &_tmpKeyName) { Json::Value SGXWalletServer::generateECDSAKey() {
return renameECDSAKeyImpl(_keyName, _tmpKeyName); return generateECDSAKeyImpl();
} }
Json::Value SGXWalletServer::getPublicECDSAKey(const string &_keyName) { Json::Value SGXWalletServer::getPublicECDSAKey(const string &_keyName) {
...@@ -679,18 +705,12 @@ Json::Value SGXWalletServer::ecdsaSignMessageHash(int _base, const string &_keyS ...@@ -679,18 +705,12 @@ Json::Value SGXWalletServer::ecdsaSignMessageHash(int _base, const string &_keyS
} }
Json::Value Json::Value
SGXWalletServer::importBLSKeyShare(const string &_keyShare, const string &_keyShareName, int _t, int _n, SGXWalletServer::importBLSKeyShare(const string &_keyShare, const string &_keyShareName) {
int index) { return importBLSKeyShareImpl(_keyShare, _keyShareName);
return importBLSKeyShareImpl(_keyShare, _keyShareName, _t, _n, index);
} }
Json::Value SGXWalletServer::blsSignMessageHash(const string &_keyShareName, const string &_messageHash, int _t, int _n, Json::Value SGXWalletServer::blsSignMessageHash(const string &_keyShareName, const string &_messageHash, int _t, int _n) {
int _signerIndex) { return blsSignMessageHashImpl(_keyShareName, _messageHash, _t, _n);
return blsSignMessageHashImpl(_keyShareName, _messageHash, _t, _n, _signerIndex);
}
Json::Value SGXWalletServer::importECDSAKey(const string &_key, const string &_keyName) {
return importECDSAKeyImpl(_key, _keyName);
} }
Json::Value SGXWalletServer::complaintResponse(const string &polyName, int ind) { Json::Value SGXWalletServer::complaintResponse(const string &polyName, int ind) {
...@@ -727,7 +747,7 @@ shared_ptr <string> SGXWalletServer::readFromDb(const string &name, const string ...@@ -727,7 +747,7 @@ shared_ptr <string> SGXWalletServer::readFromDb(const string &name, const string
return dataStr; return dataStr;
} }
void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &_value, int _index, int _n, int _t) { void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &_value) {
if (LevelDB::getLevelDb()->readString(_keyShareName) != nullptr) { if (LevelDB::getLevelDb()->readString(_keyShareName) != nullptr) {
throw SGXException(KEY_SHARE_ALREADY_EXISTS, "Key share with this name already exists"); throw SGXException(KEY_SHARE_ALREADY_EXISTS, "Key share with this name already exists");
} }
...@@ -735,18 +755,10 @@ void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &_ ...@@ -735,18 +755,10 @@ void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &_
LevelDB::getLevelDb()->writeString(_keyShareName, _value); LevelDB::getLevelDb()->writeString(_keyShareName, _value);
} }
void SGXWalletServer::writeDataToDB(const string &Name, const string &value) { void SGXWalletServer::writeDataToDB(const string &name, const string &value) {
Json::Value val; if (LevelDB::getLevelDb()->readString(name) != nullptr) {
Json::FastWriter writer;
val["value"] = value;
writer.write(val);
auto key = Name;
if (LevelDB::getLevelDb()->readString(Name) != nullptr) {
throw SGXException(KEY_NAME_ALREADY_EXISTS, "Name already exists"); throw SGXException(KEY_NAME_ALREADY_EXISTS, "Name already exists");
} }
LevelDB::getLevelDb()->writeString(key, value); LevelDB::getLevelDb()->writeString(name, value);
} }
...@@ -46,18 +46,13 @@ public: ...@@ -46,18 +46,13 @@ public:
SGXWalletServer(AbstractServerConnector &_connector, serverVersion_t _type); SGXWalletServer(AbstractServerConnector &_connector, serverVersion_t _type);
virtual Json::Value virtual Json::Value
importBLSKeyShare(const string &_keyShare, const string &_keyShareName, int _t, int _n, int index); importBLSKeyShare(const string &_keyShare, const string &_keyShareName);
virtual Json::Value virtual Json::Value
blsSignMessageHash(const string &_keyShareName, const string &_messageHash, int _t, int _n, blsSignMessageHash(const string &_keyShareName, const string &_messageHash, int _t, int _n);
int _signerIndex);
virtual Json::Value importECDSAKey(const string &_key, const string &_keyName);
virtual Json::Value generateECDSAKey(); virtual Json::Value generateECDSAKey();
virtual Json::Value renameECDSAKey(const string &_keyName, const string &_tmpKeyName);
virtual Json::Value virtual Json::Value
ecdsaSignMessageHash(int _base, const string &_keyShareName, const string &_messageHash); ecdsaSignMessageHash(int _base, const string &_keyShareName, const string &_messageHash);
...@@ -79,6 +74,8 @@ public: ...@@ -79,6 +74,8 @@ public:
virtual Json::Value getBLSPublicKeyShare(const string &blsKeyName); virtual Json::Value getBLSPublicKeyShare(const string &blsKeyName);
virtual Json::Value calculateAllBLSPublicKeys(const Json::Value& publicShares, int t, int n);
virtual Json::Value complaintResponse(const string &polyName, int ind); virtual Json::Value complaintResponse(const string &polyName, int ind);
virtual Json::Value multG2(const string &x); virtual Json::Value multG2(const string &x);
...@@ -95,21 +92,16 @@ public: ...@@ -95,21 +92,16 @@ public:
static void writeDataToDB(const string &Name, const string &value); static void writeDataToDB(const string &Name, const string &value);
static void writeKeyShare(const string &_keyShareName, const string &_value, int _index, int _n, int _t); static void writeKeyShare(const string &_keyShareName, const string &_value);
static Json::Value static Json::Value
importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int t, int n, int _index); importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName);
static Json::Value static Json::Value
blsSignMessageHashImpl(const string &_keyShareName, const string &_messageHash, int t, int n, blsSignMessageHashImpl(const string &_keyShareName, const string &_messageHash, int t, int n);
int _signerIndex);
static Json::Value importECDSAKeyImpl(const string &_key, const string &_keyName);
static Json::Value generateECDSAKeyImpl(); static Json::Value generateECDSAKeyImpl();
static Json::Value renameECDSAKeyImpl(const string &_keyName, const string &_tempKeyName);
static Json::Value ecdsaSignMessageHashImpl(int _base, const string &keyName, const string &_messageHash); static Json::Value ecdsaSignMessageHashImpl(int _base, const string &keyName, const string &_messageHash);
static Json::Value getPublicECDSAKeyImpl(const string &_keyName); static Json::Value getPublicECDSAKeyImpl(const string &_keyName);
...@@ -130,6 +122,8 @@ public: ...@@ -130,6 +122,8 @@ public:
static Json::Value getBLSPublicKeyShareImpl(const string &_blsKeyName); static Json::Value getBLSPublicKeyShareImpl(const string &_blsKeyName);
static Json::Value calculateAllBLSPublicKeysImpl(const Json::Value& publicShares, int t, int n);
static Json::Value complaintResponseImpl(const string &_polyName, int _ind); static Json::Value complaintResponseImpl(const string &_polyName, int _ind);
static Json::Value multG2Impl(const string &_x); static Json::Value multG2Impl(const string &_x);
......
...@@ -70,10 +70,10 @@ string TestUtils::stringFromFr(libff::alt_bn128_Fr &el) { ...@@ -70,10 +70,10 @@ string TestUtils::stringFromFr(libff::alt_bn128_Fr &el) {
mpz_init(t); mpz_init(t);
el.as_bigint().to_mpz(t); el.as_bigint().to_mpz(t);
char arr[mpz_sizeinbase(t, 10) + 2]; char arr[mpz_sizeinbase(t, 10) + 2];
char *tmp = mpz_get_str(arr, 10, t); mpz_get_str(arr, 10, t);
mpz_clear(t); mpz_clear(t);
return string(tmp); return string(arr);
} }
...@@ -196,14 +196,12 @@ void TestUtils::sendRPCRequest() { ...@@ -196,14 +196,12 @@ void TestUtils::sendRPCRequest() {
secretShares[i] = c.getSecretShare(polyNames[i], pubEthKeys, t, n); secretShares[i] = c.getSecretShare(polyNames[i], pubEthKeys, t, n);
for (uint8_t k = 0; k < t; k++) { for (uint8_t k = 0; k < t; k++) {
for (uint8_t j = 0; j < 4; j++) { for (uint8_t j = 0; j < 4; j++) {
string pubShare = verifVects[i]["Verification Vector"][k][j].asString(); string pubShare = verifVects[i]["verificationVector"][k][j].asString();
pubShares[i] += convertDecToHex(pubShare); pubShares[i] += convertDecToHex(pubShare);
} }
} }
} }
int k = 0;
vector <string> secShares(n); vector <string> secShares(n);
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
...@@ -212,8 +210,6 @@ void TestUtils::sendRPCRequest() { ...@@ -212,8 +210,6 @@ void TestUtils::sendRPCRequest() {
secShares[i] += secretShares[j]["secretShare"].asString().substr(192 * i, 192); secShares[i] += secretShares[j]["secretShare"].asString().substr(192 * i, 192);
Json::Value verif = c.dkgVerification(pubShares[i], ethKeys[j]["keyName"].asString(), secretShare, t, n, j); Json::Value verif = c.dkgVerification(pubShares[i], ethKeys[j]["keyName"].asString(), secretShare, t, n, j);
CHECK_STATE(verif["status"] == 0); CHECK_STATE(verif["status"] == 0);
k++;
} }
BLSSigShareSet sigShareSet(t, n); BLSSigShareSet sigShareSet(t, n);
...@@ -228,6 +224,14 @@ void TestUtils::sendRPCRequest() { ...@@ -228,6 +224,14 @@ void TestUtils::sendRPCRequest() {
map <size_t, shared_ptr<BLSPublicKeyShare>> coeffs_pkeys_map; map <size_t, shared_ptr<BLSPublicKeyShare>> coeffs_pkeys_map;
Json::Value publicShares;
for (int i = 0; i < n; ++i) {
publicShares["publicShares"][i] = pubShares[i];
}
Json::Value blsPublicKeys = c.calculateAllBLSPublicKeys(publicShares, t, n);
CHECK_STATE(blsPublicKeys["status"] == 0);
for (int i = 0; i < t; i++) { for (int i = 0; i < t; i++) {
string endName = polyNames[i].substr(4); string endName = polyNames[i].substr(4);
string blsName = "BLS_KEY" + polyNames[i].substr(4); string blsName = "BLS_KEY" + polyNames[i].substr(4);
...@@ -238,8 +242,18 @@ void TestUtils::sendRPCRequest() { ...@@ -238,8 +242,18 @@ void TestUtils::sendRPCRequest() {
pubBLSKeys[i] = c.getBLSPublicKeyShare(blsName); pubBLSKeys[i] = c.getBLSPublicKeyShare(blsName);
CHECK_STATE(pubBLSKeys[i]["status"] == 0); CHECK_STATE(pubBLSKeys[i]["status"] == 0);
libff::alt_bn128_G2 publicKey(libff::alt_bn128_Fq2(libff::alt_bn128_Fq(pubBLSKeys[i]["blsPublicKeyShare"][0].asCString()),
libff::alt_bn128_Fq(pubBLSKeys[i]["blsPublicKeyShare"][1].asCString())),
libff::alt_bn128_Fq2(libff::alt_bn128_Fq(pubBLSKeys[i]["blsPublicKeyShare"][2].asCString()),
libff::alt_bn128_Fq(pubBLSKeys[i]["blsPublicKeyShare"][3].asCString())),
libff::alt_bn128_Fq2::one());
string public_key_str = convertG2ToString(publicKey);
CHECK_STATE(public_key_str == blsPublicKeys["publicKeys"][i].asString());
string hash = SAMPLE_HASH; string hash = SAMPLE_HASH;
blsSigShares[i] = c.blsSignMessageHash(blsName, hash, t, n, i + 1); blsSigShares[i] = c.blsSignMessageHash(blsName, hash, t, n);
CHECK_STATE(blsSigShares[i]["status"] == 0); CHECK_STATE(blsSigShares[i]["status"] == 0);
shared_ptr <string> sig_share_ptr = make_shared<string>(blsSigShares[i]["signatureShare"].asString()); shared_ptr <string> sig_share_ptr = make_shared<string>(blsSigShares[i]["signatureShare"].asString());
...@@ -376,7 +390,7 @@ void TestUtils::doDKG(StubClient &c, int n, int t, ...@@ -376,7 +390,7 @@ void TestUtils::doDKG(StubClient &c, int n, int t,
for (int i = 0; i < t; i++) { for (int i = 0; i < t; i++) {
string blsName = "BLS_KEY" + polyNames[i].substr(4); string blsName = "BLS_KEY" + polyNames[i].substr(4);
blsSigShares[i] = c.blsSignMessageHash(blsName, hash, t, n, i + 1); blsSigShares[i] = c.blsSignMessageHash(blsName, hash, t, n);
CHECK_STATE(blsSigShares[i]["status"] == 0); CHECK_STATE(blsSigShares[i]["status"] == 0);
shared_ptr<string> sig_share_ptr = make_shared<string>(blsSigShares[i]["signatureShare"].asString()); shared_ptr<string> sig_share_ptr = make_shared<string>(blsSigShares[i]["signatureShare"].asString());
BLSSigShare sig(sig_share_ptr, i + 1, t, n); BLSSigShare sig(sig_share_ptr, i + 1, t, n);
......
...@@ -36,21 +36,20 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -36,21 +36,20 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
public: public:
AbstractStubServer(jsonrpc::AbstractServerConnector &conn, jsonrpc::serverVersion_t type = jsonrpc::JSONRPC_SERVER_V2) : jsonrpc::AbstractServer<AbstractStubServer>(conn, type) AbstractStubServer(jsonrpc::AbstractServerConnector &conn, jsonrpc::serverVersion_t type = jsonrpc::JSONRPC_SERVER_V2) : jsonrpc::AbstractServer<AbstractStubServer>(conn, type)
{ {
this->bindAndAddMethod(jsonrpc::Procedure("importBLSKeyShare", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT,"keyShare",jsonrpc::JSON_STRING,"keyShareName",jsonrpc::JSON_STRING,"t",jsonrpc::JSON_INTEGER,"n",jsonrpc::JSON_INTEGER, "index",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::importBLSKeyShareI); this->bindAndAddMethod(jsonrpc::Procedure("importBLSKeyShare", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT,"keyShare",jsonrpc::JSON_STRING,"keyShareName",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::importBLSKeyShareI);
this->bindAndAddMethod(jsonrpc::Procedure("blsSignMessageHash", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "keyShareName",jsonrpc::JSON_STRING,"messageHash",jsonrpc::JSON_STRING,"t",jsonrpc::JSON_INTEGER, "n",jsonrpc::JSON_INTEGER, "signerIndex",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::blsSignMessageHashI); this->bindAndAddMethod(jsonrpc::Procedure("blsSignMessageHash", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "keyShareName",jsonrpc::JSON_STRING,"messageHash",jsonrpc::JSON_STRING,"t",jsonrpc::JSON_INTEGER, "n",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::blsSignMessageHashI);
this->bindAndAddMethod(jsonrpc::Procedure("importECDSAKey", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "key",jsonrpc::JSON_STRING,"keyName",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::importECDSAKeyI);
this->bindAndAddMethod(jsonrpc::Procedure("generateECDSAKey", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, NULL), &AbstractStubServer::generateECDSAKeyI); this->bindAndAddMethod(jsonrpc::Procedure("generateECDSAKey", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, NULL), &AbstractStubServer::generateECDSAKeyI);
this->bindAndAddMethod(jsonrpc::Procedure("renameECDSAKey", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "keyName",jsonrpc::JSON_STRING,"tempKeyName",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::renameECDSAKeyI);
this->bindAndAddMethod(jsonrpc::Procedure("getPublicECDSAKey", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "keyName",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::getPublicECDSAKeyI); 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("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, "polyName",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, "t",jsonrpc::JSON_INTEGER,"t",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::getVerificationVectorI); this->bindAndAddMethod(jsonrpc::Procedure("getVerificationVector", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT,"polyName",jsonrpc::JSON_STRING, "t",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::getVerificationVectorI);
this->bindAndAddMethod(jsonrpc::Procedure("getSecretShare", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING,"publicKeys",jsonrpc::JSON_ARRAY, "n",jsonrpc::JSON_INTEGER,"t",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::getSecretShareI); this->bindAndAddMethod(jsonrpc::Procedure("getSecretShare", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING,"publicKeys",jsonrpc::JSON_ARRAY, "n",jsonrpc::JSON_INTEGER,"t",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::getSecretShareI);
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("calculateAllBLSPublicKeys", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "publicShares", jsonrpc::JSON_ARRAY, "n", jsonrpc::JSON_INTEGER, "t", jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::calculateAllBLSPublicKeysI);
this->bindAndAddMethod(jsonrpc::Procedure("complaintResponse", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING,"ind",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::complaintResponseI); this->bindAndAddMethod(jsonrpc::Procedure("complaintResponse", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING,"ind",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::complaintResponseI);
this->bindAndAddMethod(jsonrpc::Procedure("multG2", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "x",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::multG2I); this->bindAndAddMethod(jsonrpc::Procedure("multG2", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "x",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::multG2I);
this->bindAndAddMethod(jsonrpc::Procedure("isPolyExists", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::isPolyExistsI); this->bindAndAddMethod(jsonrpc::Procedure("isPolyExists", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::isPolyExistsI);
...@@ -62,25 +61,17 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -62,25 +61,17 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
inline virtual void importBLSKeyShareI(const Json::Value &request, Json::Value &response) inline virtual void importBLSKeyShareI(const Json::Value &request, Json::Value &response)
{ {
response = this->importBLSKeyShare( request["keyShare"].asString(), request["keyShareName"].asString(), request["t"].asInt(), request["n"].asInt(), request["index"].asInt()); response = this->importBLSKeyShare( request["keyShare"].asString(), request["keyShareName"].asString());
} }
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["t"].asInt(), request["n"].asInt(), request["signerIndex"].asInt()); response = this->blsSignMessageHash(request["keyShareName"].asString(), request["messageHash"].asString(), request["t"].asInt(), request["n"].asInt());
} }
inline virtual void importECDSAKeyI(const Json::Value &request, Json::Value &response)
{
response = this->importECDSAKey(request["key"].asString(), request["keyName"].asString());
}
inline virtual void generateECDSAKeyI(const Json::Value &request, Json::Value &response) inline virtual void generateECDSAKeyI(const Json::Value &request, Json::Value &response)
{ {
(void)request; (void)request;
response = this->generateECDSAKey(); response = this->generateECDSAKey();
}
inline virtual void renameECDSAKeyI(const Json::Value &request, Json::Value &response)
{
response = this->renameECDSAKey(request["keyName"].asString(), request["tempKeyName"].asString());
} }
inline virtual void getPublicECDSAKeyI(const Json::Value &request, Json::Value &response) inline virtual void getPublicECDSAKeyI(const Json::Value &request, Json::Value &response)
{ {
...@@ -115,6 +106,9 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -115,6 +106,9 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
{ {
response = this->getBLSPublicKeyShare(request["blsKeyName"].asString()); response = this->getBLSPublicKeyShare(request["blsKeyName"].asString());
} }
inline virtual void calculateAllBLSPublicKeysI(const Json::Value& request, Json::Value& response) {
response = this->calculateAllBLSPublicKeys(request["publicShares"], request["t"].asInt(), request["n"].asInt());
}
inline virtual void complaintResponseI(const Json::Value &request, Json::Value &response) inline virtual void complaintResponseI(const Json::Value &request, Json::Value &response)
{ {
response = this->complaintResponse( request["polyName"].asString(), request["ind"].asInt()); response = this->complaintResponse( request["polyName"].asString(), request["ind"].asInt());
...@@ -145,11 +139,9 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -145,11 +139,9 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
response = this->deleteBlsKey(request["blsKeyName"].asString()); response = this->deleteBlsKey(request["blsKeyName"].asString());
} }
virtual Json::Value importBLSKeyShare(const std::string& keyShare, const std::string& keyShareName, int t, int n, int index) = 0; virtual Json::Value importBLSKeyShare(const std::string& keyShare, const std::string& keyShareName) = 0;
virtual Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int t, int n, int signerIndex ) = 0; virtual Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int t, int n ) = 0;
virtual Json::Value importECDSAKey(const std::string& key, const std::string& keyName) = 0;
virtual Json::Value generateECDSAKey() = 0; virtual Json::Value generateECDSAKey() = 0;
virtual Json::Value renameECDSAKey(const std::string& KeyName, const std::string& tempKeyName) = 0;
virtual Json::Value getPublicECDSAKey(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 ecdsaSignMessageHash(int base, const std::string& keyName, const std::string& messageHash) = 0;
...@@ -159,6 +151,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -159,6 +151,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 calculateAllBLSPublicKeys(const Json::Value& publicShares, int t, int n) = 0;
virtual Json::Value complaintResponse(const std::string& polyName, int ind) = 0; virtual Json::Value complaintResponse(const std::string& polyName, int ind) = 0;
virtual Json::Value multG2(const std::string & x) = 0; virtual Json::Value multG2(const std::string & x) = 0;
virtual Json::Value isPolyExists(const std::string& polyName) = 0; virtual Json::Value isPolyExists(const std::string& polyName) = 0;
......
...@@ -16,5 +16,4 @@ services: ...@@ -16,5 +16,4 @@ services:
max-size: "10m" max-size: "10m"
max-file: "4" max-file: "4"
restart: unless-stopped restart: unless-stopped
command: -s command: -s -y
...@@ -43,12 +43,7 @@ ...@@ -43,12 +43,7 @@
#include <string.h> #include <string.h>
int gen_session_key(char *skey_str, char *pb_keyB, char *common_key) { int gen_session_key(char *skey_str, char *pb_keyB, char *common_key) {
int ret = -1; int ret = -1;
LOG_INFO(__FUNCTION__); LOG_INFO(__FUNCTION__);
...@@ -60,7 +55,6 @@ int gen_session_key(char *skey_str, char *pb_keyB, char *common_key) { ...@@ -60,7 +55,6 @@ int gen_session_key(char *skey_str, char *pb_keyB, char *common_key) {
point pub_keyB = point_init(); point pub_keyB = point_init();
point session_key = point_init(); point session_key = point_init();
if (!common_key) { if (!common_key) {
LOG_ERROR("gen_session_key: Null common_key"); LOG_ERROR("gen_session_key: Null common_key");
goto clean; goto clean;
...@@ -107,18 +101,15 @@ int gen_session_key(char *skey_str, char *pb_keyB, char *common_key) { ...@@ -107,18 +101,15 @@ int gen_session_key(char *skey_str, char *pb_keyB, char *common_key) {
point_clear(session_key); point_clear(session_key);
return ret; return ret;
} }
int session_key_recover(const char *skey_str, const char *sshare, char *common_key) { int session_key_recover(const char *skey_str, const char *sshare, char *common_key) {
int ret = -1; int ret = -1;
SAFE_CHAR_BUF(pb_keyB_x, 65); SAFE_CHAR_BUF(pb_keyB_x, 65);
SAFE_CHAR_BUF(pb_keyB_y, 65); SAFE_CHAR_BUF(pb_keyB_y, 65);
mpz_t skey; mpz_t skey;
mpz_init(skey); mpz_init(skey);
point pub_keyB = point_init(); point pub_keyB = point_init();
...@@ -147,14 +138,6 @@ int session_key_recover(const char *skey_str, const char *sshare, char *common_k ...@@ -147,14 +138,6 @@ int session_key_recover(const char *skey_str, const char *sshare, char *common_k
goto clean; goto clean;
} }
if (mpz_set_str(skey, skey_str, 16) == -1) { if (mpz_set_str(skey, skey_str, 16) == -1) {
goto clean; goto clean;
} }
...@@ -187,17 +170,17 @@ int xor_encrypt(char *key, char *message, char *cypher) { ...@@ -187,17 +170,17 @@ int xor_encrypt(char *key, char *message, char *cypher) {
if (!cypher) { if (!cypher) {
LOG_ERROR("xor_encrypt: null cypher"); LOG_ERROR("xor_encrypt: null cypher");
goto clean; return ret;
} }
if (!key) { if (!key) {
LOG_ERROR("xor_encrypt: null key"); LOG_ERROR("xor_encrypt: null key");
goto clean; return ret;
} }
if (!message) { if (!message) {
LOG_ERROR("xor_encrypt: null message"); LOG_ERROR("xor_encrypt: null message");
goto clean; return ret;
} }
SAFE_CHAR_BUF(cypher_bin, 33); SAFE_CHAR_BUF(cypher_bin, 33);
...@@ -206,13 +189,13 @@ int xor_encrypt(char *key, char *message, char *cypher) { ...@@ -206,13 +189,13 @@ int xor_encrypt(char *key, char *message, char *cypher) {
uint64_t key_length; uint64_t key_length;
if (!hex2carray(key, &key_length, (uint8_t *) key_bin)) { if (!hex2carray(key, &key_length, (uint8_t *) key_bin)) {
goto clean; return ret;
} }
uint64_t msg_length; uint64_t msg_length;
uint8_t msg_bin[33]; uint8_t msg_bin[33];
if (!hex2carray(message, &msg_length, msg_bin)) { if (!hex2carray(message, &msg_length, msg_bin)) {
goto clean; return ret;
} }
for (int i = 0; i < 32; i++) { for (int i = 0; i < 32; i++) {
...@@ -223,11 +206,7 @@ int xor_encrypt(char *key, char *message, char *cypher) { ...@@ -223,11 +206,7 @@ int xor_encrypt(char *key, char *message, char *cypher) {
ret = 0; ret = 0;
clean:
;
return ret; return ret;
} }
int xor_decrypt(char *key, char *cypher, char *message) { int xor_decrypt(char *key, char *cypher, char *message) {
...@@ -236,34 +215,33 @@ int xor_decrypt(char *key, char *cypher, char *message) { ...@@ -236,34 +215,33 @@ int xor_decrypt(char *key, char *cypher, char *message) {
if (!cypher) { if (!cypher) {
LOG_ERROR("xor_encrypt: null cypher"); LOG_ERROR("xor_encrypt: null cypher");
goto clean; return ret;
} }
if (!key) { if (!key) {
LOG_ERROR("xor_encrypt: null key"); LOG_ERROR("xor_encrypt: null key");
goto clean; return ret;
} }
if (!message) { if (!message) {
LOG_ERROR("xor_encrypt: null message"); LOG_ERROR("xor_encrypt: null message");
goto clean; return ret;
} }
SAFE_CHAR_BUF(msg_bin,33); SAFE_CHAR_BUF(msg_bin,33);
SAFE_CHAR_BUF(key_bin,33) SAFE_CHAR_BUF(key_bin,33)
uint64_t key_length; uint64_t key_length;
if (!hex2carray(key, &key_length, (uint8_t*) key_bin)) { if (!hex2carray(key, &key_length, (uint8_t*) key_bin)) {
goto clean; return ret;
} }
uint64_t cypher_length; uint64_t cypher_length;
SAFE_CHAR_BUF(cypher_bin, 33); SAFE_CHAR_BUF(cypher_bin, 33);
if (!hex2carray(cypher, &cypher_length, (uint8_t *) cypher_bin)) { if (!hex2carray(cypher, &cypher_length, (uint8_t *) cypher_bin)) {
goto clean; return ret;
} }
for (int i = 0; i < 32; i++) { for (int i = 0; i < 32; i++) {
...@@ -274,9 +252,5 @@ int xor_decrypt(char *key, char *cypher, char *message) { ...@@ -274,9 +252,5 @@ int xor_decrypt(char *key, char *cypher, char *message) {
ret = 0; ret = 0;
clean:
;
return ret; return ret;
} }
...@@ -51,10 +51,7 @@ string stringFromFr(const libff::alt_bn128_Fr &_el) { ...@@ -51,10 +51,7 @@ string stringFromFr(const libff::alt_bn128_Fr &_el) {
mpz_t t; mpz_t t;
mpz_init(t); mpz_init(t);
try { try {
_el.as_bigint().to_mpz(t); _el.as_bigint().to_mpz(t);
SAFE_CHAR_BUF(arr, BUF_LEN); SAFE_CHAR_BUF(arr, BUF_LEN);
...@@ -95,7 +92,6 @@ string ConvertToString(const T &field_elem, int base = 10) { ...@@ -95,7 +92,6 @@ string ConvertToString(const T &field_elem, int base = 10) {
char *tmp = mpz_get_str(arr, base, t); char *tmp = mpz_get_str(arr, base, t);
ret = string(tmp); ret = string(tmp);
goto clean; goto clean;
...@@ -128,24 +124,20 @@ string ConvertG2ToString(const libff::alt_bn128_G2 &elem, int base = 10, const s ...@@ -128,24 +124,20 @@ string ConvertG2ToString(const libff::alt_bn128_G2 &elem, int base = 10, const s
result += delim; result += delim;
result += ConvertToString(elem.Y.c1); result += ConvertToString(elem.Y.c1);
goto clean; return result;
} catch (exception &e) { } catch (exception &e) {
LOG_ERROR(e.what()); LOG_ERROR(e.what());
goto clean; return result;
} catch (...) { } catch (...) {
LOG_ERROR("Unknown throwable"); LOG_ERROR("Unknown throwable");
goto clean; return result;
} }
clean:
return result; return result;
} }
vector <libff::alt_bn128_Fr> SplitStringToFr(const char *coeffs, const char symbol) { vector <libff::alt_bn128_Fr> SplitStringToFr(const char *coeffs, const char symbol) {
vector <libff::alt_bn128_Fr> result; vector <libff::alt_bn128_Fr> result;
string str(coeffs); string str(coeffs);
string delim; string delim;
...@@ -168,14 +160,14 @@ vector <libff::alt_bn128_Fr> SplitStringToFr(const char *coeffs, const char symb ...@@ -168,14 +160,14 @@ vector <libff::alt_bn128_Fr> SplitStringToFr(const char *coeffs, const char symb
prev = pos + delim.length(); prev = pos + delim.length();
} while (pos < str.length() && prev < str.length()); } while (pos < str.length() && prev < str.length());
goto clean; return result;
} catch (exception &e) { } catch (exception &e) {
LOG_ERROR(e.what()); LOG_ERROR(e.what());
goto clean; return result;
} catch (...) { } catch (...) {
LOG_ERROR("Unknown throwable"); LOG_ERROR("Unknown throwable");
goto clean; return result;
} }
clean: clean:
...@@ -202,22 +194,21 @@ int gen_dkg_poly(char *secret, unsigned _t) { ...@@ -202,22 +194,21 @@ int gen_dkg_poly(char *secret, unsigned _t) {
strncpy(secret, result.c_str(), result.length() + 1); strncpy(secret, result.c_str(), result.length() + 1);
if (strlen(secret) == 0) { if (strlen(secret) == 0) {
goto clean; return status;
} }
status = 0; status = 0;
} catch (exception &e) { } catch (exception &e) {
LOG_ERROR(e.what()); LOG_ERROR(e.what());
goto clean; return status;
} catch (...) { } catch (...) {
LOG_ERROR("Unknown throwable"); LOG_ERROR("Unknown throwable");
goto clean; return status;
} }
clean: clean:
return status; return status;
} }
libff::alt_bn128_Fr PolynomialValue(const vector <libff::alt_bn128_Fr> &pol, libff::alt_bn128_Fr point, unsigned _t) { libff::alt_bn128_Fr PolynomialValue(const vector <libff::alt_bn128_Fr> &pol, libff::alt_bn128_Fr point, unsigned _t) {
...@@ -232,16 +223,15 @@ libff::alt_bn128_Fr PolynomialValue(const vector <libff::alt_bn128_Fr> &pol, lib ...@@ -232,16 +223,15 @@ libff::alt_bn128_Fr PolynomialValue(const vector <libff::alt_bn128_Fr> &pol, lib
pow *= point; pow *= point;
} }
goto clean; return result;
} catch (exception &e) { } catch (exception &e) {
LOG_ERROR(e.what()); LOG_ERROR(e.what());
goto clean; return result;
} catch (...) { } catch (...) {
LOG_ERROR("Unknown throwable"); LOG_ERROR("Unknown throwable");
goto clean; return result;
} }
clean:
return result; return result;
} }
...@@ -271,10 +261,10 @@ void calc_secret_shares(const char *decrypted_coeffs, ...@@ -271,10 +261,10 @@ void calc_secret_shares(const char *decrypted_coeffs,
} catch (exception &e) { } catch (exception &e) {
LOG_ERROR(e.what()); LOG_ERROR(e.what());
goto clean; return;
} catch (...) { } catch (...) {
LOG_ERROR("Unknown throwable"); LOG_ERROR("Unknown throwable");
goto clean; return;
} }
clean: clean:
...@@ -283,8 +273,6 @@ void calc_secret_shares(const char *decrypted_coeffs, ...@@ -283,8 +273,6 @@ void calc_secret_shares(const char *decrypted_coeffs,
int calc_secret_share(const char *decrypted_coeffs, char *s_share, int calc_secret_share(const char *decrypted_coeffs, char *s_share,
unsigned _t, unsigned _n, unsigned ind) { unsigned _t, unsigned _n, unsigned ind) {
int result = 1; int result = 1;
CHECK_ARG_CLEAN(decrypted_coeffs); CHECK_ARG_CLEAN(decrypted_coeffs);
...@@ -296,7 +284,7 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share, ...@@ -296,7 +284,7 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share,
char symbol = ':'; char symbol = ':';
vector <libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol); vector <libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol);
if (poly.size() != _t) { if (poly.size() != _t) {
goto clean; return result;
} }
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);
...@@ -306,14 +294,14 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share, ...@@ -306,14 +294,14 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share,
strncpy(s_share, cur_share.c_str(), cur_share.length() + 1); strncpy(s_share, cur_share.c_str(), cur_share.length() + 1);
result = 0; result = 0;
goto clean; return result;
} catch (exception &e) { } catch (exception &e) {
LOG_ERROR(e.what()); LOG_ERROR(e.what());
goto clean; return result;
} catch (...) { } catch (...) {
LOG_ERROR("Unknown throwable"); LOG_ERROR("Unknown throwable");
goto clean; return result;
} }
clean: clean:
...@@ -381,12 +369,11 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares, ...@@ -381,12 +369,11 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares,
CHECK_ARG_CLEAN(public_shares); CHECK_ARG_CLEAN(public_shares);
CHECK_ARG_CLEAN(_t > 0); CHECK_ARG_CLEAN(_t > 0);
try { try {
vector <libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol); vector <libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol);
if (poly.size() != _t) { if (poly.size() != _t) {
goto clean; return ret;
} }
for (size_t i = 0; i < _t; ++i) { for (size_t i = 0; i < _t; ++i) {
libff::alt_bn128_G2 pub_share = poly.at(i) * libff::alt_bn128_G2::one(); libff::alt_bn128_G2 pub_share = poly.at(i) * libff::alt_bn128_G2::one();
...@@ -406,7 +393,7 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares, ...@@ -406,7 +393,7 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares,
} }
clean: clean:
return ret; return ret;
} }
string ConvertHexToDec(string hex_str) { string ConvertHexToDec(string hex_str) {
...@@ -435,8 +422,8 @@ string ConvertHexToDec(string hex_str) { ...@@ -435,8 +422,8 @@ string ConvertHexToDec(string hex_str) {
} }
clean: clean:
mpz_clear(dec); mpz_clear(dec);
return ret; return ret;
} }
int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind) { int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind) {
...@@ -461,7 +448,7 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind) ...@@ -461,7 +448,7 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind)
string y_c1_str = ConvertHexToDec(pub_shares_str.substr(pos0 + 3 * coord_length, coord_length)); string y_c1_str = ConvertHexToDec(pub_shares_str.substr(pos0 + 3 * coord_length, coord_length));
if (x_c0_str == "" || x_c1_str == "" || y_c0_str == "" || y_c1_str == "") { if (x_c0_str == "" || x_c1_str == "" || y_c0_str == "" || y_c1_str == "") {
ret = 2; ret = 2;
goto clean; return ret;
} }
pub_share.X.c0 = libff::alt_bn128_Fq(x_c0_str.c_str()); pub_share.X.c0 = libff::alt_bn128_Fq(x_c0_str.c_str());
pub_share.X.c1 = libff::alt_bn128_Fq(x_c1_str.c_str()); pub_share.X.c1 = libff::alt_bn128_Fq(x_c1_str.c_str());
...@@ -498,11 +485,11 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind) ...@@ -498,11 +485,11 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind)
} catch (exception &e) { } catch (exception &e) {
LOG_ERROR(e.what()); LOG_ERROR(e.what());
goto clean; return ret;
} catch (...) { } catch (...) {
LOG_ERROR("Unknown throwable"); LOG_ERROR("Unknown throwable");
goto clean; return ret;
} }
clean: clean:
...@@ -550,6 +537,6 @@ int calc_bls_public_key(char *skey_hex, char *pub_key) { ...@@ -550,6 +537,6 @@ int calc_bls_public_key(char *skey_hex, char *pub_key) {
} }
clean: clean:
mpz_clear(skey); mpz_clear(skey);
return ret; return ret;
} }
...@@ -77,7 +77,8 @@ string *stringFromFq(libff::alt_bn128_Fq *_fq) { ...@@ -77,7 +77,8 @@ string *stringFromFq(libff::alt_bn128_Fq *_fq) {
string *ret = nullptr; string *ret = nullptr;
mpz_t t; mpz_t t;
mpz_init(t);SAFE_CHAR_BUF(arr, BUF_LEN); mpz_init(t);
SAFE_CHAR_BUF(arr, BUF_LEN);
try { try {
_fq->as_bigint().to_mpz(t); _fq->as_bigint().to_mpz(t);
...@@ -140,11 +141,14 @@ string *stringFromG1(libff::alt_bn128_G1 *_g1) { ...@@ -140,11 +141,14 @@ string *stringFromG1(libff::alt_bn128_G1 *_g1) {
libff::alt_bn128_Fr *keyFromString(const char *_keyStringHex) { libff::alt_bn128_Fr *keyFromString(const char *_keyStringHex) {
mpz_t skey; mpz_t skey;
mpz_init(skey);SAFE_CHAR_BUF(skey_dec, BUF_LEN); mpz_init(skey);
SAFE_CHAR_BUF(skey_dec, BUF_LEN);
libff::alt_bn128_Fr *ret = nullptr; libff::alt_bn128_Fr *ret = nullptr;
if (mpz_set_str(skey, _keyStringHex, 16) == -1) {
goto clean;
}
mpz_set_str(skey, _keyStringHex, 16);
mpz_get_str(skey_dec, 10, skey); mpz_get_str(skey_dec, 10, skey);
ret = new libff::alt_bn128_Fr(skey_dec); ret = new libff::alt_bn128_Fr(skey_dec);
......
...@@ -683,7 +683,12 @@ void trustedBlsSignMessageAES(int *errStatus, char *errString, uint8_t *encrypte ...@@ -683,7 +683,12 @@ void trustedBlsSignMessageAES(int *errStatus, char *errString, uint8_t *encrypte
CHECK_STATUS("AES decrypt failed") CHECK_STATUS("AES decrypt failed")
enclave_sign(key, _hashX, _hashY, sig); if (!enclave_sign(key, _hashX, _hashY, sig)) {
strncpy(errString, "Enclave failed to create bls signature", BUF_LEN);
LOG_ERROR(errString);
*errStatus = -1;
goto clean;
}
strncpy(signature, sig, BUF_LEN); strncpy(signature, sig, BUF_LEN);
...@@ -972,9 +977,6 @@ void trustedCreateBlsKeyAES(int *errStatus, char *errString, const char *s_share ...@@ -972,9 +977,6 @@ void trustedCreateBlsKeyAES(int *errStatus, char *errString, const char *s_share
CHECK_STATUS("session_key_recover failed"); CHECK_STATUS("session_key_recover failed");
common_key[64] = 0; common_key[64] = 0;
SAFE_CHAR_BUF(decr_sshare, 65); SAFE_CHAR_BUF(decr_sshare, 65);
......
...@@ -58,7 +58,6 @@ void SGXWallet::printUsage() { ...@@ -58,7 +58,6 @@ void SGXWallet::printUsage() {
} }
void SGXWallet::serializeKeys(const vector<string>& _ecdsaKeyNames, const vector<string>& _blsKeyNames, const string& _fileName) { void SGXWallet::serializeKeys(const vector<string>& _ecdsaKeyNames, const vector<string>& _blsKeyNames, const string& _fileName) {
Json::Value top(Json::objectValue); Json::Value top(Json::objectValue);
Json::Value ecdsaKeysJson(Json::objectValue); Json::Value ecdsaKeysJson(Json::objectValue);
......
...@@ -91,7 +91,6 @@ extern bool autoconfirm; ...@@ -91,7 +91,6 @@ extern bool autoconfirm;
#define INVALID_ECSDA_SIGNATURE -22 #define INVALID_ECSDA_SIGNATURE -22
#define KEY_NAME_ALREADY_EXISTS -23 \ #define KEY_NAME_ALREADY_EXISTS -23 \
#define ERROR_IN_ENCLAVE -33 #define ERROR_IN_ENCLAVE -33
#define FILE_NOT_FOUND -44 #define FILE_NOT_FOUND -44
......
...@@ -6,20 +6,18 @@ ...@@ -6,20 +6,18 @@
#define JSONRPC_CPP_STUB_STUBCLIENT_H_ #define JSONRPC_CPP_STUB_STUBCLIENT_H_
#include <jsonrpccpp/client.h> #include <jsonrpccpp/client.h>
#include <cassert>
class StubClient : public jsonrpc::Client class StubClient : public jsonrpc::Client
{ {
public: public:
StubClient(jsonrpc::IClientConnector &conn, jsonrpc::clientVersion_t type = jsonrpc::JSONRPC_CLIENT_V2) : jsonrpc::Client(conn, type) {} StubClient(jsonrpc::IClientConnector &conn, jsonrpc::clientVersion_t type = jsonrpc::JSONRPC_CLIENT_V2) : jsonrpc::Client(conn, type) {}
Json::Value importBLSKeyShare(const std::string& keyShare, const std::string& keyShareName, int t, int n, int index) Json::Value importBLSKeyShare(const std::string& keyShare, const std::string& keyShareName)
{ {
Json::Value p; Json::Value p;
p["index"] = index;
p["keyShare"] = keyShare; p["keyShare"] = keyShare;
p["keyShareName"] = keyShareName; p["keyShareName"] = keyShareName;
p["n"] = n;
p["t"] = t;
Json::Value result = this->CallMethod("importBLSKeyShare",p); Json::Value result = this->CallMethod("importBLSKeyShare",p);
if (result.isObject()) if (result.isObject())
return result; return result;
...@@ -27,13 +25,12 @@ class StubClient : public jsonrpc::Client ...@@ -27,13 +25,12 @@ 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 blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int t, int n, int signerIndex) Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int t, int n)
{ {
Json::Value p; Json::Value p;
p["keyShareName"] = keyShareName; p["keyShareName"] = keyShareName;
p["messageHash"] = messageHash; p["messageHash"] = messageHash;
p["n"] = n; p["n"] = n;
p["signerIndex"] = signerIndex;
p["t"] = t; p["t"] = t;
Json::Value result = this->CallMethod("blsSignMessageHash",p); Json::Value result = this->CallMethod("blsSignMessageHash",p);
if (result.isObject()) if (result.isObject())
...@@ -42,18 +39,6 @@ class StubClient : public jsonrpc::Client ...@@ -42,18 +39,6 @@ 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 importECDSAKey(const std::string& key, const std::string& keyName)
{
Json::Value p;
p["key"] = key;
p["keyName"] = keyName;
Json::Value result = this->CallMethod("importECDSAKey",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value generateECDSAKey() Json::Value generateECDSAKey()
{ {
Json::Value p; Json::Value p;
...@@ -65,18 +50,6 @@ class StubClient : public jsonrpc::Client ...@@ -65,18 +50,6 @@ 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 renameECDSAKey(const std::string& KeyName, const std::string& tempKeyName)
{
Json::Value p;
p["keyName"] = KeyName;
p["tempKeyName"] = tempKeyName;
Json::Value result = this->CallMethod("renameECDSAKey",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value getPublicECDSAKey(const std::string& keyName) Json::Value getPublicECDSAKey(const std::string& keyName)
{ {
Json::Value p; Json::Value p;
...@@ -184,6 +157,20 @@ class StubClient : public jsonrpc::Client ...@@ -184,6 +157,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 calculateAllBLSPublicKeys(const Json::Value& publicShares, int t, int n)
{
Json::Value p;
p["publicShares"] = publicShares["publicShares"];
p["t"] = t;
p["n"] = n;
Json::Value result = this->CallMethod("calculateAllBLSPublicKeys", p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value complaintResponse(const std::string& polyName, int ind) Json::Value complaintResponse(const std::string& polyName, int ind)
{ {
Json::Value p; Json::Value p;
......
...@@ -82,27 +82,27 @@ public: ...@@ -82,27 +82,27 @@ public:
} }
}; };
class TestFixtureNoReset { class TestFixtureHTTPS {
public: public:
TestFixtureNoReset() { TestFixtureHTTPS() {
setOptions(L_INFO, false, true); TestUtils::resetDB();
setOptions(L_INFO, true, true);
initAll(L_INFO, false, true); initAll(L_INFO, false, true);
} }
~TestFixtureNoReset() { ~TestFixtureHTTPS() {
TestUtils::destroyEnclave(); TestUtils::destroyEnclave();
} }
}; };
class TestFixtureHTTPS { class TestFixtureNoReset {
public: public:
TestFixtureHTTPS() { TestFixtureNoReset() {
TestUtils::resetDB(); setOptions(L_INFO, false, true);
setOptions(L_INFO, true, true);
initAll(L_INFO, false, true); initAll(L_INFO, false, true);
} }
~TestFixtureHTTPS() { ~TestFixtureNoReset() {
TestUtils::destroyEnclave(); TestUtils::destroyEnclave();
} }
}; };
...@@ -286,15 +286,14 @@ TEST_CASE_METHOD(TestFixture, "DKG AES gen test", "[dkg-aes-gen]") { ...@@ -286,15 +286,14 @@ TEST_CASE_METHOD(TestFixture, "DKG AES gen test", "[dkg-aes-gen]") {
REQUIRE(status == SGX_SUCCESS); REQUIRE(status == SGX_SUCCESS);
REQUIRE(errStatus == SGX_SUCCESS); REQUIRE(errStatus == SGX_SUCCESS);
vector<char> secret(2490, 0); vector<char> secret(BUF_LEN, 0);
vector<char> errMsg1(BUF_LEN, 0); vector<char> errMsg1(BUF_LEN, 0);
/*status = trustedDecryptDkgSecretAES(eid, &errStatus, errMsg1.data(), encryptedDKGSecret.data(), status = trustedDecryptDkgSecretAES(eid, &errStatus, errMsg1.data(), encryptedDKGSecret.data(),
(uint8_t *) secret.data(), &encLen); encLen, (uint8_t *) secret.data());
REQUIRE(status == SGX_SUCCESS); REQUIRE(status == SGX_SUCCESS);
REQUIRE(errStatus == SGX_SUCCESS); REQUIRE(errStatus == SGX_SUCCESS);
*/
} }
...@@ -432,7 +431,7 @@ TEST_CASE_METHOD(TestFixture, "Delete Bls Key", "[delete-bls-key]") { ...@@ -432,7 +431,7 @@ TEST_CASE_METHOD(TestFixture, "Delete Bls Key", "[delete-bls-key]") {
libff::alt_bn128_Fr key = libff::alt_bn128_Fr("6507625568967977077291849236396320012317305261598035438182864059942098934847"); libff::alt_bn128_Fr key = libff::alt_bn128_Fr("6507625568967977077291849236396320012317305261598035438182864059942098934847");
std::string key_str = TestUtils::stringFromFr(key); std::string key_str = TestUtils::stringFromFr(key);
PRINT_SRC_LINE PRINT_SRC_LINE
c.importBLSKeyShare(key_str, name, 1, 2, 1); c.importBLSKeyShare(key_str, name);
PRINT_SRC_LINE PRINT_SRC_LINE
REQUIRE(c.deleteBlsKey(name)["deleted"] == true); REQUIRE(c.deleteBlsKey(name)["deleted"] == true);
} }
...@@ -658,7 +657,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") { ...@@ -658,7 +657,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
REQUIRE(pubBLSKeys[i]["status"] == 0); REQUIRE(pubBLSKeys[i]["status"] == 0);
string hash = SAMPLE_HASH; string hash = SAMPLE_HASH;
blsSigShares[i] = c.blsSignMessageHash(blsName, hash, t, n, i + 1); blsSigShares[i] = c.blsSignMessageHash(blsName, hash, t, n);
REQUIRE(blsSigShares[i]["status"] == 0); REQUIRE(blsSigShares[i]["status"] == 0);
shared_ptr<string> sig_share_ptr = make_shared<string>(blsSigShares[i]["signatureShare"].asString()); shared_ptr<string> sig_share_ptr = make_shared<string>(blsSigShares[i]["signatureShare"].asString());
...@@ -722,5 +721,3 @@ TEST_CASE_METHOD(TestFixture, "First run", "[first-run]") { ...@@ -722,5 +721,3 @@ TEST_CASE_METHOD(TestFixture, "First run", "[first-run]") {
TEST_CASE_METHOD(TestFixtureNoReset, "Second run", "[second-run]") { TEST_CASE_METHOD(TestFixtureNoReset, "Second run", "[second-run]") {
} }
...@@ -35,30 +35,21 @@ testList = ["[first-run]", ...@@ -35,30 +35,21 @@ testList = ["[first-run]",
"[get-server-version]", "[get-server-version]",
"[backup-key]", "[backup-key]",
"[delete-bls-key]", "[delete-bls-key]",
"[ecdsa-key-gen]",
"[ecdsa-aes-key-gen]", "[ecdsa-aes-key-gen]",
"[ecdsa-key-sig-gen]",
"[ecdsa-aes-key-sig-gen]", "[ecdsa-aes-key-sig-gen]",
"[ecdsa-get-pub-key]",
"[ecdsa-aes-get-pub-key]", "[ecdsa-aes-get-pub-key]",
"[ecdsa-key-gen-api]", "[ecdsa-key-gen-api]",
"[ecdsa-key-gen-sign-api]",
"[bls-key-encrypt]", "[bls-key-encrypt]",
"[dkg-gen]",
"[dkg-aes-gen]", "[dkg-aes-gen]",
"[dkg-encr-sshares]",
"[dkg-aes-encr-sshares]", "[dkg-aes-encr-sshares]",
"[dkg-verify]", "[dkg-verify]",
"[dkg-api]", "[dkg-api]",
"[dkg-bls]", "[dkg-bls]",
"[dkg-poly-exists]", "[dkg-poly-exists]",
# "[dkg-pub-shares]",
"[dkg-aes-pub-shares]", "[dkg-aes-pub-shares]",
"[many-threads-crypto]", "[many-threads-crypto]",
"[aes-encrypt-decrypt]", "[aes-encrypt-decrypt]",
"[sgx-encrypt-decrypt]", "[aes-dkg]"
"[aes-dkg]",
"[aes-not-aes]"
] ]
......
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