1# crypto_digest.h 2 3<!--Kit: Crypto Architecture Kit--> 4<!--Subsystem: Security--> 5<!--Owner: @zxz--3--> 6<!--Designer: @lanming--> 7<!--Tester: @PAFT--> 8<!--Adviser: @zengyawen--> 9 10## Overview 11 12Defines APIs for MD algorithms. 13 14**Header file**: <CryptoArchitectureKit/crypto_digest.h> 15 16**Library**: libohcrypto.so 17 18**System capability**: SystemCapability.Security.CryptoFramework 19 20**Since**: 12 21 22**Related module**: [CryptoDigestApi](capi-cryptodigestapi.md) 23 24## Summary 25 26### Structs 27 28| Name| typedef Keyword| Description| 29| -- | -- | -- | 30| [OH_CryptoDigest](capi-cryptodigestapi-oh-cryptodigest.md) | OH_CryptoDigest | Defines an MD.| 31 32### Functions 33 34| Name| Description| 35| -- | -- | 36| [OH_Crypto_ErrCode OH_CryptoDigest_Create(const char *algoName, OH_CryptoDigest **ctx)](#oh_cryptodigest_create) | Creates an MD instance based on the given algorithm name.| 37| [OH_Crypto_ErrCode OH_CryptoDigest_Update(OH_CryptoDigest *ctx, Crypto_DataBlob *in)](#oh_cryptodigest_update) | Updates MD data.| 38| [OH_Crypto_ErrCode OH_CryptoDigest_Final(OH_CryptoDigest *ctx, Crypto_DataBlob *out)](#oh_cryptodigest_final) | Implements MD calculation.| 39| [uint32_t OH_CryptoDigest_GetLength(OH_CryptoDigest *ctx)](#oh_cryptodigest_getlength) | Obtains the length of an MD.| 40| [const char *OH_CryptoDigest_GetAlgoName(OH_CryptoDigest *ctx)](#oh_cryptodigest_getalgoname) | Obtains the name of an MD algorithm.| 41| [void OH_DigestCrypto_Destroy(OH_CryptoDigest *ctx)](#oh_digestcrypto_destroy) | Destroys an MD instance.| 42 43## Function Description 44 45### OH_CryptoDigest_Create() 46 47``` 48OH_Crypto_ErrCode OH_CryptoDigest_Create(const char *algoName, OH_CryptoDigest **ctx) 49``` 50 51**Description** 52 53Creates an MD instance based on the given algorithm name. 54 55**Since**: 12 56 57 58**Parameters** 59 60| Name| Description| 61| -- | -- | 62| const char *algoName | Pointer to the algorithm used to generate the MD instance.<br> For example, **'SHA256'**.| 63| [OH_CryptoDigest](capi-cryptodigestapi-oh-cryptodigest.md) **ctx | Pointer to the MD instance created.| 64 65**Returns** 66 67| Type| Description| 68| -- | -- | 69| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | **CRYPTO_SUCCESS**: The operation is successful.<br> **CRYPTO_INVALID_PARAMS**: A parameter is invalid.<br> **CRYPTO_NOT_SUPPORTED**: The operation is not supported.<br> **CRYPTO_MEMORY_ERROR**: A memory error occurs.<br> **CRYPTO_OPERTION_ERROR**: Failed to call an API of a third-party algorithm library.| 70 71### OH_CryptoDigest_Update() 72 73``` 74OH_Crypto_ErrCode OH_CryptoDigest_Update(OH_CryptoDigest *ctx, Crypto_DataBlob *in) 75``` 76 77**Description** 78 79Updates MD data. 80 81**Since**: 12 82 83 84**Parameters** 85 86| Name| Description| 87| -- | -- | 88| [OH_CryptoDigest](capi-cryptodigestapi-oh-cryptodigest.md) *ctx | Pointer to the MD instance.| 89| [Crypto_DataBlob](capi-cryptocommonapi-crypto-datablob.md) *in | Pointer to the data to pass in.| 90 91**Returns** 92 93| Type| Description| 94| -- | -- | 95| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | **CRYPTO_SUCCESS**: The operation is successful.<br> **CRYPTO_INVALID_PARAMS**: A parameter is invalid.<br> **CRYPTO_NOT_SUPPORTED**: The operation is not supported.<br> **CRYPTO_MEMORY_ERROR**: A memory error occurs.<br> **CRYPTO_OPERTION_ERROR**: Failed to call an API of a third-party algorithm library.| 96 97**See also** 98 99[OH_CryptoDigest_Final](capi-crypto-digest-h.md#oh_cryptodigest_final) 100 101 102### OH_CryptoDigest_Final() 103 104``` 105OH_Crypto_ErrCode OH_CryptoDigest_Final(OH_CryptoDigest *ctx, Crypto_DataBlob *out) 106``` 107 108**Description** 109 110Implements MD calculation. 111 112**Since**: 12 113 114 115**Parameters** 116 117| Name| Description| 118| -- | -- | 119| [OH_CryptoDigest](capi-cryptodigestapi-oh-cryptodigest.md) *ctx | Pointer to the MD instance.| 120| [Crypto_DataBlob](capi-cryptocommonapi-crypto-datablob.md) *out | Pointer to the MD generated.| 121 122**Returns** 123 124| Type| Description| 125| -- | -- | 126| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | **CRYPTO_SUCCESS**: The operation is successful.<br> **CRYPTO_INVALID_PARAMS**: A parameter is invalid.<br> **CRYPTO_NOT_SUPPORTED**: The operation is not supported.<br> **CRYPTO_MEMORY_ERROR**: A memory error occurs.<br> **CRYPTO_OPERTION_ERROR**: Failed to call an API of a third-party algorithm library.| 127 128**See also** 129 130[OH_CryptoDigest_Update](capi-crypto-digest-h.md#oh_cryptodigest_update) 131 132 133### OH_CryptoDigest_GetLength() 134 135``` 136uint32_t OH_CryptoDigest_GetLength(OH_CryptoDigest *ctx) 137``` 138 139**Description** 140 141Obtains the length of an MD. 142 143**Since**: 12 144 145 146**Parameters** 147 148| Name| Description| 149| -- | -- | 150| [OH_CryptoDigest](capi-cryptodigestapi-oh-cryptodigest.md) *ctx | Pointer to the MD instance.| 151 152**Returns** 153 154| Type| Description| 155| -- | -- | 156| uint32_t | Digest length.<br> If the input parameter **ctx** is **NULL**, **401** is returned. In other cases, **0** is returned.| 157 158### OH_CryptoDigest_GetAlgoName() 159 160``` 161const char *OH_CryptoDigest_GetAlgoName(OH_CryptoDigest *ctx) 162``` 163 164**Description** 165 166Obtains the name of an MD algorithm. 167 168**Since**: 12 169 170 171**Parameters** 172 173| Name| Description| 174| -- | -- | 175| [OH_CryptoDigest](capi-cryptodigestapi-oh-cryptodigest.md) *ctx | Pointer to the MD instance.| 176 177**Returns** 178 179| Type| Description| 180| -- | -- | 181| const char * | MD algorithm name.| 182 183### OH_DigestCrypto_Destroy() 184 185``` 186void OH_DigestCrypto_Destroy(OH_CryptoDigest *ctx) 187``` 188 189**Description** 190 191Destroys an MD instance. 192 193**Since**: 12 194 195 196**Parameters** 197 198| Name| Description| 199| -- | -- | 200| [OH_CryptoDigest](capi-cryptodigestapi-oh-cryptodigest.md) *ctx | Pointer to the MD instance.| 201