openharmony 鸿蒙 capi-crypto-mac-h

2026-08-25 浏览 (1)

crypto_mac.h

Overview

Define message authentication code (MAC) APIs.

Header file: <CryptoArchitectureKit/crypto_mac.h>

Library: libohcrypto.so

System capability: SystemCapability.Security.CryptoFramework

Since: 20

Related module: CryptoMacApi

Summary

Structs

Nametypedef KeywordDescription
OH_CryptoMacOH_CryptoMacDefines a struct for a MAC.

Enums

Nametypedef KeywordDescription
CryptoMac_ParamTypeCryptoMac_ParamTypeDefines the parameter type for the MAC algorithm.

Functions

NameDescription
OH_Crypto_ErrCode OH_CryptoMac_Create(const char *algoName, OH_CryptoMac **ctx)Creates a MAC instance based on the given algorithm name.
Note: The created resource must be destroyed by calling OH_CryptoMac_Destroy.
OH_Crypto_ErrCode OH_CryptoMac_SetParam(OH_CryptoMac *ctx, CryptoMac_ParamType type, const Crypto_DataBlob *value)Sets MAC parameters.
OH_Crypto_ErrCode OH_CryptoMac_Init(OH_CryptoMac *ctx, const OH_CryptoSymKey *key)Initializes a MAC instance using a symmetric key.
OH_Crypto_ErrCode OH_CryptoMac_Update(OH_CryptoMac *ctx, const Crypto_DataBlob *in)Updates a MAC instance.
OH_Crypto_ErrCode OH_CryptoMac_Final(OH_CryptoMac *ctx, Crypto_DataBlob *out)Finalizes a MAC operation.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.
OH_Crypto_ErrCode OH_CryptoMac_GetLength(OH_CryptoMac *ctx, uint32_t *length)Obtains the MAC length.
void OH_CryptoMac_Destroy(OH_CryptoMac *ctx)Destroys a MAC instance.

Enum Description

CryptoMac_ParamType

enum CryptoMac_ParamType

Description

Defines the parameter type for the MAC algorithm.

Since: 20

Enum ItemDescription
CRYPTO_MAC_DIGEST_NAME_STR = 0Algorithm name of the digest function used by the HMAC, for example, SHA256.
CRYPTO_MAC_CIPHER_NAME_STR = 1Name of the symmetric encryption algorithm used by the CMAC, for example, AES256.

Function Description

OH_CryptoMac_Create()

OH_Crypto_ErrCode OH_CryptoMac_Create(const char *algoName, OH_CryptoMac **ctx)

Description

Creates a MAC instance based on the given algorithm name.
Note: The created resource must be destroyed by calling OH_CryptoMac_Destroy.

Since: 20

Parameters

NameDescription
const char *algoNamePointer to the algorithm used to generate the MAC instance.
For example, HMAC or CMAC.
OH_CryptoMac **ctxMAC instance.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called.

OH_CryptoMac_SetParam()

OH_Crypto_ErrCode OH_CryptoMac_SetParam(OH_CryptoMac *ctx, CryptoMac_ParamType type, const Crypto_DataBlob *value)

Description

Sets MAC parameters.

Since: 20

Parameters

NameDescription
OH_CryptoMac *ctxMAC instance.
CryptoMac_ParamType typeMAC parameter type.
const Crypto_DataBlob *valueMAC parameters.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called.

OH_CryptoMac_Init()

OH_Crypto_ErrCode OH_CryptoMac_Init(OH_CryptoMac *ctx, const OH_CryptoSymKey *key)

Description

Initializes a MAC instance using a symmetric key.

Since: 20

Parameters

NameDescription
OH_CryptoMac *ctxMAC instance.
const OH_CryptoSymKey *keySymmetric key obtained.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called.

Reference

OH_CryptoMac_Update

OH_CryptoMac_Final

OH_CryptoMac_Update()

OH_Crypto_ErrCode OH_CryptoMac_Update(OH_CryptoMac *ctx, const Crypto_DataBlob *in)

Description

Updates a MAC instance.

Since: 20

Parameters

NameDescription
OH_CryptoMac *ctxMAC instance.
const Crypto_DataBlob *inData to be updated.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called.

Reference

OH_CryptoMac_Init

OH_CryptoMac_Final

OH_CryptoMac_Final()

OH_Crypto_ErrCode OH_CryptoMac_Final(OH_CryptoMac *ctx, Crypto_DataBlob *out)

Description

Finalizes a MAC operation.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.

Since: 20

Parameters

NameDescription
OH_CryptoMac *ctxMAC instance.
Crypto_DataBlob *outMAC value.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called.

Reference

OH_CryptoMac_Init

OH_CryptoMac_Update

OH_CryptoMac_GetLength()

OH_Crypto_ErrCode OH_CryptoMac_GetLength(OH_CryptoMac *ctx, uint32_t *length)

Description

Obtains the MAC length.

Since: 20

Parameters

NameDescription
OH_CryptoMac *ctxMAC instance.
uint32_t *lengthMAC length.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called.

OH_CryptoMac_Destroy()

void OH_CryptoMac_Destroy(OH_CryptoMac *ctx)

Description

Destroys a MAC instance.

Since: 20

Parameters

NameDescription
OH_CryptoMac *ctxMAC instance.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-cryptosymkeyapi-oh-cryptosymkey

openharmony 鸿蒙 capi-cryptoasymkeyapi-oh-cryptoasymkeygeneratorwithspec

openharmony 鸿蒙 capi-cryptoasymcipherapi-oh-cryptoasymcipher

openharmony 鸿蒙 capi-cryptokdfapi-oh-cryptokdfparams

openharmony 鸿蒙 capi-cryptomacapi

openharmony 鸿蒙 capi-cryptodigestapi-oh-cryptodigest

openharmony 鸿蒙 capi-cryptomacapi-oh-cryptomac

openharmony 鸿蒙 capi-cryptosignatureapi-oh-cryptoeccsignaturespec

openharmony 鸿蒙 capi-cryptocommonapi-crypto-datablob

openharmony 鸿蒙 capi-cryptoasymcipherapi-oh-cryptosm2ciphertextspec

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/FGKwJoSj