crypto_kdf.h
Overview
Defines key derivation function (KDF) APIs.
Header file: <CryptoArchitectureKit/crypto_kdf.h>
Library: libohcrypto.so
System capability: SystemCapability.Security.CryptoFramework
Since: 20
Related module: CryptoKdfApi
Summary
Structs
| Name | typedef Keyword | Description |
|---|---|---|
| OH_CryptoKdf | OH_CryptoKdf | Defines a KDF. |
| OH_CryptoKdfParams | OH_CryptoKdfParams | Defines KDF parameters. |
Enums
| Name | typedef Keyword | Description |
|---|---|---|
| CryptoKdf_ParamType | CryptoKdf_ParamType | Defines KDF parameter types. |
Functions
| Name | Description |
|---|---|
| OH_Crypto_ErrCode OH_CryptoKdfParams_Create(const char *algoName, OH_CryptoKdfParams **params) | Creates KDF parameters. Note: The created resource must be destroyed by calling OH_CryptoKdfParams_Destroy. |
| OH_Crypto_ErrCode OH_CryptoKdfParams_SetParam(OH_CryptoKdfParams *params, CryptoKdf_ParamType type, Crypto_DataBlob *value) | Sets KDF parameters. |
| void OH_CryptoKdfParams_Destroy(OH_CryptoKdfParams *params) | Destroys KDF parameters. |
| OH_Crypto_ErrCode OH_CryptoKdf_Create(const char *algoName, OH_CryptoKdf **ctx) | Creates a KDF instance. Note: The created resource must be destroyed by calling OH_CryptoKdf_Destroy. |
| OH_Crypto_ErrCode OH_CryptoKdf_Derive(OH_CryptoKdf *ctx, const OH_CryptoKdfParams *params, int keyLen, Crypto_DataBlob *key) | Derives a key. Note: After the use is complete, the memory for storing the key parameter must be released by calling OH_Crypto_FreeDataBlob. |
| void OH_CryptoKdf_Destroy(OH_CryptoKdf *ctx) | Destroys a KDF instance. |
Enum Description
CryptoKdf_ParamType
enum CryptoKdf_ParamType
Description
Defines KDF parameter types.
Since: 20
| Enum Item | Description |
|---|---|
| CRYPTO_KDF_KEY_DATABLOB = 0 | Key or password of the KDF. |
| CRYPTO_KDF_SALT_DATABLOB = 1 | Salt value of the KDF. |
| CRYPTO_KDF_INFO_DATABLOB = 2 | Information of the KDF. |
| CRYPTO_KDF_ITER_COUNT_INT = 3 | Iteration count of PBKDF2. |
| CRYPTO_KDF_SCRYPT_N_UINT64 = 4 | Parameter n of the SCRYPT KDF. |
| CRYPTO_KDF_SCRYPT_R_UINT64 = 5 | Parameter r of the SCRYPT KDF. |
| CRYPTO_KDF_SCRYPT_P_UINT64 = 6 | Parameter p of the SCRYPT KDF. |
| CRYPTO_KDF_SCRYPT_MAX_MEM_UINT64 = 7 | Maximum memory usage of the SCRYPT KDF. |
Function Description
OH_CryptoKdfParams_Create()
OH_Crypto_ErrCode OH_CryptoKdfParams_Create(const char *algoName, OH_CryptoKdfParams **params)
Description
Creates KDF parameters.
Note: The created resource must be destroyed by calling OH_CryptoKdfParams_Destroy.
Since: 20
Parameters
| Name | Description |
|---|---|
| const char *algoName | KDF algorithm name. For example, HKDF|SHA384|EXTRACT_AND_EXPAND or PBKDF2|SHA384. |
| OH_CryptoKdfParams **params | KDF parameters. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_SUCCESS: The operation is successful. CRYPTO_NOT_SUPPORTED: The operation is not supported. CRYPTO_MEMORY_ERROR: A memory error occurs. CRYPTO_PARAMETER_CHECK_FAILED: The parameter check failed. CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library. |
OH_CryptoKdfParams_SetParam()
OH_Crypto_ErrCode OH_CryptoKdfParams_SetParam(OH_CryptoKdfParams *params, CryptoKdf_ParamType type, Crypto_DataBlob *value)
Description
Sets KDF parameters.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoKdfParams *params | KDF parameters. |
| CryptoKdf_ParamType type | KDF parameter type. |
| Crypto_DataBlob *value | KDF parameter values. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_SUCCESS: The operation is successful. CRYPTO_NOT_SUPPORTED: The operation is not supported. CRYPTO_MEMORY_ERROR: A memory error occurs. CRYPTO_PARAMETER_CHECK_FAILED: The parameter check failed. CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library. |
OH_CryptoKdfParams_Destroy()
void OH_CryptoKdfParams_Destroy(OH_CryptoKdfParams *params)
Description
Destroys KDF parameters.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoKdfParams *params | KDF parameters. |
OH_CryptoKdf_Create()
OH_Crypto_ErrCode OH_CryptoKdf_Create(const char *algoName, OH_CryptoKdf **ctx)
Description
Creates a KDF instance.
Note: The created resource must be destroyed by calling OH_CryptoKdf_Destroy.
Since: 20
Parameters
| Name | Description |
|---|---|
| const char *algoName | KDF algorithm name. |
| OH_CryptoKdf **ctx | KDF instance. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_SUCCESS: The operation is successful. CRYPTO_NOT_SUPPORTED: The operation is not supported. CRYPTO_MEMORY_ERROR: A memory error occurs. CRYPTO_PARAMETER_CHECK_FAILED: The parameter check failed. CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library. |
OH_CryptoKdf_Derive()
OH_Crypto_ErrCode OH_CryptoKdf_Derive(OH_CryptoKdf *ctx, const OH_CryptoKdfParams *params, int keyLen, Crypto_DataBlob *key)
Description
Derives a key.
Note: After the use is complete, the memory for storing the key parameter must be released by calling OH_Crypto_FreeDataBlob.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoKdf *ctx | KDF instance. |
| const OH_CryptoKdfParams *params | KDF parameters. |
| int keyLen | Length of the derived key. |
| Crypto_DataBlob *key | Derived key. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_SUCCESS: The operation is successful. CRYPTO_NOT_SUPPORTED: The operation is not supported. CRYPTO_MEMORY_ERROR: A memory error occurs. CRYPTO_PARAMETER_CHECK_FAILED: The parameter check failed. CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library. |
OH_CryptoKdf_Destroy()
void OH_CryptoKdf_Destroy(OH_CryptoKdf *ctx)
Description
Destroys a KDF instance.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoKdf *ctx | KDF instance. |