crypto_digest.h

Overview

Defines APIs for MD algorithms.

Header file: <CryptoArchitectureKit/crypto_digest.h>

Library: libohcrypto.so

System capability: SystemCapability.Security.CryptoFramework

Since: 12

Related module: CryptoDigestApi

Summary

Structs

Name typedef Keyword Description
OH_CryptoDigest OH_CryptoDigest Defines an MD.

Functions

Name Description
OH_Crypto_ErrCode OH_CryptoDigest_Create(const char *algoName, OH_CryptoDigest **ctx) Creates an MD instance based on the given algorithm name.
Note: The created resource must be destroyed by calling OH_DigestCrypto_Destroy.
OH_Crypto_ErrCode OH_CryptoDigest_Update(OH_CryptoDigest *ctx, Crypto_DataBlob *in) Updates MD data.
OH_Crypto_ErrCode OH_CryptoDigest_Final(OH_CryptoDigest *ctx, Crypto_DataBlob *out) Implements MD calculation.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.
uint32_t OH_CryptoDigest_GetLength(OH_CryptoDigest *ctx) Obtains the length of an MD.
const char *OH_CryptoDigest_GetAlgoName(OH_CryptoDigest *ctx) Obtains the name of an MD algorithm.
void OH_DigestCrypto_Destroy(OH_CryptoDigest *ctx) Destroys an MD instance.

Function Description

OH_CryptoDigest_Create()

OH_Crypto_ErrCode OH_CryptoDigest_Create(const char *algoName, OH_CryptoDigest **ctx)

Description

Creates an MD instance based on the given algorithm name.
Note: The created resource must be destroyed by calling OH_DigestCrypto_Destroy.

Since: 12

Parameters

Name Description
const char *algoName Pointer to the algorithm used to generate the MD instance.
For example, SHA256.
OH_CryptoDigest **ctx Pointer to the MD instance created.

Returns

Type Description
OH_Crypto_ErrCode CRYPTO_SUCCESS: The operation is successful.
CRYPTO_INVALID_PARAMS: A parameter is invalid.
CRYPTO_NOT_SUPPORTED: The operation is not supported.
CRYPTO_MEMORY_ERROR: A memory error occurs.
CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library.

OH_CryptoDigest_Update()

OH_Crypto_ErrCode OH_CryptoDigest_Update(OH_CryptoDigest *ctx, Crypto_DataBlob *in)

Description

Updates MD data.

Since: 12

Parameters

Name Description
OH_CryptoDigest *ctx Pointer to the MD instance.
Crypto_DataBlob *in Pointer to the data to pass in.

Returns

Type Description
OH_Crypto_ErrCode CRYPTO_SUCCESS: The operation is successful.
CRYPTO_INVALID_PARAMS: A parameter is invalid.
CRYPTO_NOT_SUPPORTED: The operation is not supported.
CRYPTO_MEMORY_ERROR: A memory error occurs.
CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library.

See also

OH_CryptoDigest_Final

OH_CryptoDigest_Final()

OH_Crypto_ErrCode OH_CryptoDigest_Final(OH_CryptoDigest *ctx, Crypto_DataBlob *out)

Description

Implements MD calculation.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.

Since: 12

Parameters

Name Description
OH_CryptoDigest *ctx Pointer to the MD instance.
Crypto_DataBlob *out Pointer to the MD generated.

Returns

Type Description
OH_Crypto_ErrCode CRYPTO_SUCCESS: The operation is successful.
CRYPTO_INVALID_PARAMS: A parameter is invalid.
CRYPTO_NOT_SUPPORTED: The operation is not supported.
CRYPTO_MEMORY_ERROR: A memory error occurs.
CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library.

See also

OH_CryptoDigest_Update

OH_CryptoDigest_GetLength()

uint32_t OH_CryptoDigest_GetLength(OH_CryptoDigest *ctx)

Description

Obtains the length of an MD.

Since: 12

Parameters

Name Description
OH_CryptoDigest *ctx Pointer to the MD instance.

Returns

Type Description
uint32_t MD length.
If the input parameter ctx is NULL, 401 is returned. In other cases, 0 is returned.

OH_CryptoDigest_GetAlgoName()

const char *OH_CryptoDigest_GetAlgoName(OH_CryptoDigest *ctx)

Description

Obtains the name of an MD algorithm.

Since: 12

Parameters

Name Description
OH_CryptoDigest *ctx Pointer to the MD instance.

Returns

Type Description
const char * MD algorithm name.

OH_DigestCrypto_Destroy()

void OH_DigestCrypto_Destroy(OH_CryptoDigest *ctx)

Description

Destroys an MD instance.

Since: 12

Parameters

Name Description
OH_CryptoDigest *ctx Pointer to the MD instance.