1# crypto_kdf.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 key derivation function (KDF) APIs. 13 14**Header file**: <CryptoArchitectureKit/crypto_kdf.h> 15 16**Library**: libohcrypto.so 17 18**System capability**: SystemCapability.Security.CryptoFramework 19 20**Since**: 20 21 22**Related module**: [CryptoKdfApi](capi-cryptokdfapi.md) 23 24## Summary 25 26### Structs 27 28| Name| typedef Keyword| Description| 29| -- | -- | -- | 30| [OH_CryptoKdf](capi-cryptokdfapi-oh-cryptokdf.md) | OH_CryptoKdf | Defines a KDF.| 31| [OH_CryptoKdfParams](capi-cryptokdfapi-oh-cryptokdfparams.md) | OH_CryptoKdfParams | Defines KDF parameters.| 32 33### Enums 34 35| Name| typedef Keyword| Description| 36| -- | -- | -- | 37| [CryptoKdf_ParamType](#cryptokdf_paramtype) | CryptoKdf_ParamType | Defines KDF parameter types.| 38 39### Functions 40 41| Name| Description| 42| -- | -- | 43| [OH_Crypto_ErrCode OH_CryptoKdfParams_Create(const char *algoName, OH_CryptoKdfParams **params)](#oh_cryptokdfparams_create) | Creates KDF parameters.| 44| [OH_Crypto_ErrCode OH_CryptoKdfParams_SetParam(OH_CryptoKdfParams *params, CryptoKdf_ParamType type,Crypto_DataBlob *value)](#oh_cryptokdfparams_setparam) | Sets KDF parameters.| 45| [void OH_CryptoKdfParams_Destroy(OH_CryptoKdfParams *params)](#oh_cryptokdfparams_destroy) | Destroys KDF parameters.| 46| [OH_Crypto_ErrCode OH_CryptoKdf_Create(const char *algoName, OH_CryptoKdf **ctx)](#oh_cryptokdf_create) | Creates a KDF instance.| 47| [OH_Crypto_ErrCode OH_CryptoKdf_Derive(OH_CryptoKdf *ctx, const OH_CryptoKdfParams *params, int keyLen,Crypto_DataBlob *key)](#oh_cryptokdf_derive) | Derives a key.| 48| [void OH_CryptoKdf_Destroy(OH_CryptoKdf *ctx)](#oh_cryptokdf_destroy) | Destroys a KDF instance.| 49 50## Enum Description 51 52### CryptoKdf_ParamType 53 54``` 55enum CryptoKdf_ParamType 56``` 57 58**Description** 59 60Defines KDF parameter types. 61 62**Since**: 20 63 64| Enum Item| Description| 65| -- | -- | 66| CRYPTO_KDF_KEY_DATABLOB = 0 | Key or password of the KDF.| 67| CRYPTO_KDF_SALT_DATABLOB = 1 | Salt value of the KDF.| 68| CRYPTO_KDF_INFO_DATABLOB = 2 | Information of the KDF.| 69| CRYPTO_KDF_ITER_COUNT_INT = 3 | Iteration count of PBKDF2.| 70| CRYPTO_KDF_SCRYPT_N_UINT64 = 4 | Parameter **n** of the SCRYPT KDF.| 71| CRYPTO_KDF_SCRYPT_R_UINT64 = 5 | Parameter **r** of the SCRYPT KDF.| 72| CRYPTO_KDF_SCRYPT_P_UINT64 = 6 | Parameter **p** of the SCRYPT KDF.| 73| CRYPTO_KDF_SCRYPT_MAX_MEM_UINT64 = 7 | Maximum memory usage of the SCRYPT KDF.| 74 75 76## Function Description 77 78### OH_CryptoKdfParams_Create() 79 80``` 81OH_Crypto_ErrCode OH_CryptoKdfParams_Create(const char *algoName, OH_CryptoKdfParams **params) 82``` 83 84**Description** 85 86Creates KDF parameters. 87 88**Since**: 20 89 90 91**Parameters** 92 93| Name| Description| 94| -- | -- | 95| const char *algoName | KDF algorithm name.<br> For example, HKDF\|SHA384\|EXTRACT_AND_EXPAND; PBKDF2\|SHA-384.| 96| [OH_CryptoKdfParams](capi-cryptokdfapi-oh-cryptokdfparams.md) **params | KDF parameters.| 97 98**Returns** 99 100| Type| Description| 101| -- | -- | 102| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | **CRYPTO_SUCCESS**: The operation is successful.<br> **CRYPTO_NOT_SUPPORTED**: The operation is not supported.<br> **CRYPTO_MEMORY_ERROR**: A memory error occurs.<br> **CRYPTO_PARAMETER_CHECK_FAILED**: The parameter check failed.<br> **CRYPTO_OPERTION_ERROR**: Failed to call an API of a third-party algorithm library.| 103 104### OH_CryptoKdfParams_SetParam() 105 106``` 107OH_Crypto_ErrCode OH_CryptoKdfParams_SetParam(OH_CryptoKdfParams *params, CryptoKdf_ParamType type,Crypto_DataBlob *value) 108``` 109 110**Description** 111 112Sets KDF parameters. 113 114**Since**: 20 115 116 117**Parameters** 118 119| Name| Description| 120| -- | -- | 121| [OH_CryptoKdfParams](capi-cryptokdfapi-oh-cryptokdfparams.md) *params | KDF parameters.| 122| [CryptoKdf_ParamType](#cryptokdf_paramtype) type | KDF parameter type.| 123| [Crypto_DataBlob](capi-cryptocommonapi-crypto-datablob.md) *value | KDF parameter values.| 124 125**Returns** 126 127| Type| Description| 128| -- | -- | 129| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | **CRYPTO_SUCCESS**: The operation is successful.<br> **CRYPTO_NOT_SUPPORTED**: The operation is not supported.<br> **CRYPTO_MEMORY_ERROR**: A memory error occurs.<br> **CRYPTO_PARAMETER_CHECK_FAILED**: The parameter check failed.<br> **CRYPTO_OPERTION_ERROR**: Failed to call an API of a third-party algorithm library.| 130 131### OH_CryptoKdfParams_Destroy() 132 133``` 134void OH_CryptoKdfParams_Destroy(OH_CryptoKdfParams *params) 135``` 136 137**Description** 138 139Destroys KDF parameters. 140 141**Since**: 20 142 143 144**Parameters** 145 146| Name| Description| 147| -- | -- | 148| [OH_CryptoKdfParams](capi-cryptokdfapi-oh-cryptokdfparams.md) *params | KDF parameters.| 149 150### OH_CryptoKdf_Create() 151 152``` 153OH_Crypto_ErrCode OH_CryptoKdf_Create(const char *algoName, OH_CryptoKdf **ctx) 154``` 155 156**Description** 157 158Creates a KDF instance. 159 160**Since**: 20 161 162 163**Parameters** 164 165| Name| Description| 166| -- | -- | 167| const char *algoName | KDF algorithm name.| 168| [OH_CryptoKdf](capi-cryptokdfapi-oh-cryptokdf.md) **ctx | KDF instance.| 169 170**Returns** 171 172| Type| Description| 173| -- | -- | 174| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | **CRYPTO_SUCCESS**: The operation is successful.<br> **CRYPTO_NOT_SUPPORTED**: The operation is not supported.<br> **CRYPTO_MEMORY_ERROR**: A memory error occurs.<br> **CRYPTO_PARAMETER_CHECK_FAILED**: The parameter check failed.<br> **CRYPTO_OPERTION_ERROR**: Failed to call an API of a third-party algorithm library.| 175 176### OH_CryptoKdf_Derive() 177 178``` 179OH_Crypto_ErrCode OH_CryptoKdf_Derive(OH_CryptoKdf *ctx, const OH_CryptoKdfParams *params, int keyLen,Crypto_DataBlob *key) 180``` 181 182**Description** 183 184Derives a key. 185 186**Since**: 20 187 188 189**Parameters** 190 191| Name| Description| 192| -- | -- | 193| [OH_CryptoKdf](capi-cryptokdfapi-oh-cryptokdf.md) *ctx | KDF instance.| 194| [const OH_CryptoKdfParams](capi-cryptokdfapi-oh-cryptokdfparams.md) *params | KDF parameters.| 195| int keyLen | Length of the derived key.| 196| [Crypto_DataBlob](capi-cryptocommonapi-crypto-datablob.md) *key | Derived key.| 197 198**Returns** 199 200| Type| Description| 201| -- | -- | 202| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | **CRYPTO_SUCCESS**: The operation is successful.<br> **CRYPTO_NOT_SUPPORTED**: The operation is not supported.<br> **CRYPTO_MEMORY_ERROR**: A memory error occurs.<br> **CRYPTO_PARAMETER_CHECK_FAILED**: The parameter check failed.<br> **CRYPTO_OPERTION_ERROR**: Failed to call an API of a third-party algorithm library.| 203 204### OH_CryptoKdf_Destroy() 205 206``` 207void OH_CryptoKdf_Destroy(OH_CryptoKdf *ctx) 208``` 209 210**Description** 211 212Destroys a KDF instance. 213 214**Since**: 20 215 216 217**Parameters** 218 219| Name| Description| 220| -- | -- | 221| [OH_CryptoKdf](capi-cryptokdfapi-oh-cryptokdf.md) *ctx | KDF instance.| 222