Fixing tests

parent 6555cb0a
...@@ -89,10 +89,11 @@ char *encryptKey2Hex(int *errStatus, char *err_string, const char *_key) { ...@@ -89,10 +89,11 @@ char *encryptKey2Hex(int *errStatus, char *err_string, const char *_key) {
} }
#define TEST_KEY "4160780231445160889237664391382223604184857153814275770598791864649971919844"
char* encryptTestKey() { char* encryptTestKey() {
const char *key = "4160780231445160889237664391382223604184857153814275770598" const char *key = TEST_KEY;
"791864649971919844";
int errStatus = -1; int errStatus = -1;
...@@ -128,46 +129,20 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") { ...@@ -128,46 +129,20 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
init_all(); init_all();
const char *key = "4160780231445160889237664391382223604184857153814275770598" int errStatus = -1;
"791864649971919844";
char *keyArray = (char *) calloc(BUF_LEN, 1);
uint8_t *encryptedKey = (uint8_t *) calloc(BUF_LEN, 1);
char *errMsg = (char *) calloc(BUF_LEN, 1);
strncpy((char *) keyArray, (char *) key, BUF_LEN);
int errStatus = 0;
unsigned int encryptedLen = 0;
status = encrypt_key(eid, &errStatus, errMsg, keyArray, encryptedKey, &encryptedLen);
REQUIRE(status == SGX_SUCCESS); char* errMsg = (char*) calloc(BUF_LEN, 1);
REQUIRE(errStatus == 0);
printf("Encrypt key completed with status: %d %s \n", errStatus, errMsg); const char *key = TEST_KEY;
printf(" Encrypted key len %d\n", encryptedLen);
char result[2 * BUF_LEN]; char* encryptedKey = encryptTestKey();
REQUIRE(encryptedKey != nullptr);
carray2Hex(encryptedKey, encryptedLen, result);
uint64_t decodedLen = 0; uint64_t decodedLen = 0;
uint8_t decoded[BUF_LEN]; uint8_t decoded[BUF_LEN];
REQUIRE(hex2carray(result, &decodedLen, decoded)); REQUIRE(hex2carray(encryptedKey, &decodedLen, decoded));
for (uint64_t i = 0; i < decodedLen; i++) {
REQUIRE(decoded[i] == encryptedKey[i]);
}
REQUIRE(decodedLen == encryptedLen);
gmp_printf("Result: %s", result);
gmp_printf("\n Encrypted length: %d \n", encryptedLen);
char *plaintextKey = (char *) calloc(BUF_LEN, 1); char *plaintextKey = (char *) calloc(BUF_LEN, 1);
...@@ -179,10 +154,6 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") { ...@@ -179,10 +154,6 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
REQUIRE(strcmp(plaintextKey, key) == 0); REQUIRE(strcmp(plaintextKey, key) == 0);
for (int i = 0; i < BUF_LEN; i++) {
REQUIRE(plaintextKey[i] == keyArray[i]);
}
printf("Decrypt key completed with status: %d %s \n", errStatus, errMsg); printf("Decrypt key completed with status: %d %s \n", errStatus, errMsg);
printf("Decrypted key len %d\n", (int) strlen(plaintextKey)); printf("Decrypted key len %d\n", (int) strlen(plaintextKey));
printf("Decrypted key: %s\n", plaintextKey); printf("Decrypted key: %s\n", plaintextKey);
......
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