/* * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @addtogroup CryptoDigestApi * @{ * * @brief Describe openHarmony digest interfaces provide for applications. * * @since 12 */ /** * @file crypto_digest.h * * @brief Defines the digest apis. * * @library libohcrypto.so * @kit Crypto Architecture Kit * @syscap SystemCapability.Security.CryptoFramework * @since 12 */ #ifndef CRYPTO_DIGEST_H #define CRYPTO_DIGEST_H #include "crypto_common.h" #ifdef __cplusplus extern "C" { #endif /** * @brief Define the digest structure. * * @since 12 */ typedef struct OH_CryptoDigest OH_CryptoDigest; /** * @brief Create a digest context according to the given algorithm name. * * @param algoName Indicates the algorithm name for generating the digest context. Example SHA256. * @param ctx Indicates the pointer to the md context. * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed. * @since 12 */ OH_Crypto_ErrCode OH_CryptoDigest_Create(const char *algoName, OH_CryptoDigest **ctx); /** * @brief Update digest with dataBlob. * * @param ctx Indicates the digest context. * @param in Indicates the dataBlob. * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed. * @see OH_CryptoDigest_Final * @since 12 */ OH_Crypto_ErrCode OH_CryptoDigest_Update(OH_CryptoDigest *ctx, Crypto_DataBlob *in); /** * @brief Final digest with dataBlob. * * @param ctx Indicates the digest context. * @param out Indicates the result as dataBlob. * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed. * @see OH_CryptoDigest_Update * @since 12 */ OH_Crypto_ErrCode OH_CryptoDigest_Final(OH_CryptoDigest *ctx, Crypto_DataBlob *out); /** * @brief Get the digest length of the digest context. * * @param ctx Indicates the digest context. * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed. * @since 12 */ uint32_t OH_CryptoDigest_GetLength(OH_CryptoDigest *ctx); /** * @brief Get the algorithm name of the digest context. * * @param ctx Indicates the digest context. * @return Return md algorithm name. * @since 12 */ const char *OH_CryptoDigest_GetAlgoName(OH_CryptoDigest *ctx); /** * @brief Destroy the digest context. * * @param ctx Indicates the digest context. * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed. * @since 12 */ void OH_DigestCrypto_Destroy(OH_CryptoDigest *ctx); #ifdef __cplusplus } #endif /** @} */ #endif /* CRYPTO_DIGEST_H */