Unverified Commit 4fcda5df authored by Stan Kladko's avatar Stan Kladko Committed by GitHub

Merge pull request #136 from skalenetwork/SKALE-3067-remove-use-check

Skale 3067 remove use check
parents 6502d7bc 4f68f132
......@@ -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,
......@@ -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());
......@@ -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 (i % 1000 == 0) {
if (exception)
throw *exception;
if (!verifyECDSASig(pubKeyStr, hashHex, signatureR.data(), signatureS.data(), base)) {
throw SGXException(667, "ECDSA did not verify");
}
}
return signatureVector;
}
......@@ -73,7 +73,9 @@ public:
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();}
......
......@@ -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,
......
......@@ -21,6 +21,11 @@
@date 2019
*/
#include "DomainParameters.h"
#include "Signature.h"
#include "Curves.h"
#ifndef SGXWALLET_ENCLAVECOMMON_H
#define SGXWALLET_ENCLAVECOMMON_H
......@@ -59,5 +64,7 @@ extern uint32_t globalLogLevel_;
extern unsigned char* globalRandom;
extern domain_parameters curve;
#endif //SGXWALLET_ENCLAVECOMMON_H
This diff is collapsed.
......@@ -111,10 +111,13 @@ TEST_CASE_METHOD(TestFixture, "ECDSA keygen and signature test", "[ecdsa-key-sig
vector<char> signatureS(BUF_LEN, 0);
uint8_t signatureV = 0;
for (int i = 0; i < 50; i++) {
status = trustedEcdsaSign(eid, &errStatus, errMsg.data(), encrPrivKey.data(), encLen,
(unsigned char *) hex.data(),
signatureR.data(),
signatureS.data(), &signatureV, 16);
}
REQUIRE(status == SGX_SUCCESS);
......@@ -286,6 +289,13 @@ TEST_CASE_METHOD(TestFixture, "ECDSA key gen API", "[ecdsa-key-gen-api]") {
}
}
auto keyName = genECDSAKeyAPI(c);
Json::Value sig = c.ecdsaSignMessageHash(10, keyName, SAMPLE_HASH);
for (int i = 0; i <= 20; i++) {
try {
auto keyName = genECDSAKeyAPI(c);
......
......@@ -51,7 +51,7 @@ testList = [ "[cert-sign]",
"[dkg-api]",
"[dkg-bls]",
"[dkg-poly-exists]",
"[dkg-pub-shares]",
# "[dkg-pub-shares]",
"[dkg-aes-pub-shares]",
"[many-threads-crypto]",
"[aes-encrypt-decrypt]",
......
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