crypto_signature.h
Overview
Defines APIs for signature verification.
Header file: <CryptoArchitectureKit/crypto_signature.h>
Library: libohcrypto.so
System capability: SystemCapability.Security.CryptoFramework
Since: 12
Related module: CryptoSignatureApi
Summary
Structs
| Name | typedef Keyword | Description |
|---|---|---|
| OH_CryptoVerify | OH_CryptoVerify | Defines the data used for signature verification. |
| OH_CryptoSign | OH_CryptoSign | Defines a struct for signing. |
| OH_CryptoEccSignatureSpec | OH_CryptoEccSignatureSpec | Defines a struct for ECC signing specifications. |
Enums
| Name | typedef Keyword | Description |
|---|---|---|
| CryptoSignature_ParamType | CryptoSignature_ParamType | Enumerates the types of signature verification parameters. |
Functions
Enum Description
CryptoSignature_ParamType
enum CryptoSignature_ParamType
Description
Enumerates the types of signature verification parameters.
Since: 12
| Enum Item | Description |
|---|---|
| CRYPTO_PSS_MD_NAME_STR = 100 | MD algorithm used with the PSS padding mode in RSA. |
| CRYPTO_PSS_MGF_NAME_STR = 101 | Mask generation algorithm used with the PSS padding mode in RSA. Currently, only MGF1 is supported. |
| CRYPTO_PSS_MGF1_NAME_STR = 102 | MD parameters for the MGF1 mask generation used with the PSS padding mode in RSA. |
| CRYPTO_PSS_SALT_LEN_INT = 103 | Length of the salt in bytes used with the PSS padding mode in RSA. |
| CRYPTO_PSS_TRAILER_FIELD_INT = 104 | Trailer field used in the encoding operation when PSS padding mode is used in RSA. The value is 1. |
| CRYPTO_SM2_USER_ID_DATABLOB = 105 | User ID field in SM2. |
Function Description
OH_CryptoVerify_Create()
OH_Crypto_ErrCode OH_CryptoVerify_Create(const char *algoName, OH_CryptoVerify **verify)
Description
Creates a Verify instance for signature verification.
Note: The created resource must be destroyed by calling OH_CryptoVerify_Destroy.
Since: 12
Parameters
| Name | Description |
|---|---|
| const char *algoName | Pointer to the algorithm used to generate the Verify instance. For example, RSA1024|PKCS1|SHA256. |
| OH_CryptoVerify **verify | Pointer to the Verify 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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
OH_CryptoVerify_Init()
OH_Crypto_ErrCode OH_CryptoVerify_Init(OH_CryptoVerify *ctx, OH_CryptoPubKey *pubKey)
Description
Initializes a Verify instance by using the public key.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoVerify *ctx | Pointer to the Verify instance. |
| OH_CryptoPubKey *pubKey | Pointer to the public key. |
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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
Reference
OH_CryptoVerify_Update()
OH_Crypto_ErrCode OH_CryptoVerify_Update(OH_CryptoVerify *ctx, Crypto_DataBlob *in)
Description
Updates the data to be verified.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoVerify *ctx | Pointer to the Verify 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_INVALID_CALL: Invalid function call. It is supported since API version 26.0.0. CRYPTO_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
Reference
OH_CryptoVerify_Final()
bool OH_CryptoVerify_Final(OH_CryptoVerify *ctx, Crypto_DataBlob *in, Crypto_DataBlob *signData)
Description
Verifies the signature of the data.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoVerify *ctx | Pointer to the Verify instance. |
| Crypto_DataBlob *in | Pointer to the data passed in. |
| Crypto_DataBlob *signData | Pointer to the signature data. |
Returns
| Type | Description |
|---|---|
| bool | Whether the signature verification is successful. The value true indicates that the signature verification is successful, and the value false indicates that the signature verification fails. |
Reference
OH_CryptoVerify_Recover()
OH_Crypto_ErrCode OH_CryptoVerify_Recover(OH_CryptoVerify *ctx, Crypto_DataBlob *signData, Crypto_DataBlob *rawSignData)
Description
Restores the raw signature data.
Note: After the use is complete, the memory for storing the rawSignData parameter must be released by calling OH_Crypto_FreeDataBlob.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoVerify *ctx | Pointer to the Verify instance. |
| Crypto_DataBlob *signData | Pointer to the signature data. |
| Crypto_DataBlob *rawSignData | Pointer to the raw data restored. |
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_INVALID_CALL: Invalid function call. It is supported since API version 26.0.0. CRYPTO_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
OH_CryptoVerify_GetAlgoName()
const char *OH_CryptoVerify_GetAlgoName(OH_CryptoVerify *ctx)
Description
Obtains the signature verification algorithm.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoVerify *ctx | Pointer to the Verify instance. |
Returns
| Type | Description |
|---|---|
| const char * | Signature verification algorithm obtained. |
OH_CryptoVerify_SetParam()
OH_Crypto_ErrCode OH_CryptoVerify_SetParam(OH_CryptoVerify *ctx, CryptoSignature_ParamType type, Crypto_DataBlob *value)
Description
Sets a signature verification parameter.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoVerify *ctx | Pointer to the Verify instance. |
| CryptoSignature_ParamType type | Name of the signature verification parameter to set. |
| Crypto_DataBlob *value | Pointer to the value of the signature verification parameter to set. |
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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
OH_CryptoVerify_GetParam()
OH_Crypto_ErrCode OH_CryptoVerify_GetParam(OH_CryptoVerify *ctx, CryptoSignature_ParamType type, Crypto_DataBlob *value)
Description
Obtains a signature verification parameter.
Note: After the use is complete, the memory for storing the value parameter must be released by calling OH_Crypto_FreeDataBlob.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoVerify *ctx | Pointer to the Verify instance. |
| CryptoSignature_ParamType type | Name of the signature verification parameter to obtain. |
| Crypto_DataBlob *value | Pointer to the parameter value obtained. |
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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
OH_CryptoVerify_Destroy()
void OH_CryptoVerify_Destroy(OH_CryptoVerify *ctx)
Description
Destroys a Verify instance.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoVerify *ctx | Pointer to the Verify instance. |
OH_CryptoSign_Create()
OH_Crypto_ErrCode OH_CryptoSign_Create(const char *algoName, OH_CryptoSign **sign)
Description
Creates a signature instance based on the given algorithm name.
Note: The created resource must be destroyed by calling OH_CryptoSign_Destroy.
Since: 20
Parameters
| Name | Description |
|---|---|
| const char *algoName | Pointer to the algorithm used to generate the signature instance. For example, RSA|PKCS1|SHA384 or ECC|SHA384. |
| OH_CryptoSign **sign | Pointer to the signature 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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
OH_CryptoSign_Init()
OH_Crypto_ErrCode OH_CryptoSign_Init(OH_CryptoSign *ctx, OH_CryptoPrivKey *privKey)
Description
Initializes a signature instance.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoSign *ctx | Pointer to the signature instance. |
| OH_CryptoPrivKey *privKey | Pointer to the private 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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
Reference
OH_CryptoSign_Update()
OH_Crypto_ErrCode OH_CryptoSign_Update(OH_CryptoSign *ctx, const Crypto_DataBlob *in)
Description
Updates the data to be signed.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoSign *ctx | Pointer to the signature instance. |
| const Crypto_DataBlob *in | Pointer to the data to be signed. |
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_INVALID_CALL: Invalid function call. It is supported since API version 26.0.0. CRYPTO_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
Reference
OH_CryptoSign_Final()
OH_Crypto_ErrCode OH_CryptoSign_Final(OH_CryptoSign *ctx, const Crypto_DataBlob *in, Crypto_DataBlob *out)
Description
Finalizes the signing 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
| Name | Description |
|---|---|
| OH_CryptoSign *ctx | Pointer to the signature instance. |
| const Crypto_DataBlob *in | Pointer to the data to be signed. |
| Crypto_DataBlob *out | Pointer to the signing result. |
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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
Reference
OH_CryptoSign_GetAlgoName()
const char *OH_CryptoSign_GetAlgoName(OH_CryptoSign *ctx)
Description
Obtains the algorithm name of a signature instance.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoSign *ctx | Pointer to the signature instance. |
Returns
| Type | Description |
|---|---|
| const char * | Algorithm name of the signature instance. |
OH_CryptoSign_SetParam()
OH_Crypto_ErrCode OH_CryptoSign_SetParam(OH_CryptoSign *ctx, CryptoSignature_ParamType type, const Crypto_DataBlob *value)
Description
Sets parameters for a signature instance.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoSign *ctx | Pointer to the signature instance. |
| CryptoSignature_ParamType type | Pointer to the signature parameter type. |
| const Crypto_DataBlob *value | Pointer to the input data. |
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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
OH_CryptoSign_GetParam()
OH_Crypto_ErrCode OH_CryptoSign_GetParam(OH_CryptoSign *ctx, CryptoSignature_ParamType type, Crypto_DataBlob *value)
Description
Obtains the specified parameter from a signature instance.
Note: After the use is complete, the memory for storing the value parameter must be released by calling OH_Crypto_FreeDataBlob.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoSign *ctx | Pointer to the signature instance. |
| CryptoSignature_ParamType type | Pointer to the signature parameter type. |
| Crypto_DataBlob *value | Pointer to the output data. |
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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
OH_CryptoSign_Destroy()
void OH_CryptoSign_Destroy(OH_CryptoSign *ctx)
Description
Destroys a signature instance.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoSign *ctx | Pointer to the signature instance. |
OH_CryptoEccSignatureSpec_Create()
OH_Crypto_ErrCode OH_CryptoEccSignatureSpec_Create(Crypto_DataBlob *eccSignature, OH_CryptoEccSignatureSpec **spec)
Description
Creates ECC signing specifications.
Note: The created resource must be destroyed by calling OH_CryptoEccSignatureSpec_Destroy.
Since: 20
Parameters
| Name | Description |
|---|---|
| Crypto_DataBlob *eccSignature | Pointer to the ECC signature (in DER format). If EccSignature is NULL, an empty ECC signing specification is created. |
| OH_CryptoEccSignatureSpec **spec | Pointer to the ECC signing specifications. |
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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
OH_CryptoEccSignatureSpec_GetRAndS()
OH_Crypto_ErrCode OH_CryptoEccSignatureSpec_GetRAndS(OH_CryptoEccSignatureSpec *spec, Crypto_DataBlob *r, Crypto_DataBlob *s)
Description
Obtains the r and s values of an ECC signature.
Note: After the use is complete, the memory for storing the r and s parameters must be released by calling OH_Crypto_FreeDataBlob.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoEccSignatureSpec *spec | Pointer to the ECC signing specifications. |
| Crypto_DataBlob *r | Pointer to the r value. |
| Crypto_DataBlob *s | Pointer to the s value. |
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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
OH_CryptoEccSignatureSpec_SetRAndS()
OH_Crypto_ErrCode OH_CryptoEccSignatureSpec_SetRAndS(OH_CryptoEccSignatureSpec *spec, Crypto_DataBlob *r, Crypto_DataBlob *s)
Description
Sets the r and s values of an ECC signature.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoEccSignatureSpec *spec | Pointer to the ECC signing specifications. |
| Crypto_DataBlob *r | Pointer to the r value. |
| Crypto_DataBlob *s | Pointer to the s value. |
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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
OH_CryptoEccSignatureSpec_Encode()
OH_Crypto_ErrCode OH_CryptoEccSignatureSpec_Encode(OH_CryptoEccSignatureSpec *spec, Crypto_DataBlob *out)
Description
Encodes ECC signing specifications into a signature in DER format.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoEccSignatureSpec *spec | Pointer to the ECC signing specifications. |
| Crypto_DataBlob *out | Pointer to the output data. |
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_OPERATION_ERROR: An error occurs when the API of a third-party algorithm library is called. |
OH_CryptoEccSignatureSpec_Destroy()
void OH_CryptoEccSignatureSpec_Destroy(OH_CryptoEccSignatureSpec *spec)
Description
Destroys ECC signing specifications.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_CryptoEccSignatureSpec *spec | Pointer to the ECC signing specifications. |