SKALE-2748 refactoring

parent 5b71e0f4
......@@ -114,6 +114,11 @@ string getECDSAPubKey(const char *_encryptedKeyHex) {
if (errStatus != 0) {
throw SGXException(-666, errMsg.data());
}
if (status != SGX_SUCCESS) {
spdlog::error("failed to get ECDSA public key {}", status);
throw SGXException(666, "failed to get ECDSA public key");
}
string pubKey = string(pubKeyX.data()) + string(pubKeyY.data());//concatPubKeyWith0x(pub_key_x, pub_key_y);//
......@@ -131,8 +136,8 @@ bool verifyECDSASig(string& pubKeyStr, const char *hashHex, const char *signatur
signature sig = signature_init();
auto r = pubKeyStr.substr(0, 64);
auto s = pubKeyStr.substr(64, 128);
auto x = pubKeyStr.substr(0, 64);
auto y = pubKeyStr.substr(64, 128);
domain_parameters curve = domain_parameters_init();
domain_parameters_load_curve(curve, secp256k1);
point publicKey = point_init();
......@@ -144,9 +149,12 @@ bool verifyECDSASig(string& pubKeyStr, const char *hashHex, const char *signatur
goto clean;
}
signature_set_str(sig, signatureR, signatureS, 16);
if (signature_set_str(sig, signatureR, signatureS, 16) != 0) {
spdlog::error("Failed to set str signature");
goto clean;
}
point_set_hex(publicKey, r.c_str(), s.c_str());
point_set_hex(publicKey, x.c_str(), y.c_str());
if (!signature_verify(msgMpz, sig, publicKey, curve)) {
spdlog::error("ECDSA sig not verified");
goto clean;
......
......@@ -361,7 +361,7 @@ void trustedEcdsaSign(int *errStatus, char *errString, uint8_t *encryptedPrivate
if (!signature_verify(msgMpz, sign, publicKey, curve)) {
*errStatus = 2;
snprintf(errString, BUF_LEN, "ECDSA sig not verified");
snprintf(errString, BUF_LEN, "ECDSA signature is not verified");
LOG_WARN(errString);
goto clean;
}
......
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