1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 // [Start message_digest_calculation_digest_algorithm_one_time_incoming]
17
18 #include "CryptoArchitectureKit/crypto_common.h"
19 #include "CryptoArchitectureKit/crypto_digest.h"
20 #include <cstring>
21 #include "file.h"
22
doTestMd()23 OH_Crypto_ErrCode doTestMd()
24 {
25 OH_Crypto_ErrCode ret;
26 OH_CryptoDigest *ctx = nullptr;
27 char *testData = const_cast<char *>("0123456789");
28 Crypto_DataBlob in = {.data = (uint8_t *)(testData), .len = strlen(testData)};
29 Crypto_DataBlob out = {.data = nullptr, .len = 0};
30 int mdLen = 0;
31 ret = OH_CryptoDigest_Create("SHA256", &ctx);
32 if (ret != CRYPTO_SUCCESS) {
33 return ret;
34 }
35 do {
36 ret = OH_CryptoDigest_Update(ctx, &in);
37 if (ret != CRYPTO_SUCCESS) {
38 break;
39 }
40 ret = OH_CryptoDigest_Final(ctx, &out);
41 if (ret != CRYPTO_SUCCESS) {
42 break;
43 }
44 mdLen = OH_CryptoDigest_GetLength(ctx);
45 } while (0);
46 OH_Crypto_FreeDataBlob(&out);
47 OH_DigestCrypto_Destroy(ctx);
48 return ret;
49 }
50
51 // [End message_digest_calculation_digest_algorithm_one_time_incoming]