diff --git a/test/unittest/src/crypto_aes_cipher_test.cpp b/test/unittest/src/crypto_aes_cipher_test.cpp index ab8f0f0131dcf0fc3bdd028ff373d6818121311e..0db75de6f062ce41e019dc33cd149284cd52b3e9 100644 --- a/test/unittest/src/crypto_aes_cipher_test.cpp +++ b/test/unittest/src/crypto_aes_cipher_test.cpp @@ -45,6 +45,7 @@ constexpr int32_t GCM_TAG_LEN = 16; constexpr int32_t CCM_IV_LEN = 7; // CCM constexpr int32_t CCM_AAD_LEN = 8; constexpr int32_t CCM_TAG_LEN = 12; +constexpr int32_t PLAINTEXT_LEN = 13; class CryptoAesCipherTest : public testing::Test { public: @@ -170,10 +171,10 @@ static int32_t CompareFileContent() infile2.read(reinterpret_cast(buffer2), FILE_BLOCK_SIZE); ret = memcmp(buffer1, buffer2, FILE_BLOCK_SIZE); if (ret != 0) { - goto clearup; + goto CLEAR_UP; } } -clearup: +CLEAR_UP: infile1.close(); infile2.close(); return ret; @@ -196,14 +197,14 @@ static int32_t AesMultiBlockEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParams int32_t ret = cipher->init(cipher, ENCRYPT_MODE, (HcfKey *)key, params); if (ret != 0) { LOGE("init failed! %d", ret); - goto clearup; + goto CLEAR_UP; } for (uint32_t i = 0; i < count; i++) { infile.read(reinterpret_cast(buffer), FILE_BLOCK_SIZE); ret = cipher->update(cipher, &input, &output); if (ret != 0) { LOGE("update failed!"); - goto clearup; + goto CLEAR_UP; } if (output.data != nullptr && output.len > 0) { outfile.write(reinterpret_cast(output.data), output.len); @@ -216,7 +217,7 @@ static int32_t AesMultiBlockEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParams ret = cipher->doFinal(cipher, nullptr, &output); if (ret != 0) { LOGE("doFinal failed!"); - goto clearup; + goto CLEAR_UP; } if (output.data != nullptr && output.len > 0) { outfile.write((const char *)output.data, output.len); @@ -226,7 +227,7 @@ static int32_t AesMultiBlockEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParams HcfFree(output.data); output.data = nullptr; } -clearup: +CLEAR_UP: outfile.close(); infile.close(); @@ -250,14 +251,14 @@ static int32_t AesMultiBlockDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParams int32_t ret = cipher->init(cipher, DECRYPT_MODE, (HcfKey *)key, params); if (ret != 0) { LOGE("init failed! %d", ret); - goto clearup; + goto CLEAR_UP; } for (uint32_t i = 0; i < count; i++) { infile.read(reinterpret_cast(buffer), FILE_BLOCK_SIZE); ret = cipher->update(cipher, &input, &output); if (ret != 0) { LOGE("update failed!"); - goto clearup; + goto CLEAR_UP; } if (output.data != nullptr && output.len > 0) { outfile.write(reinterpret_cast(output.data), output.len); @@ -270,7 +271,7 @@ static int32_t AesMultiBlockDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParams ret = cipher->doFinal(cipher, nullptr, &output); if (ret != 0) { LOGE("doFinal failed!"); - goto clearup; + goto CLEAR_UP; } if (output.data != nullptr && output.len > 0) { outfile.write((const char *)output.data, output.len); @@ -280,13 +281,57 @@ static int32_t AesMultiBlockDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParams HcfFree(output.data); output.data = nullptr; } -clearup: +CLEAR_UP: outfile.close(); infile.close(); return ret; } +// use ECB, test abnormal input +static int32_t AesEncryptWithInput(HcfCipher *cipher, HcfSymKey *key, HcfBlob *input, + uint8_t *cipherText, int *cipherTextLen) +{ + HcfBlob output = { .data = nullptr, .len = 0 }; + int32_t maxLen = *cipherTextLen; + int32_t ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); + if (ret != 0) { + LOGE("init failed! %d", ret); + return ret; + } + + ret = cipher->update(cipher, input, &output); + if (ret != 0) { + LOGE("update failed!"); + return ret; + } + *cipherTextLen = output.len; + if (output.data != nullptr) { + if (memcpy_s(cipherText, maxLen, output.data, output.len) != EOK) { + HcfBlobDataFree(&output); + return -1; + } + HcfBlobDataFree(&output); + } + + ret = cipher->doFinal(cipher, nullptr, &output); + if (ret != 0) { + LOGE("doFinal failed!"); + return ret; + } + if (output.data != nullptr) { + if (memcpy_s(cipherText + *cipherTextLen, maxLen - *cipherTextLen, output.data, output.len) != EOK) { + HcfBlobDataFree(&output); + return -1; + } + *cipherTextLen += output.len; + HcfBlobDataFree(&output); + } + + PrintfHex("ciphertext", cipherText, *cipherTextLen); + return 0; +} + static int32_t AesEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, uint8_t *cipherText, int *cipherTextLen) { @@ -380,6 +425,62 @@ static int32_t AesDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *para return memcmp(cipherText, plainText, cipherTextLen); } +static int32_t AesNoUpdateEncWithInput(HcfCipher *cipher, HcfSymKey *key, HcfBlob *input, + uint8_t *cipherText, int *cipherTextLen) +{ + HcfBlob output = { .data = nullptr, .len = 0 }; + int32_t maxLen = *cipherTextLen; + int32_t ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); + if (ret != 0) { + LOGE("init failed! %d", ret); + return ret; + } + + *cipherTextLen = 0; + ret = cipher->doFinal(cipher, input, &output); + if (ret != 0) { + LOGE("doFinal failed!"); + return ret; + } + if (output.data != nullptr) { + if (memcpy_s(cipherText, maxLen, output.data, output.len) != EOK) { + HcfBlobDataFree(&output); + return -1; + } + *cipherTextLen += output.len; + HcfBlobDataFree(&output); + } + + PrintfHex("ciphertext", cipherText, *cipherTextLen); + return 0; +} + +// test encrypt and decrypt with null plain text +static int32_t AesDecryptEmptyMsg(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, + uint8_t *cipherText, int cipherTextLen) +{ + HcfBlob input = { .data = cipherText, .len = cipherTextLen }; + HcfBlob output = { .data = nullptr, .len = 0 }; + int32_t ret = cipher->init(cipher, DECRYPT_MODE, &(key->key), params); + if (ret != 0) { + LOGE("init failed! %d", ret); + return ret; + } + + ret = cipher->doFinal(cipher, &input, &output); + if (ret != 0) { + LOGE("doFinal failed!"); + return ret; + } + if (output.len == 0 && output.data == nullptr) { + ret = 0; + } else { + ret = -1; + } + HcfBlobDataFree(&output); + return ret; +} + static int32_t AesNoUpdateEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, uint8_t *cipherText, int *cipherTextLen) { @@ -466,33 +567,33 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest001, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -517,33 +618,33 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest002, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -562,34 +663,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest003, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -613,34 +714,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest004, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -664,34 +765,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest005, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -715,34 +816,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest006, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -766,34 +867,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest007, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -817,34 +918,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest008, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -868,34 +969,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest009, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -919,34 +1020,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest010, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -970,34 +1071,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest011, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1021,33 +1122,33 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest012, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1071,34 +1172,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest013, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1122,34 +1223,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest014, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1173,34 +1274,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest015, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1225,34 +1326,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest016, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB1|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1276,34 +1377,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest017, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB1|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1327,7 +1428,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest018, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -1338,22 +1439,22 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest018, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB1|PKCS7", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1377,7 +1478,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest019, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -1388,22 +1489,22 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest019, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB8|NoPadding", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1427,7 +1528,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest020, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -1438,22 +1539,22 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest020, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB8|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1477,7 +1578,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest021, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -1488,22 +1589,22 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest021, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB8|PKCS7", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1527,7 +1628,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest022, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -1538,22 +1639,22 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest022, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB128|NoPadding", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1577,7 +1678,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest023, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -1588,22 +1689,22 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest023, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB128|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1627,7 +1728,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest024, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -1638,22 +1739,22 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest024, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB128|PKCS7", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -1683,19 +1784,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest025, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, 16, cipherText + cipherTextLen - 16, 16); @@ -1705,10 +1806,10 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest025, TestSize.Level0) ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -1737,19 +1838,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest026, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, 16, cipherText + cipherTextLen - 16, 16); @@ -1759,10 +1860,10 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest026, TestSize.Level0) ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -1791,19 +1892,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest027, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, 16, cipherText + cipherTextLen - 16, 16); @@ -1813,10 +1914,10 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest027, TestSize.Level0) ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -1844,19 +1945,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest028, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed!"); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, 12, cipherText + cipherTextLen - 12, 12); @@ -1866,10 +1967,10 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest028, TestSize.Level0) ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed!"); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -1897,19 +1998,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest029, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed!"); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, 12, cipherText + cipherTextLen - 12, 12); @@ -1919,10 +2020,10 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest029, TestSize.Level0) ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed!"); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -1950,19 +2051,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest030, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed!"); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, 12, cipherText + cipherTextLen - 12, 12); @@ -1972,10 +2073,10 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest030, TestSize.Level0) ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed!"); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -1997,34 +2098,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest031, TestSize.Level0) ret = ConvertSymKey("AES128", &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = memcmp(cipherText, codeCipherText, cipherTextLen); if (ret != 0) { LOGE("cipherText compare failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -2043,33 +2144,33 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest032, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2088,33 +2189,33 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest033, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2133,34 +2234,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest034, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2184,34 +2285,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest035, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2235,34 +2336,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest036, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2286,34 +2387,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest037, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2337,34 +2438,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest038, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2388,34 +2489,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest039, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2439,34 +2540,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest040, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2490,34 +2591,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest041, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2541,34 +2642,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest042, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2592,33 +2693,33 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest043, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2642,34 +2743,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest044, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2693,34 +2794,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest045, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2744,34 +2845,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest046, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2796,34 +2897,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest047, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB1|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2847,34 +2948,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest048, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB1|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2898,7 +2999,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest049, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -2909,22 +3010,22 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest049, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB1|PKCS7", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2948,7 +3049,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest050, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -2959,22 +3060,22 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest050, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB8|NoPadding", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -2998,7 +3099,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest051, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -3009,22 +3110,22 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest051, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB8|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -3048,7 +3149,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest052, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -3059,21 +3160,21 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest052, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB8|PKCS7", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -3097,7 +3198,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest053, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -3108,21 +3209,21 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest053, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB128|NoPadding", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -3146,7 +3247,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest054, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -3157,21 +3258,21 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest054, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB128|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -3195,7 +3296,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest055, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); @@ -3206,21 +3307,21 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest055, TestSize.Level0) ret = HcfCipherCreate("AES128|CFB128|PKCS7", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); HcfObjDestroy((HcfObjectBase *)generator); @@ -3250,19 +3351,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest056, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, 16, cipherText + cipherTextLen - 16, 16); @@ -3272,10 +3373,10 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest056, TestSize.Level0) ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -3304,19 +3405,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest057, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, 16, cipherText + cipherTextLen - 16, 16); @@ -3326,10 +3427,10 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest057, TestSize.Level0) ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -3358,19 +3459,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest058, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, 16, cipherText + cipherTextLen - 16, 16); @@ -3380,10 +3481,10 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest058, TestSize.Level0) ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -3411,19 +3512,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest059, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed!"); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, 12, cipherText + cipherTextLen - 12, 12); @@ -3433,10 +3534,10 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest059, TestSize.Level0) ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed!"); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -3464,19 +3565,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest060, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed!"); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, 12, cipherText + cipherTextLen - 12, 12); @@ -3486,10 +3587,10 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest060, TestSize.Level0) ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed!"); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -3518,19 +3619,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest061, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed!"); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, 12, cipherText + cipherTextLen - 12, 12); @@ -3540,10 +3641,10 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest061, TestSize.Level0) ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed!"); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -3565,34 +3666,34 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest062, TestSize.Level0) ret = ConvertSymKey("AES128", &key); if (ret != 0) { LOGE("ConvertSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = memcmp(cipherText, codeCipherText, cipherTextLen); if (ret != 0) { LOGE("cipherText compare failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesNoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -3607,38 +3708,38 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest063, TestSize.Level0) ret = GeneratorFile("/data/test_aes.txt", 10 * FILE_BLOCK_SIZE); if (ret != 0) { LOGE("GeneratorFile failed!"); - goto clearup; + goto CLEAR_UP; } ret = ConvertSymKey("AES128", &key); if (ret != 0) { LOGE("ConvertSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesMultiBlockEncrypt(cipher, key, nullptr); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesMultiBlockDecrypt(cipher, key, nullptr); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = CompareFileContent(); if (ret != 0) { LOGE("CompareFileContent failed!"); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -3658,39 +3759,39 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest064, TestSize.Level0) ret = GeneratorFile("/data/test_aes.txt", 10 * FILE_BLOCK_SIZE); if (ret != 0) { LOGE("GeneratorFile failed!"); - goto clearup; + goto CLEAR_UP; } ret = ConvertSymKey("AES128", &key); if (ret != 0) { LOGE("ConvertSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesMultiBlockEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesMultiBlockDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = CompareFileContent(); if (ret != 0) { LOGE("CompareFileContent failed!"); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -3710,38 +3811,38 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest065, TestSize.Level0) ret = ConvertSymKey("AES128", &key); if (ret != 0) { LOGE("ConvertSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = GeneratorFile("/data/test_aes.txt", 10 * FILE_BLOCK_SIZE); if (ret != 0) { LOGE("GeneratorFile failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesMultiBlockEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesMultiBlockDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = CompareFileContent(); if (ret != 0) { LOGE("CompareFileContent failed!"); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -3761,38 +3862,38 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest066, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = GeneratorFile("/data/test_aes.txt", 10 * FILE_BLOCK_SIZE); if (ret != 0) { LOGE("GeneratorFile failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesMultiBlockEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesMultiBlockDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = CompareFileContent(); if (ret != 0) { LOGE("CompareFileContent failed!"); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -3812,38 +3913,38 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest067, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = GeneratorFile("/data/test_aes.txt", 10 * FILE_BLOCK_SIZE); if (ret != 0) { LOGE("GeneratorFile failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesMultiBlockEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec); if (ret != 0) { LOGE("AesNoUpdateEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesMultiBlockDecrypt(cipher, key, (HcfParamsSpec *)&ivSpec); if (ret != 0) { LOGE("AesNoUpdateDecrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = CompareFileContent(); if (ret != 0) { LOGE("CompareFileContent failed!"); - goto clearup; + goto CLEAR_UP; } -clearup: +CLEAR_UP: HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); EXPECT_EQ(ret, 0); @@ -3860,26 +3961,26 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest068, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES192|ECB|NoPadding", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_NE(ret, 0); @@ -3896,19 +3997,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest069, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES192|ECB|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); @@ -3916,7 +4017,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest069, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } key->clearMem(key); -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -3933,19 +4034,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest070, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES256|ECB|PKCS7", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); @@ -3953,7 +4054,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest070, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } key->clearMem(key); -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -3975,19 +4076,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest071, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CBC|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -3995,7 +4096,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest071, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4017,19 +4118,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest072, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CBC|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -4037,7 +4138,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest072, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4059,19 +4160,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest073, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CTR|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -4079,7 +4180,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest073, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4101,19 +4202,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest074, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CTR|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -4121,7 +4222,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest074, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4143,19 +4244,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest075, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES192|OFB|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -4163,7 +4264,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest075, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4185,19 +4286,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest076, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES256|OFB|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -4205,7 +4306,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest076, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4227,19 +4328,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest077, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CFB|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -4247,7 +4348,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest077, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4269,19 +4370,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest078, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CFB|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -4289,7 +4390,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest078, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4311,19 +4412,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest079, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CFB1|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -4331,7 +4432,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest079, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4354,19 +4455,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest080, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CFB1|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -4374,7 +4475,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest080, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4396,19 +4497,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest081, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CFB8|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -4416,7 +4517,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest081, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4438,19 +4539,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest082, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CFB8|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -4458,7 +4559,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest082, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4480,19 +4581,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest083, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CFB128|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -4500,7 +4601,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest083, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4522,19 +4623,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest084, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CFB128|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(ivSpec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed! %d", ret); - goto clearup; + goto CLEAR_UP; } ret = AesDecrypt(cipher, key, &(ivSpec.base), cipherText, cipherTextLen); @@ -4542,7 +4643,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest084, TestSize.Level0) LOGE("AesDecrypt failed! %d", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4571,19 +4672,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest085, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES192|GCM|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, GCM_TAG_LEN, cipherText + cipherTextLen - GCM_TAG_LEN, GCM_TAG_LEN); @@ -4595,7 +4696,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest085, TestSize.Level0) LOGE("AesDecrypt failed, ret:%d!", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4624,19 +4725,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest086, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES256|GCM|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed, ret:%d!", ret); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, GCM_TAG_LEN, cipherText + cipherTextLen - GCM_TAG_LEN, GCM_TAG_LEN); @@ -4648,7 +4749,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest086, TestSize.Level0) LOGE("AesDecrypt failed, ret:%d!", ret); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4676,19 +4777,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest087, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CCM|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed!"); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, CCM_TAG_LEN, cipherText + cipherTextLen - CCM_TAG_LEN, CCM_TAG_LEN); @@ -4700,7 +4801,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest087, TestSize.Level0) LOGE("AesDecrypt failed!"); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4728,19 +4829,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest088, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CCM|PKCS5", &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); if (ret != 0) { LOGE("AesEncrypt failed!"); - goto clearup; + goto CLEAR_UP; } (void)memcpy_s(spec.tag.data, CCM_TAG_LEN, cipherText + cipherTextLen - CCM_TAG_LEN, CCM_TAG_LEN); @@ -4752,7 +4853,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest088, TestSize.Level0) LOGE("AesDecrypt failed!"); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); @@ -4767,21 +4868,21 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest089, TestSize.Level0) ret = HcfCipherCreate(cipherName, &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } retAlgo = cipher->getAlgorithm(cipher); if (retAlgo == nullptr) { LOGE("cipher getAlgorithm failed!"); ret = HCF_ERR_CRYPTO_OPERATION; - goto clearup; + goto CLEAR_UP; } ret = strcmp(retAlgo, cipherName); if (ret != 0) { LOGE("cipher getAlgorithm failed!"); } -clearup: +CLEAR_UP: HcfObjDestroy(cipher); EXPECT_EQ(ret, 0); } @@ -4795,7 +4896,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest090, TestSize.Level0) ret = HcfCipherCreate(cipherName, &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } retAlgo = cipher->getAlgorithm(nullptr); @@ -4804,7 +4905,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest090, TestSize.Level0) ret = HCF_ERR_CRYPTO_OPERATION; } -clearup: +CLEAR_UP: HcfObjDestroy(cipher); EXPECT_NE(ret, 0); } @@ -4820,13 +4921,13 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest091, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = HcfCipherCreate(cipherName, &cipher); if (ret != 0) { LOGE("HcfCipherCreate failed!"); - goto clearup; + goto CLEAR_UP; } retAlgo = cipher->getAlgorithm(reinterpret_cast(generator)); @@ -4835,7 +4936,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest091, TestSize.Level0) ret = HCF_ERR_CRYPTO_OPERATION; } -clearup: +CLEAR_UP: HcfObjDestroy(generator); HcfObjDestroy(cipher); EXPECT_NE(ret, 0); @@ -4852,12 +4953,12 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest092, TestSize.Level0) ret = HcfSymKeyGeneratorCreate(inputAlgoName, &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } // generator getAlgoName @@ -4865,14 +4966,14 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest092, TestSize.Level0) if (generatorAlgoName == nullptr) { LOGE("generator getAlgoName returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; - goto clearup; + goto CLEAR_UP; } ret = strcmp(generatorAlgoName, inputAlgoName); if (ret != 0) { LOGE("generator getAlgoName failed!"); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(generator); EXPECT_EQ(ret, 0); @@ -4888,7 +4989,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest093, TestSize.Level0) ret = HcfSymKeyGeneratorCreate(inputAlgoName, &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } // generator getAlgoName @@ -4898,7 +4999,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest093, TestSize.Level0) ret = HCF_ERR_CRYPTO_OPERATION; } -clearup: +CLEAR_UP: HcfObjDestroy(generator); EXPECT_NE(ret, 0); } @@ -4914,12 +5015,12 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest094, TestSize.Level0) ret = HcfSymKeyGeneratorCreate(inputAlgoName, &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } // generator getAlgoName @@ -4929,7 +5030,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest094, TestSize.Level0) ret = HCF_ERR_CRYPTO_OPERATION; } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(generator); EXPECT_NE(ret, 0); @@ -4945,7 +5046,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest095, TestSize.Level0) ret = GenerateSymKey(inputAlgoName, &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } // key getAlgorithm @@ -4953,14 +5054,14 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest095, TestSize.Level0) if (keyAlgoName == nullptr) { LOGE("key getAlgorithm returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; - goto clearup; + goto CLEAR_UP; } ret = strcmp(keyAlgoName, inputAlgoName); if (ret != 0) { LOGE("key getAlgorithm failed!"); } -clearup: +CLEAR_UP: HcfObjDestroy(key); EXPECT_EQ(ret, 0); } @@ -4975,7 +5076,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest096, TestSize.Level0) ret = GenerateSymKey(inputAlgoName, &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } // key getAlgorithm @@ -4985,7 +5086,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest096, TestSize.Level0) ret = HCF_ERR_CRYPTO_OPERATION; } -clearup: +CLEAR_UP: HcfObjDestroy(key); EXPECT_NE(ret, 0); } @@ -5001,12 +5102,12 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest097, TestSize.Level0) ret = HcfSymKeyGeneratorCreate(inputAlgoName, &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } // key getAlgorithm @@ -5016,7 +5117,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest097, TestSize.Level0) ret = HCF_ERR_CRYPTO_OPERATION; } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(generator); EXPECT_NE(ret, 0); @@ -5032,7 +5133,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest098, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } // key GetFormat @@ -5040,7 +5141,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest098, TestSize.Level0) if (retFormat == nullptr) { LOGE("key GetFormat returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; - goto clearup; + goto CLEAR_UP; } ret = strcmp(retFormat, keyFormat); @@ -5048,7 +5149,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest098, TestSize.Level0) LOGE("key GetFormat failed!"); } -clearup: +CLEAR_UP: HcfObjDestroy(key); EXPECT_EQ(ret, 0); } @@ -5062,7 +5163,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest099, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { LOGE("GenerateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } // key getFormat @@ -5072,7 +5173,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest099, TestSize.Level0) ret = HCF_ERR_CRYPTO_OPERATION; } -clearup: +CLEAR_UP: HcfObjDestroy(key); EXPECT_NE(ret, 0); } @@ -5087,12 +5188,12 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest100, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } // key getFormat @@ -5102,7 +5203,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest100, TestSize.Level0) ret = HCF_ERR_CRYPTO_OPERATION; } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(generator); EXPECT_NE(ret, 0); @@ -5123,29 +5224,29 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest101, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } // key getEncoded ret = key->key.getEncoded(&(key->key), &encodedBlob); if (ret != 0) { LOGE("key GetEncoded failed."); - goto clearup; + goto CLEAR_UP; } if (encodedBlob.len != keyTmpBlob.len) { LOGE("key GetEncoded failed!"); ret = HCF_ERR_CRYPTO_OPERATION; - goto clearup; + goto CLEAR_UP; } ret = memcmp(encodedBlob.data, keyTmpBlob.data, keyTmpBlob.len); -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(generator); if (encodedBlob.data != nullptr) { @@ -5170,12 +5271,12 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest102, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } // key getEncoded @@ -5184,7 +5285,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest102, TestSize.Level0) LOGE("key GetEncoded failed."); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(generator); if (encodedBlob.data != nullptr) { @@ -5209,12 +5310,12 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest103, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } // key getEncoded @@ -5223,7 +5324,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest103, TestSize.Level0) LOGE("key GetEncoded failed."); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(generator); if (encodedBlob.data != nullptr) { @@ -5250,12 +5351,12 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest104, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } impl = reinterpret_cast(key); tmpLen = impl->keyMaterial.len; @@ -5268,7 +5369,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest104, TestSize.Level0) LOGE("key GetEncoded failed."); } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(generator); if (encodedBlob.data != nullptr) { @@ -5293,12 +5394,12 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest105, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); - goto clearup; + goto CLEAR_UP; } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { LOGE("generateSymKey failed!"); - goto clearup; + goto CLEAR_UP; } key->clearMem(nullptr); @@ -5306,14 +5407,14 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest105, TestSize.Level0) ret = key->key.getEncoded(&(key->key), &encodedBlob); if (ret != 0) { LOGE("key GetEncoded failed."); - goto clearup; + goto CLEAR_UP; } if ((encodedBlob.data != nullptr) && (encodedBlob.data[0] != '\0')) { LOGE("clearMem failed!"); ret = HCF_ERR_CRYPTO_OPERATION; } -clearup: +CLEAR_UP: HcfObjDestroy(key); HcfObjDestroy(generator); if (encodedBlob.data != nullptr) { @@ -5336,4 +5437,1178 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest106, TestSize.Level0) HcfObjDestroy(generator); EXPECT_NE(ret, 0); } + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest107, TestSize.Level0) +{ + int ret = 0; + HcfSymKeyGenerator *generator = nullptr; + + ret = HcfSymKeyGeneratorCreate("RSA512", &generator); + if (ret != 0) { + LOGE("HcfSymKeyGeneratorCreate failed! Should not select RSA for symKey generator."); + } + + HcfObjDestroy(generator); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest108, TestSize.Level0) +{ + int ret = 0; + HcfSymKeyGenerator *generator = nullptr; + + ret = HcfSymKeyGeneratorCreate("", &generator); + if (ret != 0) { + LOGE("HcfSymKeyGeneratorCreate failed! Should not select empty string for symKey generator."); + } + + HcfObjDestroy(generator); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest109, TestSize.Level0) +{ + int ret = 0; + HcfSymKeyGenerator *generator = nullptr; + + ret = HcfSymKeyGeneratorCreate(nullptr, &generator); + if (ret != 0) { + LOGE("HcfSymKeyGeneratorCreate failed! Should not select nullptr for symKey generator."); + } + + HcfObjDestroy(generator); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest110, TestSize.Level0) +{ + int ret = 0; + HcfSymKeyGenerator *generator = nullptr; + + ret = HcfSymKeyGeneratorSpiCreate(nullptr, nullptr); + if (ret != 0) { + LOGE("HcfSymKeyGeneratorSpiCreate failed!"); + } + + HcfObjDestroy(generator); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest111, TestSize.Level0) +{ + int ret = 0; + HcfSymKeyGenerator *generator = nullptr; + HcfSymKey *key = nullptr; + + ret = HcfSymKeyGeneratorCreate("AES128", &generator); + if (ret != 0) { + LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); + goto CLEAR_UP; + } + ret = generator->generateSymKey(nullptr, &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(generator); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest112, TestSize.Level0) +{ + int ret = 0; + HcfSymKeyGenerator *generator = nullptr; + HcfSymKey *key = nullptr; + HcfCipher *cipher = nullptr; + + ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + ret = HcfSymKeyGeneratorCreate("AES128", &generator); + if (ret != 0) { + LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); + goto CLEAR_UP; + } + ret = generator->generateSymKey(reinterpret_cast(cipher), &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(generator); + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest113, TestSize.Level0) +{ + int ret = 0; + HcfSymKeyGenerator *generator = nullptr; + HcfSymKey *key = nullptr; + uint8_t keyMaterial[] = { + 0xba, 0x3b, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, + 0xad, 0x47, 0xfc, 0x5a, 0x46, 0x39, 0xee, 0x7c + }; + HcfBlob keyTmpBlob = { .data = keyMaterial, .len = KEY_MATERIAL_LEN }; + + ret = HcfSymKeyGeneratorCreate("AES128", &generator); + if (ret != 0) { + LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); + goto CLEAR_UP; + } + + ret = generator->convertSymKey(nullptr, &keyTmpBlob, &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(generator); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest114, TestSize.Level0) +{ + int ret = 0; + HcfSymKeyGenerator *generator = nullptr; + HcfSymKey *key = nullptr; + uint8_t keyMaterial[] = { + 0xba, 0x3b, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, + 0xad, 0x47, 0xfc, 0x5a, 0x46, 0x39, 0xee, 0x7c + }; + HcfBlob keyTmpBlob = { .data = keyMaterial, .len = KEY_MATERIAL_LEN }; + HcfCipher *cipher = nullptr; + + ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + ret = HcfSymKeyGeneratorCreate("AES128", &generator); + if (ret != 0) { + LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); + goto CLEAR_UP; + } + + ret = generator->convertSymKey(reinterpret_cast(cipher), &keyTmpBlob, &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(generator); + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest115, TestSize.Level0) +{ + int ret = 0; + HcfSymKeyGenerator *generator = nullptr; + HcfSymKey *key = nullptr; + uint8_t keyMaterial[] = { + 0xba, 0x3b, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, + 0xad, 0x47, 0xfc, 0x5a, 0x46, 0x39, 0xee, 0x7c + }; + HcfBlob keyTmpBlob = { .data = keyMaterial, .len = 0 }; + + ret = HcfSymKeyGeneratorCreate("AES128", &generator); + if (ret != 0) { + LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); + goto CLEAR_UP; + } + + ret = generator->convertSymKey(generator, &keyTmpBlob, &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(generator); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest116, TestSize.Level0) +{ + int ret = 0; + HcfCipher *cipher = nullptr; + + ret = HcfCipherCreate("RSA128|GCM|NoPadding", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed! Should not select RSA for GCM generator."); + } + + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest117, TestSize.Level0) +{ + int ret = 0; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("GenerateSymKey failed!"); + goto CLEAR_UP; + } + + // allow input without encryption mode. It will pick the last PKCS5, and use default aes128ecb. + ret = HcfCipherCreate("AES128|NoPadding|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed! %d", ret); + goto CLEAR_UP; + } + + ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); + if (ret != 0) { + LOGE("AesDecrypt failed! %d", ret); + } +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest118, TestSize.Level0) +{ + int ret = 0; + HcfCipher *cipher = nullptr; + + // not allow '|' without content, because findAbility will fail for "" input + ret = HcfCipherCreate("AES128|GCM|", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed! Should select padding mode for AES generator."); + } + + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest119, TestSize.Level0) +{ + int ret = 0; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("GenerateSymKey failed!"); + goto CLEAR_UP; + } + + // allow input without encryption mode. It will use default aes128ecb. + ret = HcfCipherCreate("AES128|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed! %d", ret); + goto CLEAR_UP; + } + + ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); + if (ret != 0) { + LOGE("AesDecrypt failed! %d", ret); + } +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest120, TestSize.Level0) +{ + int ret = 0; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("GenerateSymKey failed!"); + goto CLEAR_UP; + } + + // allow input without encryption mode. It will use default aes128ecb. + ret = HcfCipherCreate("AES128", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed! %d", ret); + goto CLEAR_UP; + } + + ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); + if (ret != 0) { + LOGE("AesDecrypt failed! %d", ret); + } +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest121, TestSize.Level0) +{ + int ret = 0; + HcfCipher *cipher = nullptr; + + ret = HcfCipherCreate("", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + } + + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest122, TestSize.Level0) +{ + int ret = 0; + HcfCipher *cipher = nullptr; + + ret = HcfCipherCreate(nullptr, &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + } + + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest123, TestSize.Level0) +{ + int ret = 0; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("GenerateSymKey failed!"); + goto CLEAR_UP; + } + + // allow input with more than one padding mode. It will pick the last PKCS5. + ret = HcfCipherCreate("AES128|ECB|NoPadding|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed! %d", ret); + goto CLEAR_UP; + } + + ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); + if (ret != 0) { + LOGE("AesDecrypt failed! %d", ret); + } +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest124, TestSize.Level0) +{ + int ret = 0; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("GenerateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES256|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + // It is not allowed that AES128 in key is smaller AES256 in cipher. + ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed! %d", ret); + goto CLEAR_UP; + } + + ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); + if (ret != 0) { + LOGE("AesDecrypt failed! %d", ret); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest125, TestSize.Level0) +{ + int ret = 0; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + + ret = GenerateSymKey("AES256", &key); + if (ret != 0) { + LOGE("GenerateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed! %d", ret); + goto CLEAR_UP; + } + + ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); + if (ret != 0) { + LOGE("AesDecrypt failed! %d", ret); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest126, TestSize.Level0) +{ + int ret = 0; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("GenerateSymKey failed!"); + goto CLEAR_UP; + } + + // CBC, CTR, OFB, CFB enc/dec success, + // GCM, CCM enc/dec failed with params set to nullptr. + ret = HcfCipherCreate("AES128|GCM|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed! %d", ret); + goto CLEAR_UP; + } + + ret = AesDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); + if (ret != 0) { + LOGE("AesDecrypt failed! %d", ret); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest127, TestSize.Level0) +{ + int ret = 0; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("GenerateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = cipher->init(nullptr, ENCRYPT_MODE, &(key->key), nullptr); + if (ret != 0) { + LOGE("init failed! Should input cipher when init."); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest128, TestSize.Level0) +{ + int ret = 0; + HcfSymKeyGenerator *generator = nullptr; + HcfCipher *cipher = nullptr; + + ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = cipher->init(cipher, ENCRYPT_MODE, nullptr, nullptr); + if (ret != 0) { + LOGE("init failed! Should input key when init."); + } + +CLEAR_UP: + HcfObjDestroy(cipher); + HcfObjDestroy(generator); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest129, TestSize.Level0) +{ + int ret = 0; + HcfSymKeyGenerator *generator = nullptr; + HcfSymKey *key = nullptr; + HcfCipher *cipher = nullptr; + + ret = HcfSymKeyGeneratorCreate("AES128", &generator); + if (ret != 0) { + LOGE("HcfSymKeyGeneratorCreate failed!%d", ret); + goto CLEAR_UP; + } + ret = generator->generateSymKey(generator, &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = cipher->init(reinterpret_cast(generator), ENCRYPT_MODE, &(key->key), nullptr); + if (ret != 0) { + LOGE("init failed! Should input key when init."); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + HcfObjDestroy(generator); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest130, TestSize.Level0) +{ + int ret = 0; + uint8_t aad[GCM_AAD_LEN] = { 0 }; + uint8_t tag[GCM_TAG_LEN] = { 0 }; + uint8_t iv[GCM_IV_LEN] = { 0 }; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + + HcfGcmParamsSpec spec = {}; + spec.aad.data = nullptr; + spec.aad.len = sizeof(aad); + spec.tag.data = tag; + spec.tag.len = sizeof(tag); + spec.iv.data = iv; + spec.iv.len = sizeof(iv); + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed, ret:%d!", ret); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest131, TestSize.Level0) +{ + int ret = 0; + uint8_t aad[GCM_AAD_LEN] = { 0 }; + uint8_t tag[GCM_TAG_LEN] = { 0 }; + uint8_t iv[GCM_IV_LEN] = { 0 }; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + + HcfGcmParamsSpec spec = {}; + spec.aad.data = aad; + spec.aad.len = sizeof(aad); + spec.tag.data = tag; + spec.tag.len = sizeof(tag); + spec.iv.data = nullptr; + spec.iv.len = sizeof(iv); + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed, ret:%d!", ret); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest132, TestSize.Level0) +{ + int ret = 0; + uint8_t aad[GCM_AAD_LEN] = { 0 }; + uint8_t tag[GCM_TAG_LEN] = { 0 }; + uint8_t iv[GCM_IV_LEN] = { 0 }; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + + HcfGcmParamsSpec spec = {}; + spec.aad.data = aad; + spec.aad.len = sizeof(aad); + spec.tag.data = nullptr; + spec.tag.len = sizeof(tag); + spec.iv.data = iv; + spec.iv.len = sizeof(iv); + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed, ret:%d!", ret); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest133, TestSize.Level0) +{ + int ret = 0; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|CCM|NoPadding", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed!"); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest134, TestSize.Level0) +{ + int ret = 0; + uint8_t aad[CCM_AAD_LEN] = { 0 }; + uint8_t tag[CCM_TAG_LEN] = { 0 }; + uint8_t iv[CCM_IV_LEN] = { 0 }; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + HcfCcmParamsSpec spec = {}; + spec.aad.data = nullptr; + spec.aad.len = sizeof(aad); + spec.tag.data = tag; + spec.tag.len = sizeof(tag); + spec.iv.data = iv; + spec.iv.len = sizeof(iv); + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|CCM|NoPadding", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed!"); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest135, TestSize.Level0) +{ + int ret = 0; + uint8_t aad[CCM_AAD_LEN] = { 0 }; + uint8_t tag[CCM_TAG_LEN] = { 0 }; + uint8_t iv[CCM_IV_LEN] = { 0 }; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + HcfCcmParamsSpec spec = {}; + spec.aad.data = aad; + spec.aad.len = sizeof(aad); + spec.tag.data = tag; + spec.tag.len = sizeof(tag); + spec.iv.data = nullptr; + spec.iv.len = sizeof(iv); + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|CCM|NoPadding", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed!"); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest136, TestSize.Level0) +{ + int ret = 0; + uint8_t aad[CCM_AAD_LEN] = { 0 }; + uint8_t tag[CCM_TAG_LEN] = { 0 }; + uint8_t iv[CCM_IV_LEN] = { 0 }; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + HcfCcmParamsSpec spec = {}; + spec.aad.data = aad; + spec.aad.len = sizeof(aad); + spec.tag.data = nullptr; + spec.tag.len = sizeof(tag); + spec.iv.data = iv; + spec.iv.len = sizeof(iv); + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|CCM|NoPadding", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed!"); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest137, TestSize.Level0) +{ + int ret = 0; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + uint8_t plainText[] = "this is test!"; + HcfBlob input = { .data = plainText, .len = 0 }; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncryptWithInput(cipher, key, &input, cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed! %d", ret); + goto CLEAR_UP; + } + + ret = AesDecryptEmptyMsg(cipher, key, nullptr, cipherText, cipherTextLen); + if (ret != 0) { + LOGE("AesDecrypt failed! %d", ret); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest138, TestSize.Level0) +{ + int ret = 0; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + HcfBlob input = { .data = nullptr, .len = 0 }; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesEncryptWithInput(cipher, key, &input, cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed! %d", ret); + goto CLEAR_UP; + } + + ret = AesDecryptEmptyMsg(cipher, key, nullptr, cipherText, cipherTextLen); + if (ret != 0) { + LOGE("AesDecrypt failed! %d", ret); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest139, TestSize.Level0) +{ + int ret = 0; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + HcfBlob input = { .data = nullptr, .len = PLAINTEXT_LEN }; + HcfBlob output = { .data = nullptr, .len = 0 }; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); + if (ret != 0) { + LOGE("init failed!"); + goto CLEAR_UP; + } + + ret = cipher->update(nullptr, &input, &output); + if (ret != 0) { + LOGE("update failed! Blob data should not be nullptr."); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + if (output.data != nullptr) { + HcfFree(output.data); + output.data = nullptr; + } + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest140, TestSize.Level0) +{ + int ret = 0; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + HcfBlob input = { .data = nullptr, .len = PLAINTEXT_LEN }; + HcfBlob output = { .data = nullptr, .len = 0 }; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); + if (ret != 0) { + LOGE("init failed!"); + goto CLEAR_UP; + } + + ret = cipher->update(reinterpret_cast(key), &input, &output); + if (ret != 0) { + LOGE("update failed! Blob data should not be nullptr."); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + if (output.data != nullptr) { + HcfFree(output.data); + output.data = nullptr; + } + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest141, TestSize.Level0) +{ + int ret = 0; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + uint8_t cipherText[CIPHER_TEXT_LEN] = { 0 }; + int cipherTextLen = CIPHER_TEXT_LEN; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = AesNoUpdateEncWithInput(cipher, key, nullptr, cipherText, &cipherTextLen); + if (ret != 0) { + LOGE("AesEncrypt failed! %d", ret); + goto CLEAR_UP; + } + + ret = AesDecryptEmptyMsg(cipher, key, nullptr, cipherText, cipherTextLen); + if (ret != 0) { + LOGE("AesDecrypt failed! %d", ret); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest142, TestSize.Level0) +{ + int ret = 0; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + uint8_t plainText[] = "this is test!"; + HcfBlob input = { .data = plainText, .len = PLAINTEXT_LEN }; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); + if (ret != 0) { + LOGE("init failed!"); + goto CLEAR_UP; + } + + ret = cipher->doFinal(cipher, &input, nullptr); + if (ret != 0) { + LOGE("update failed! Blob data should not be nullptr."); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest143, TestSize.Level0) +{ + int ret = 0; + HcfCipher *cipher = nullptr; + HcfSymKey *key = nullptr; + uint8_t plainText[] = "this is test!"; + HcfBlob input = { .data = plainText, .len = PLAINTEXT_LEN }; + HcfBlob output = { .data = nullptr, .len = 0 }; + + ret = GenerateSymKey("AES128", &key); + if (ret != 0) { + LOGE("generateSymKey failed!"); + goto CLEAR_UP; + } + + ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); + if (ret != 0) { + LOGE("HcfCipherCreate failed!"); + goto CLEAR_UP; + } + + ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); + if (ret != 0) { + LOGE("init failed!"); + goto CLEAR_UP; + } + + ret = cipher->doFinal(reinterpret_cast(key), &input, &output); + if (ret != 0) { + LOGE("update failed! Blob data should not be nullptr."); + } + +CLEAR_UP: + HcfObjDestroy(key); + HcfObjDestroy(cipher); + if (output.data != nullptr) { + HcfFree(output.data); + output.data = nullptr; + } + EXPECT_NE(ret, 0); +} + +HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest144, TestSize.Level0) +{ + int ret = HcfCipherAesGeneratorSpiCreate(nullptr, nullptr); + if (ret != 0) { + LOGE("HcfCipherAesGeneratorSpiCreate failed!"); + } + EXPECT_NE(ret, 0); +} } \ No newline at end of file