Fixing tests

parent df5efe3b
...@@ -114,5 +114,6 @@ add_custom_target(sgxd COMMAND make all ...@@ -114,5 +114,6 @@ add_custom_target(sgxd COMMAND make all
sgx_stub.c sgx_stub.c
sgx_stub.h sgx_stub.h
sgx_tgmp.h sgx_tgmp.h
sgxd.c sgxwallet.c
testw.cpp
) )
...@@ -46,11 +46,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -46,11 +46,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp" #include "catch.hpp"
void usage() { void usage() {
fprintf(stderr, "usage: sgxwallet\n"); fprintf(stderr, "usage: sgxwallet\n");
exit(1); exit(1);
} }
sgx_launch_token_t token = {0}; sgx_launch_token_t token = {0};
...@@ -59,74 +60,128 @@ sgx_status_t status; ...@@ -59,74 +60,128 @@ sgx_status_t status;
int updated; int updated;
TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
{
TEST_CASE( "BLS sign test", "[bls-sign]" ) {
init_all(); init_all();
const char *key = "4160780231445160889237664391382223604184857153814275770598" const char *key = "4160780231445160889237664391382223604184857153814275770598"
"791864649971919844"; "791864649971919844";
char *keyArray = (char *) calloc(128, 1);
const char *hexHash = "001122334455667788" "001122334455667788" "001122334455667788" "001122334455667788"; uint8_t *encryptedKey = (uint8_t *) calloc(1024, 1);
char *errMsg = (char *) calloc(1024, 1);
char* keyArray = (char*) calloc(128, 1); strncpy((char *) keyArray, (char *) key, 128);
uint8_t* encryptedKey = (uint8_t*) calloc(1024, 1); int err_status = 0;
char* errMsg = (char*) calloc(1024,1); unsigned int enc_len = 0;
strncpy((char *)keyArray, (char*)key, 128); status = encrypt_key(eid, &err_status, errMsg, keyArray, encryptedKey, &enc_len);
int err_status = 0; REQUIRE(status == SGX_SUCCESS);
REQUIRE(err_status == 0);
unsigned int enc_len = 0;
status = encrypt_key(eid, &err_status, errMsg, keyArray, encryptedKey, &enc_len); printf("Encrypt key completed with status: %d %s \n", err_status, errMsg);
printf(" Encrypted key len %d\n", enc_len);
REQUIRE(status == SGX_SUCCESS);
REQUIRE(err_status == 0);
char result[2 * BUF_LEN];
printf("Encrypt key completed with status: %d %s \n", err_status, errMsg); carray2Hex(encryptedKey, enc_len, result);
printf(" Encrypted key len %d\n", enc_len);
uint64_t dec_len = 0;
uint8_t bin[BUF_LEN];
char result[2* BUF_LEN]; REQUIRE(hex2carray(result, &dec_len, bin));
carray2Hex(encryptedKey, enc_len, result); for (uint64_t i = 0; i < dec_len; i++) {
REQUIRE(bin[i] == encryptedKey[i]);
}
uint64_t dec_len = 0; REQUIRE(dec_len == enc_len);
uint8_t bin[BUF_LEN]; gmp_printf("Result: %s", result);
REQUIRE(hex2carray(result, &dec_len, bin)); gmp_printf("\n Length: %d \n", enc_len);
for (uint64_t i=0; i < dec_len; i++) { }
REQUIRE(bin[i] == encryptedKey[i]); }
}
REQUIRE(dec_len == enc_len);
gmp_printf("Result: %s", result); TEST_CASE("BLS sign test", "[bls-sign]") {
gmp_printf("\n Length: %d \n", enc_len); init_all();
const char *key = "4160780231445160889237664391382223604184857153814275770598"
"791864649971919844";
char sig[BUF_LEN];
REQUIRE(sign(result, hexHash, 2, 2, 1, sig)); const char *hexHash = "001122334455667788" "001122334455667788" "001122334455667788" "001122334455667788";
}
char *keyArray = (char *) calloc(128, 1);
uint8_t *encryptedKey = (uint8_t *) calloc(1024, 1);
char *errMsg = (char *) calloc(1024, 1);
strncpy((char *) keyArray, (char *) key, 128);
int err_status = 0;
unsigned int enc_len = 0;
status = encrypt_key(eid, &err_status, errMsg, keyArray, encryptedKey, &enc_len);
REQUIRE(status == SGX_SUCCESS);
REQUIRE(err_status == 0);
printf("Encrypt key completed with status: %d %s \n", err_status, errMsg);
printf(" Encrypted key len %d\n", enc_len);
char result[2 * BUF_LEN];
carray2Hex(encryptedKey, enc_len, result
);
uint64_t dec_len = 0;
uint8_t bin[BUF_LEN];
REQUIRE(hex2carray(result, &dec_len, bin)
);
for (uint64_t i = 0; i < dec_len; i++) {
REQUIRE(bin[i] == encryptedKey[i]);
}
REQUIRE(dec_len == enc_len);
gmp_printf("Result: %s", result);
gmp_printf("\n Length: %d \n", enc_len);
char sig[BUF_LEN];
REQUIRE(sign(result, hexHash, 2, 2, 1, sig));
}
TEST_CASE( "DKG gen test", "[dkg-gen]" ) { TEST_CASE("DKG gen test", "[dkg-gen]") {
init_all(); init_all();
// put your test here // put your test here
} }
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