Skip to content

Commit

Permalink
Merge pull request #136 from skalenetwork/SKALE-3067-remove-use-check
Browse files Browse the repository at this point in the history
Skale 3067 remove use check
  • Loading branch information
kladkogex authored Aug 11, 2020
2 parents 6502d7b + 4f68f13 commit 4fcda5d
Show file tree
Hide file tree
Showing 7 changed files with 408 additions and 359 deletions.
27 changes: 12 additions & 15 deletions ECDSACrypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,8 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,

string pubKeyStr = "";

shared_ptr<SGXException> exception = NULL;

if (!hex2carray(encryptedKeyHex, &decLen, encryptedKey.data())) {
exception = make_shared<SGXException>(INVALID_HEX, "Invalid encryptedKeyHex");
goto clean;
throw SGXException(INVALID_HEX, "Invalid encryptedKeyHex");
}

status = trustedEcdsaSignAES(eid, &errStatus,
Expand All @@ -188,15 +185,14 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,
signatureS.data(), &signatureV, base);

if (errStatus != 0) {
exception = make_shared<SGXException>(666, errMsg.data());
goto clean;
throw SGXException(666, errMsg.data());
}

if (status != SGX_SUCCESS) {
spdlog::error("failed to sign {}", status);
exception = make_shared<SGXException>(666, "failed to sign");
goto clean;
throw SGXException(666, "failed to sign");
}

signatureVector.at(0) = to_string(signatureV);
if (base == 16) {
signatureVector.at(1) = "0x" + string(signatureR.data());
Expand All @@ -210,15 +206,16 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,

pubKeyStr = getECDSAPubKey(encryptedKeyHex);

if (!verifyECDSASig(pubKeyStr, hashHex, signatureR.data(), signatureS.data(), base)) {
exception = make_shared<SGXException>(667, "ECDSA did not verify");
goto clean;
}
static uint64_t i = 0;

clean:
i++;

if (exception)
throw *exception;
if (i % 1000 == 0) {

if (!verifyECDSASig(pubKeyStr, hashHex, signatureR.data(), signatureS.data(), base)) {
throw SGXException(667, "ECDSA did not verify");
}
}

return signatureVector;
}
4 changes: 3 additions & 1 deletion Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class Log {
static void handleSGXException(Json::Value &_result, SGXException &_e);
};

#define INIT_RESULT(__RESULT__) Json::Value __RESULT__; __RESULT__["status"] = 0; __RESULT__["errorMessage"] = "";
#define INIT_RESULT(__RESULT__) Json::Value __RESULT__; __RESULT__["status"] = 0; __RESULT__["errorMessage"] = \
"Server error. Please see server log.";
#define RESULT_SUCCESS(__RESULT__) ; __RESULT__["status"] = 0; __RESULT__["errorMessage"] = "";
#define HANDLE_SGX_EXCEPTION(_RESULT_) catch (SGXException &__e) { Log::handleSGXException(_RESULT_, __e);} \
catch (exception &__e) {spdlog::error(__e.what()); _RESULT_["status"] = 1; _RESULT_["errorMessage"] = __e.what();}

Expand Down
5 changes: 5 additions & 0 deletions secure_enclave/EnclaveCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,16 @@ libff::alt_bn128_Fr *keyFromString(const char *_keyStringHex) {

int inited = 0;

domain_parameters curve;

void enclave_init() {
if (inited == 1)
return;
inited = 1;
libff::init_alt_bn128_params();

curve = domain_parameters_init();
domain_parameters_load_curve(curve, secp256k1);
}

bool enclave_sign(const char *_keyString, const char *_hashXString, const char *_hashYString,
Expand Down
7 changes: 7 additions & 0 deletions secure_enclave/EnclaveCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
@date 2019
*/

#include "DomainParameters.h"

#include "Signature.h"
#include "Curves.h"

#ifndef SGXWALLET_ENCLAVECOMMON_H
#define SGXWALLET_ENCLAVECOMMON_H

Expand Down Expand Up @@ -59,5 +64,7 @@ extern uint32_t globalLogLevel_;

extern unsigned char* globalRandom;

extern domain_parameters curve;


#endif //SGXWALLET_ENCLAVECOMMON_H
Loading

0 comments on commit 4fcda5d

Please sign in to comment.