From 3110b7a89a551315cf5fbfaa9d06a4d2038be8e2 Mon Sep 17 00:00:00 2001 From: zhangqiang Date: Sat, 24 Aug 2024 10:58:57 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fuzz=E7=94=A8=E4=BE=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangqiang --- .../hcfciphercreate_fuzzer.cpp | 2 +- .../hcfkeyagreementcreate_fuzzer/corpus/init | 2 +- .../hcfmaccreate_fuzzer.cpp | 21 +++++++++++-------- .../hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp | 5 ++++- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/test/fuzztest/crypto_operation/hcfciphercreate_fuzzer/hcfciphercreate_fuzzer.cpp b/test/fuzztest/crypto_operation/hcfciphercreate_fuzzer/hcfciphercreate_fuzzer.cpp index 7b37ad4..727dd12 100755 --- a/test/fuzztest/crypto_operation/hcfciphercreate_fuzzer/hcfciphercreate_fuzzer.cpp +++ b/test/fuzztest/crypto_operation/hcfciphercreate_fuzzer/hcfciphercreate_fuzzer.cpp @@ -332,7 +332,7 @@ namespace OHOS { return; } (void)cipher->init(cipher, DECRYPT_MODE, reinterpret_cast(keyPair->priKey), nullptr); - (void)cipher->doFinal(cipher, &encoutput, &decoutput); + (void)cipher->doFinal(cipher, &input, &decoutput); HcfBlobDataClearAndFree(&encoutput); HcfBlobDataClearAndFree(&decoutput); HcfObjDestroy(generator); diff --git a/test/fuzztest/crypto_operation/hcfkeyagreementcreate_fuzzer/corpus/init b/test/fuzztest/crypto_operation/hcfkeyagreementcreate_fuzzer/corpus/init index 2be750d..5786153 100755 --- a/test/fuzztest/crypto_operation/hcfkeyagreementcreate_fuzzer/corpus/init +++ b/test/fuzztest/crypto_operation/hcfkeyagreementcreate_fuzzer/corpus/init @@ -11,4 +11,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -FUZZ \ No newline at end of file +ECC256 \ No newline at end of file diff --git a/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp b/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp index 35be61e..940996a 100755 --- a/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp +++ b/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "blob.h" #include "mac.h" @@ -25,20 +26,20 @@ #include "sym_key_generator.h" namespace OHOS { - static const int KEY_LEN = 16; + static const char *g_testMacAlg[] = { "MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512", "SM3"}; static void TestMacConvertSymKey(const uint8_t* data, size_t size) { - HcfMac *macObj = nullptr; + HcfMac *macObj = nullptr; HcfResult res = HcfMacCreate("SHA1", &macObj); if (res != HCF_SUCCESS) { return; } HcfSymKeyGenerator *generator = nullptr; - (void)HcfSymKeyGeneratorCreate("AES128", &generator); + (void)HcfSymKeyGeneratorCreate("HMAC", &generator); HcfSymKey *key = nullptr; HcfBlob keyMaterialBlob = {.data = const_cast(data), .len = size}; - generator->convertSymKey(generator, &keyMaterialBlob, &key); + (void)generator->convertSymKey(generator, &keyMaterialBlob, &key); HcfObjDestroy(macObj); HcfObjDestroy(key); @@ -48,17 +49,19 @@ namespace OHOS { static void TestMac(const uint8_t* data, size_t size) { HcfMac *macObj = nullptr; - HcfResult res = HcfMacCreate("SHA1", &macObj); + int index = rand() % 7; + HcfResult res = HcfMacCreate(g_testMacAlg[index], &macObj); if (res != HCF_SUCCESS) { return; } HcfSymKeyGenerator *generator = nullptr; (void)HcfSymKeyGeneratorCreate("AES128", &generator); - char testKey[] = "abcdefghijklmnop"; - uint32_t testKeyLen = KEY_LEN; HcfSymKey *key = nullptr; - HcfBlob keyMaterialBlob = {.data = reinterpret_cast(testKey), .len = testKeyLen}; - generator->convertSymKey(generator, &keyMaterialBlob, &key); + HcfBlob keyMaterialBlob = {.data = reinterpret_cast(data), .len = size}; + res = generator->convertSymKey(generator, &keyMaterialBlob, &key); + if (res != HCF_SUCCESS) { + return; + } HcfBlob inBlob = {.data = const_cast(data), .len = size}; (void)macObj->init(macObj, key); diff --git a/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp b/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp index 91e62ff..d7c7764 100755 --- a/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp +++ b/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include "blob.h" @@ -24,10 +25,12 @@ #include "result.h" namespace OHOS { + static const char *g_testMdAlg[] = { "MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512", "SM3"}; static void TestMd(const uint8_t* data, size_t size) { HcfMd *mdObj = nullptr; - HcfResult res = HcfMdCreate("SHA1", &mdObj); + int index = rand() % 7; + HcfResult res = HcfMdCreate(g_testMdAlg[index], &mdObj); if (res != HCF_SUCCESS) { return; } -- Gitee From 73dd7be2d7cf952c3a9b904911e907c183c2e158 Mon Sep 17 00:00:00 2001 From: zhangqiang Date: Sat, 24 Aug 2024 11:25:37 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fuzz=E7=94=A8=E4=BE=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangqiang --- .../hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp b/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp index 940996a..7a887bc 100755 --- a/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp +++ b/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp @@ -30,7 +30,7 @@ namespace OHOS { static const char *g_testMacAlg[] = { "MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512", "SM3"}; static void TestMacConvertSymKey(const uint8_t* data, size_t size) { - HcfMac *macObj = nullptr; + HcfMac *macObj = nullptr; HcfResult res = HcfMacCreate("SHA1", &macObj); if (res != HCF_SUCCESS) { return; @@ -55,7 +55,7 @@ namespace OHOS { return; } HcfSymKeyGenerator *generator = nullptr; - (void)HcfSymKeyGeneratorCreate("AES128", &generator); + (void)HcfSymKeyGeneratorCreate("HMAC", &generator); HcfSymKey *key = nullptr; HcfBlob keyMaterialBlob = {.data = reinterpret_cast(data), .len = size}; res = generator->convertSymKey(generator, &keyMaterialBlob, &key); -- Gitee From d6300aefaca9d1261c6cb1f51978038721e8b40d Mon Sep 17 00:00:00 2001 From: zhangqiang Date: Sat, 24 Aug 2024 15:27:46 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fuzz=E7=94=A8=E4=BE=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangqiang --- .../hcfmaccreate_fuzzer.cpp | 34 +++++++++---------- .../hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp | 28 +++++++-------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp b/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp index 7a887bc..fcf08f1 100755 --- a/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp +++ b/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include "blob.h" #include "mac.h" @@ -48,30 +47,31 @@ namespace OHOS { static void TestMac(const uint8_t* data, size_t size) { - HcfMac *macObj = nullptr; - int index = rand() % 7; - HcfResult res = HcfMacCreate(g_testMacAlg[index], &macObj); - if (res != HCF_SUCCESS) { - return; - } HcfSymKeyGenerator *generator = nullptr; (void)HcfSymKeyGeneratorCreate("HMAC", &generator); HcfSymKey *key = nullptr; HcfBlob keyMaterialBlob = {.data = reinterpret_cast(data), .len = size}; - res = generator->convertSymKey(generator, &keyMaterialBlob, &key); + HcfResult res = generator->convertSymKey(generator, &keyMaterialBlob, &key); if (res != HCF_SUCCESS) { return; } + for (int index = 0; index < sizeof(g_testMacAlg)/g_testMacAlg[0]; index++) { + HcfMac *macObj = nullptr; + res = HcfMacCreate(g_testMacAlg[index], &macObj); + if (res != HCF_SUCCESS) { + return; + } - HcfBlob inBlob = {.data = const_cast(data), .len = size}; - (void)macObj->init(macObj, key); - (void)macObj->update(macObj, &inBlob); - HcfBlob outBlob = { 0 }; - (void)macObj->doFinal(macObj, &outBlob); - (void)macObj->getAlgoName(macObj); - (void)macObj->getMacLength(macObj); - HcfBlobDataClearAndFree(&outBlob); - HcfObjDestroy(macObj); + HcfBlob inBlob = {.data = const_cast(data), .len = size}; + (void)macObj->init(macObj, key); + (void)macObj->update(macObj, &inBlob); + HcfBlob outBlob = { 0 }; + (void)macObj->doFinal(macObj, &outBlob); + (void)macObj->getAlgoName(macObj); + (void)macObj->getMacLength(macObj); + HcfBlobDataClearAndFree(&outBlob); + HcfObjDestroy(macObj); + } HcfObjDestroy(key); HcfObjDestroy(generator); } diff --git a/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp b/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp index d7c7764..5962621 100755 --- a/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp +++ b/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include "blob.h" @@ -28,20 +27,21 @@ namespace OHOS { static const char *g_testMdAlg[] = { "MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512", "SM3"}; static void TestMd(const uint8_t* data, size_t size) { - HcfMd *mdObj = nullptr; - int index = rand() % 7; - HcfResult res = HcfMdCreate(g_testMdAlg[index], &mdObj); - if (res != HCF_SUCCESS) { - return; + for (int index = 0; index < sizeof(g_testMdAlg)/g_testMdAlg[0]; index++) { + HcfMd *mdObj = nullptr; + HcfResult res = HcfMdCreate(g_testMdAlg[index], &mdObj); + if (res != HCF_SUCCESS) { + return; + } + HcfBlob inBlob = {.data = const_cast(data), .len = size}; + (void)mdObj->update(mdObj, &inBlob); + HcfBlob outBlob = { 0 }; + (void)mdObj->doFinal(mdObj, &outBlob); + (void)mdObj->getAlgoName(mdObj); + (void)mdObj->getMdLength(mdObj); + HcfBlobDataClearAndFree(&outBlob); + HcfObjDestroy(mdObj); } - HcfBlob inBlob = {.data = const_cast(data), .len = size}; - (void)mdObj->update(mdObj, &inBlob); - HcfBlob outBlob = { 0 }; - (void)mdObj->doFinal(mdObj, &outBlob); - (void)mdObj->getAlgoName(mdObj); - (void)mdObj->getMdLength(mdObj); - HcfBlobDataClearAndFree(&outBlob); - HcfObjDestroy(mdObj); } bool HcMdCreateFuzzTest(const uint8_t* data, size_t size) -- Gitee From ae66eaeeff296691e168dfde9f92d0402a3c3679 Mon Sep 17 00:00:00 2001 From: zhangqiang Date: Sat, 24 Aug 2024 15:30:54 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fuzz=E7=94=A8=E4=BE=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangqiang --- .../hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp | 2 +- .../crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp b/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp index fcf08f1..2bb3312 100755 --- a/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp +++ b/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp @@ -55,7 +55,7 @@ namespace OHOS { if (res != HCF_SUCCESS) { return; } - for (int index = 0; index < sizeof(g_testMacAlg)/g_testMacAlg[0]; index++) { + for (size_t index = 0; index < sizeof(g_testMacAlg)/g_testMacAlg[0]; index++) { HcfMac *macObj = nullptr; res = HcfMacCreate(g_testMacAlg[index], &macObj); if (res != HCF_SUCCESS) { diff --git a/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp b/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp index 5962621..d577578 100755 --- a/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp +++ b/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp @@ -27,7 +27,7 @@ namespace OHOS { static const char *g_testMdAlg[] = { "MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512", "SM3"}; static void TestMd(const uint8_t* data, size_t size) { - for (int index = 0; index < sizeof(g_testMdAlg)/g_testMdAlg[0]; index++) { + for (size_t index = 0; index < sizeof(g_testMdAlg)/g_testMdAlg[0]; index++) { HcfMd *mdObj = nullptr; HcfResult res = HcfMdCreate(g_testMdAlg[index], &mdObj); if (res != HCF_SUCCESS) { -- Gitee From 8486b9a379d42921477be6d614a4a08f55b35df4 Mon Sep 17 00:00:00 2001 From: zhangqiang Date: Sat, 24 Aug 2024 16:02:16 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fuzz=E7=94=A8=E4=BE=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangqiang --- .../hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp | 2 +- .../crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp b/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp index 2bb3312..df47946 100755 --- a/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp +++ b/test/fuzztest/crypto_operation/hcfmaccreate_fuzzer/hcfmaccreate_fuzzer.cpp @@ -55,7 +55,7 @@ namespace OHOS { if (res != HCF_SUCCESS) { return; } - for (size_t index = 0; index < sizeof(g_testMacAlg)/g_testMacAlg[0]; index++) { + for (size_t index = 0; index < sizeof(g_testMacAlg)/sizeof(g_testMacAlg[0]); index++) { HcfMac *macObj = nullptr; res = HcfMacCreate(g_testMacAlg[index], &macObj); if (res != HCF_SUCCESS) { diff --git a/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp b/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp index d577578..32fd8e5 100755 --- a/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp +++ b/test/fuzztest/crypto_operation/hcfmdcreate_fuzzer/hcfmdcreate_fuzzer.cpp @@ -27,7 +27,7 @@ namespace OHOS { static const char *g_testMdAlg[] = { "MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512", "SM3"}; static void TestMd(const uint8_t* data, size_t size) { - for (size_t index = 0; index < sizeof(g_testMdAlg)/g_testMdAlg[0]; index++) { + for (size_t index = 0; index < sizeof(g_testMdAlg)/sizeof(g_testMdAlg[0]); index++) { HcfMd *mdObj = nullptr; HcfResult res = HcfMdCreate(g_testMdAlg[index], &mdObj); if (res != HCF_SUCCESS) { -- Gitee From 8eaf740517291d4674b362f18c80e46ec62506d9 Mon Sep 17 00:00:00 2001 From: zhangqiang Date: Sat, 24 Aug 2024 16:37:19 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fuzz=E7=94=A8=E4=BE=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangqiang --- .../hcfciphercreate_fuzzer.cpp | 14 ++++++++------ .../hcfkdfcreate_fuzzer/hcfkdfcreate_fuzzer.cpp | 13 +++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/test/fuzztest/crypto_operation/hcfciphercreate_fuzzer/hcfciphercreate_fuzzer.cpp b/test/fuzztest/crypto_operation/hcfciphercreate_fuzzer/hcfciphercreate_fuzzer.cpp index 727dd12..27566bf 100755 --- a/test/fuzztest/crypto_operation/hcfciphercreate_fuzzer/hcfciphercreate_fuzzer.cpp +++ b/test/fuzztest/crypto_operation/hcfciphercreate_fuzzer/hcfciphercreate_fuzzer.cpp @@ -28,6 +28,8 @@ #include "sym_key_generator.h" #include "detailed_gcm_params.h" +#define TEST_DATA_MAX_SIZE 1024 + namespace OHOS { static int32_t AesEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfBlob *input, uint8_t *cipherText, int *cipherTextLen) @@ -191,8 +193,8 @@ namespace OHOS { { int ret = 0; HcfBlob input = {.data = const_cast(plan), .len = size}; - uint8_t cipherText[128] = {0}; - int cipherTextLen = 128; + uint8_t cipherText[TEST_DATA_MAX_SIZE] = {0}; + int cipherTextLen = TEST_DATA_MAX_SIZE; HcfSymKeyGenerator *generator = nullptr; HcfCipher *cipher = nullptr; HcfSymKey *key = nullptr; @@ -223,8 +225,8 @@ namespace OHOS { { int ret = 0; HcfBlob input = {.data = const_cast(plan), .len = size}; - uint8_t cipherText[128] = {0}; - int cipherTextLen = 128; + uint8_t cipherText[TEST_DATA_MAX_SIZE] = {0}; + int cipherTextLen = TEST_DATA_MAX_SIZE; HcfSymKeyGenerator *generator = nullptr; HcfCipher *cipher = nullptr; HcfSymKey *key = nullptr; @@ -258,8 +260,8 @@ namespace OHOS { uint8_t aad[8] = {0}; uint8_t tag[16] = {0}; uint8_t iv[12] = {0}; // openssl only support nonce 12 bytes, tag 16bytes - uint8_t cipherText[128] = {0}; - int cipherTextLen = 128; + uint8_t cipherText[TEST_DATA_MAX_SIZE] = {0}; + int cipherTextLen = TEST_DATA_MAX_SIZE; HcfGcmParamsSpec spec = {}; spec.aad.data = aad; diff --git a/test/fuzztest/crypto_operation/hcfkdfcreate_fuzzer/hcfkdfcreate_fuzzer.cpp b/test/fuzztest/crypto_operation/hcfkdfcreate_fuzzer/hcfkdfcreate_fuzzer.cpp index 9fb427d..66a702e 100644 --- a/test/fuzztest/crypto_operation/hcfkdfcreate_fuzzer/hcfkdfcreate_fuzzer.cpp +++ b/test/fuzztest/crypto_operation/hcfkdfcreate_fuzzer/hcfkdfcreate_fuzzer.cpp @@ -26,6 +26,8 @@ #include "kdf.h" #include "result.h" +#define TEST_DATA_MAX_SIZE 1024 + namespace OHOS { static const char *g_testKdfAlg[] = { "HKDF|SHA1", "HKDF|SHA224", "HKDF|SHA256", "HKDF|SHA384", "HKDF|SHA512", "HKDF|SM3", "PBKDF2|SHA1", "PBKDF2|SHA224", "PBKDF2|SHA256", "PBKDF2|SHA384", @@ -33,8 +35,7 @@ namespace OHOS { static const char *g_keyData = "012345678901234567890123456789"; static const char *g_infoData = "infostring"; static const char *g_saltData = "saltstring"; - constexpr uint32_t OUT_PUT_MAX_LENGTH = 128; - constexpr uint32_t OUT_PUT_NORMAL_LENGTH = 32; + constexpr uint32_t OUT_PUT_MAX_LENGTH = TEST_DATA_MAX_SIZE; constexpr uint32_t SALT_NORMAL_LENGTH = 16; static void TestHkdfGenerateSecretSalt(const char *kdfAlg, const uint8_t* data, size_t size) @@ -45,7 +46,7 @@ namespace OHOS { return; } uint8_t out[OUT_PUT_MAX_LENGTH] = {0}; - HcfBlob output = {.data = out, .len = OUT_PUT_NORMAL_LENGTH}; + HcfBlob output = {.data = out, .len = size}; HcfBlob salt = {.data = const_cast(data), .len = size}; HcfBlob key = {.data = reinterpret_cast(const_cast(g_keyData)), .len = strlen(g_keyData)}; @@ -72,7 +73,7 @@ namespace OHOS { return; } uint8_t out[OUT_PUT_MAX_LENGTH] = {0}; - HcfBlob output = {.data = out, .len = OUT_PUT_NORMAL_LENGTH}; + HcfBlob output = {.data = out, .len = size}; HcfBlob key = {.data = const_cast(data), .len = size}; HcfBlob salt = {.data = reinterpret_cast(const_cast(g_saltData)), .len = strlen(g_saltData)}; @@ -99,7 +100,7 @@ namespace OHOS { return; } uint8_t out[OUT_PUT_MAX_LENGTH] = {0}; - HcfBlob output = {.data = out, .len = OUT_PUT_NORMAL_LENGTH}; + HcfBlob output = {.data = out, .len = size}; HcfBlob info = {.data = const_cast(data), .len = size}; HcfBlob key = {.data = reinterpret_cast(const_cast(g_keyData)), .len = strlen(g_keyData)}; @@ -127,7 +128,7 @@ namespace OHOS { } uint8_t out[OUT_PUT_MAX_LENGTH] = {0}; uint8_t saltData[SALT_NORMAL_LENGTH] = {0}; - HcfBlob output = {.data = out, .len = OUT_PUT_NORMAL_LENGTH}; + HcfBlob output = {.data = out, .len = size}; HcfBlob salt = {.data = saltData, .len = SALT_NORMAL_LENGTH}; HcfBlob password = {.data = const_cast(data), .len = size}; HcfPBKDF2ParamsSpec params = { -- Gitee