Unverified Commit d7432fd5 authored by svetaro's avatar svetaro

SKALE-1887 Add flag not to use AES in ECDSA procedures

parent c11762aa
...@@ -51,8 +51,10 @@ std::vector<std::string> gen_ecdsa_key(){ ...@@ -51,8 +51,10 @@ std::vector<std::string> gen_ecdsa_key(){
char *pub_key_y = (char *)calloc(1024, 1); char *pub_key_y = (char *)calloc(1024, 1);
uint32_t enc_len = 0; uint32_t enc_len = 0;
//status = generate_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, &enc_len, pub_key_x, pub_key_y ); if ( !is_aes)
status = generate_ecdsa_key_aes(eid, &err_status, errMsg, encr_pr_key, &enc_len, pub_key_x, pub_key_y ); status = generate_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, &enc_len, pub_key_x, pub_key_y );
else status = generate_ecdsa_key_aes(eid, &err_status, errMsg, encr_pr_key, &enc_len, pub_key_x, pub_key_y );
if ( err_status != 0 ){ if ( err_status != 0 ){
std::cerr << "RPCException thrown" << std::endl; std::cerr << "RPCException thrown" << std::endl;
throw RPCException(-666, errMsg) ; throw RPCException(-666, errMsg) ;
...@@ -65,7 +67,7 @@ std::vector<std::string> gen_ecdsa_key(){ ...@@ -65,7 +67,7 @@ std::vector<std::string> gen_ecdsa_key(){
// for(int i = 0 ; i < 1024; i++) // for(int i = 0 ; i < 1024; i++)
// std::cerr << (int)encr_pr_key[i] << " " ; // std::cerr << (int)encr_pr_key[i] << " " ;
} }
char *hexEncrKey = (char *) calloc(BUF_LEN, 1); char *hexEncrKey = (char *) calloc(BUF_LEN * 2, 1);
carray2Hex(encr_pr_key, enc_len, hexEncrKey); carray2Hex(encr_pr_key, enc_len, hexEncrKey);
keys.at(0) = hexEncrKey; keys.at(0) = hexEncrKey;
keys.at(1) = std::string(pub_key_x) + std::string(pub_key_y);//concatPubKeyWith0x(pub_key_x, pub_key_y);// keys.at(1) = std::string(pub_key_x) + std::string(pub_key_y);//concatPubKeyWith0x(pub_key_x, pub_key_y);//
...@@ -119,8 +121,9 @@ std::string get_ecdsa_pubkey(const char* encryptedKeyHex){ ...@@ -119,8 +121,9 @@ std::string get_ecdsa_pubkey(const char* encryptedKeyHex){
throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex"); throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex");
} }
//status = get_public_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y ); if ( !is_aes)
status = get_public_ecdsa_key_aes(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y ); status = get_public_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y );
else status = get_public_ecdsa_key_aes(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y );
if (err_status != 0){ if (err_status != 0){
throw RPCException(-666, errMsg) ; throw RPCException(-666, errMsg) ;
} }
...@@ -164,8 +167,9 @@ std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char ...@@ -164,8 +167,9 @@ std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char
spdlog::info("encrypted len: {}", dec_len); spdlog::info("encrypted len: {}", dec_len);
} }
//status = ecdsa_sign1(eid, &err_status, errMsg, encr_key, ECDSA_ENCR_LEN, (unsigned char*)hashHex, signature_r, signature_s, &signature_v, base ); if (!is_aes)
status = ecdsa_sign_aes(eid, &err_status, errMsg, encr_key, dec_len, (unsigned char*)hashHex, signature_r, signature_s, &signature_v, base ); status = ecdsa_sign1(eid, &err_status, errMsg, encr_key, ECDSA_ENCR_LEN, (unsigned char*)hashHex, signature_r, signature_s, &signature_v, base );
else status = ecdsa_sign_aes(eid, &err_status, errMsg, encr_key, dec_len, (unsigned char*)hashHex, signature_r, signature_s, &signature_v, base );
if ( err_status != 0){ if ( err_status != 0){
throw RPCException(-666, errMsg ) ; throw RPCException(-666, errMsg ) ;
} }
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
int DEBUG_PRINT = 0; int DEBUG_PRINT = 0;
int is_sgx_https = 1; int is_sgx_https = 1;
int is_aes = 0;
SGXRegistrationServer *regs = nullptr; SGXRegistrationServer *regs = nullptr;
HttpServer *hs2 = nullptr; HttpServer *hs2 = nullptr;
......
...@@ -153,6 +153,8 @@ void init_all(bool check_cert, bool sign_automatically) { ...@@ -153,6 +153,8 @@ void init_all(bool check_cert, bool sign_automatically) {
if (sgxServerInited == 1) if (sgxServerInited == 1)
return; return;
init_daemon();
sgxServerInited = 1; sgxServerInited = 1;
if (is_sgx_https) { if (is_sgx_https) {
...@@ -165,5 +167,5 @@ void init_all(bool check_cert, bool sign_automatically) { ...@@ -165,5 +167,5 @@ void init_all(bool check_cert, bool sign_automatically) {
} }
init_enclave(); init_enclave();
//std::cerr << "enclave inited" << std::endl; //std::cerr << "enclave inited" << std::endl;
init_daemon();
} }
...@@ -1248,7 +1248,7 @@ void decrypt_key_aes(int *err_status, char *err_string, uint8_t *encrypted_key, ...@@ -1248,7 +1248,7 @@ void decrypt_key_aes(int *err_status, char *err_string, uint8_t *encrypted_key,
} }
void bls_sign_message_aes(int *err_status, char *err_string, uint8_t *encrypted_key, void bls_sign_message_test(int *err_status, char *err_string, uint8_t *encrypted_key,
uint32_t enc_len, char *_hashX, uint32_t enc_len, char *_hashX,
char *_hashY, char *signature) { char *_hashY, char *signature) {
......
...@@ -213,14 +213,7 @@ enclave { ...@@ -213,14 +213,7 @@ enclave {
uint32_t enc_len, uint32_t enc_len,
[out, count = 1024] char* key ); [out, count = 1024] char* key );
public void bls_sign_message_aes (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[in, count = 1024] uint8_t* encrypted_key,
uint32_t enc_len,
[in, count = 1024] char* hashX ,
[in, count = 1024] char* hashY ,
[out, count = 1024] char* signature);
}; };
......
...@@ -62,7 +62,7 @@ int main(int argc, char *argv[]) { ...@@ -62,7 +62,7 @@ int main(int argc, char *argv[]) {
exit(1); exit(1);
} }
while ((opt = getopt(argc, argv, "cshd0")) != -1) { while ((opt = getopt(argc, argv, "cshd0a")) != -1) {
switch (opt) { switch (opt) {
case 'h': case 'h':
if (strlen(argv[1]) == 2 ) { if (strlen(argv[1]) == 2 ) {
...@@ -87,6 +87,8 @@ int main(int argc, char *argv[]) { ...@@ -87,6 +87,8 @@ int main(int argc, char *argv[]) {
case '0': case '0':
is_sgx_https = 0; is_sgx_https = 0;
break; break;
case 'a':
is_aes = 1;
case '?': // fprintf(stderr, "unknown flag\n"); case '?': // fprintf(stderr, "unknown flag\n");
exit(1); exit(1);
default: default:
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
extern int DEBUG_PRINT; extern int DEBUG_PRINT;
extern int is_sgx_https; extern int is_sgx_https;
extern int is_aes;
#define BUF_LEN 1024 #define BUF_LEN 1024
......
...@@ -763,7 +763,7 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") { ...@@ -763,7 +763,7 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
reset_db(); reset_db();
int n = 4, t = 4; int n = 16, t = 16;
Json::Value EthKeys[n]; Json::Value EthKeys[n];
Json::Value VerifVects[n]; Json::Value VerifVects[n];
Json::Value pubEthKeys; Json::Value pubEthKeys;
...@@ -1071,6 +1071,7 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") { ...@@ -1071,6 +1071,7 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
TEST_CASE("ecdsa API test", "[ecdsa_api_test]") { TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
DEBUG_PRINT = 1; DEBUG_PRINT = 1;
is_sgx_https = 0; is_sgx_https = 0;
is_aes = 0;
cerr << "ecdsa_api_test started" << endl; cerr << "ecdsa_api_test started" << endl;
init_all(false, false); init_all(false, false);
......
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