1# CryptoSignatureApi 2 3 4## Overview 5 6Provides APIs for signature verification. 7 8**Since**: 12 9 10 11## Summary 12 13 14### Files 15 16| Name | Description | 17| -------- | -------- | 18| [crypto_signature.h](crypto__signature_8h.md) | Defines APIs for signature verification. | 19 20 21### Types 22 23| Name | Description | 24| -------- | -------- | 25| typedef struct [OH_CryptoVerify](#oh_cryptoverify) [OH_CryptoVerify](#oh_cryptoverify) | Defines the data used for signature verification. | 26 27 28### Enums 29 30| Name | Description | 31| -------- | -------- | 32| [CryptoSignature_ParamType](#cryptosignature_paramtype) {<br>CRYPTO_PSS_MD_NAME_STR = 100, CRYPTO_PSS_MGF_NAME_STR = 101,<br>CRYPTO_PSS_MGF1_NAME_STR = 102, CRYPTO_PSS_SALT_LEN_INT = 103,<br>CRYPTO_PSS_TRAILER_FIELD_INT = 104, CRYPTO_SM2_USER_ID_DATABLOB = 105<br>} | Enumerates the types of signature verification parameters. | 33 34 35### Functions 36 37| Name | Description | 38| -------- | -------- | 39| [OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode) [OH_CryptoVerify_Create](#oh_cryptoverify_create) (const char \*algoName, [OH_CryptoVerify](#oh_cryptoverify) \*\*verify) | Creates a **Verify** instance for signature verification. | 40| [OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode) [OH_CryptoVerify_Init](#oh_cryptoverify_init) ([OH_CryptoVerify](#oh_cryptoverify) \*ctx, [OH_CryptoPubKey](_crypto_asym_key_api.md#oh_cryptopubkey) \*pubKey) | Initializes a **Verify** instance by using the public key. | 41| [OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode) [OH_CryptoVerify_Update](#oh_cryptoverify_update) ([OH_CryptoVerify](#oh_cryptoverify) \*ctx, [Crypto_DataBlob](_crypto___data_blob.md) \*in) | Updates the data to be verified. | 42| bool [OH_CryptoVerify_Final](#oh_cryptoverify_final) ([OH_CryptoVerify](#oh_cryptoverify) \*ctx, [Crypto_DataBlob](_crypto___data_blob.md) \*in, [Crypto_DataBlob](_crypto___data_blob.md) \*signData) | Verifies the signature of the data. | 43| [OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode) [OH_CryptoVerify_Recover](#oh_cryptoverify_recover) ([OH_CryptoVerify](#oh_cryptoverify) \*ctx, [Crypto_DataBlob](_crypto___data_blob.md) \*signData, [Crypto_DataBlob](_crypto___data_blob.md) \*rawSignData) | Restores the raw signature data. | 44| const char \* [OH_CryptoVerify_GetAlgoName](#oh_cryptoverify_getalgoname) ([OH_CryptoVerify](#oh_cryptoverify) \*ctx) | Obtains the signature verification algorithm. | 45| [OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode) [OH_CryptoVerify_SetParam](#oh_cryptoverify_setparam) ([OH_CryptoVerify](#oh_cryptoverify) \*ctx, [CryptoSignature_ParamType](#cryptosignature_paramtype) type, [Crypto_DataBlob](_crypto___data_blob.md) \*value) | Sets a signature verification parameter. | 46| [OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode) [OH_CryptoVerify_GetParam](#oh_cryptoverify_getparam) ([OH_CryptoVerify](#oh_cryptoverify) \*ctx, [CryptoSignature_ParamType](#cryptosignature_paramtype) type, [Crypto_DataBlob](_crypto___data_blob.md) \*value) | Obtains a signature verification parameter. | 47| void [OH_CryptoVerify_Destroy](#oh_cryptoverify_destroy) ([OH_CryptoVerify](#oh_cryptoverify) \*ctx) | Destroys a **Verify** instance. | 48 49 50## Type Description 51 52 53### OH_CryptoVerify 54 55``` 56typedef struct OH_CryptoVerifyOH_CryptoVerify 57``` 58 59**Description** 60 61Defines the data used for signature verification. 62 63**Since**: 12 64 65 66## Enum Description 67 68 69### CryptoSignature_ParamType 70 71``` 72enum CryptoSignature_ParamType 73``` 74 75**Description** 76 77Enumerates the types of signature verification parameters. 78 79**Since**: 12 80 81| Enum | Description | 82| -------- | -------- | 83| CRYPTO_PSS_MD_NAME_STR | MD algorithm used with the PSS padding mode in RSA. | 84| CRYPTO_PSS_MGF_NAME_STR | Mask generation algorithm used with the PSS padding mode in RSA. Currently, only MGF1 is supported. | 85| CRYPTO_PSS_MGF1_NAME_STR | MD parameters for the MGF1 mask generation used with the PSS padding mode in RSA. | 86| CRYPTO_PSS_SALT_LEN_INT | Length of the salt in bytes used with the PSS padding mode in RSA. | 87| CRYPTO_PSS_TRAILER_FIELD_INT | Trailer field used in the encoding operation when PSS padding mode is used in RSA. The value is **1**. | 88| CRYPTO_SM2_USER_ID_DATABLOB | User ID field in SM2. | 89 90 91## Function Description 92 93 94### OH_CryptoVerify_Create() 95 96``` 97OH_Crypto_ErrCode OH_CryptoVerify_Create (const char *algoName, OH_CryptoVerify **verify ) 98``` 99 100**Description** 101 102Creates a **Verify** instance for signature verification. 103 104**Since**: 12 105 106**Parameters** 107 108| Name | Description | 109| -------- | -------- | 110| algoName | Pointer to the algorithm used to generate the **Verify** instance. For example, **'RSA1024\|PKCS1\|SHA256'**.| | | 111| verify | Pointer to the **Verify** instance created. | 112 113**Returns** 114 115[OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode): 116 117**0**: The operation is successful. 118 119**401**: Invalid parameters are detected. 120 121**801**: The operation is not supported. 122 123**17620001**: A memory error occurred. 124 125**17630001**: Failed to call an API of a third-party algorithm library. 126 127 128### OH_CryptoVerify_Destroy() 129 130``` 131void OH_CryptoVerify_Destroy (OH_CryptoVerify *ctx) 132``` 133 134**Description** 135 136Destroys a **Verify** instance. 137 138**Since**: 12 139 140**Parameters** 141 142| Name | Description | 143| -------- | -------- | 144| ctx | Pointer to the **Verify** instance to destroy. | 145 146 147### OH_CryptoVerify_Final() 148 149``` 150bool OH_CryptoVerify_Final (OH_CryptoVerify *ctx, Crypto_DataBlob *in, Crypto_DataBlob *signData ) 151``` 152 153**Description** 154 155Verifies the signature of the data. 156 157**Since**: 12 158 159**Parameters** 160 161| Name | Description | 162| -------- | -------- | 163| ctx | Pointer to the **Verify** instance. | 164| in | Pointer to the data passed in. | 165| out | Pointer to the signature data. | 166 167**Returns** 168 169Returns a boolean value, indicating whether the signature verification is successful. 170 171**See** 172 173[OH_CryptoVerify_Init](#oh_cryptoverify_init) 174 175[OH_CryptoVerify_Update](#oh_cryptoverify_update) 176 177 178### OH_CryptoVerify_GetAlgoName() 179 180``` 181const char* OH_CryptoVerify_GetAlgoName (OH_CryptoVerify *ctx) 182``` 183 184**Description** 185 186Obtains the signature verification algorithm. 187 188**Since**: 12 189 190**Parameters** 191 192| Name | Description | 193| -------- | -------- | 194| ctx | Pointer to the **Verify** instance. | 195 196**Returns** 197 198Signature verification algorithm obtained. 199 200 201### OH_CryptoVerify_GetParam() 202 203``` 204OH_Crypto_ErrCode OH_CryptoVerify_GetParam (OH_CryptoVerify *ctx, CryptoSignature_ParamType type, Crypto_DataBlob *value ) 205``` 206 207**Description** 208 209Obtains a signature verification parameter. 210 211**Since**: 12 212 213**Parameters** 214 215| Name | Description | 216| -------- | -------- | 217| ctx | Pointer to the **Verify** instance. | 218| type | Name of the signature verification parameter to obtain. | 219| value | Pointer to the parameter value obtained. | 220 221**Returns** 222 223[OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode): 224 225**0**: The operation is successful. 226 227**401**: Invalid parameters are detected. 228 229**801**: The operation is not supported. 230 231**17620001**: A memory error occurred. 232 233**17630001**: Failed to call an API of a third-party algorithm library. 234 235 236### OH_CryptoVerify_Init() 237 238``` 239OH_Crypto_ErrCode OH_CryptoVerify_Init (OH_CryptoVerify *ctx, OH_CryptoPubKey *pubKey ) 240``` 241 242**Description** 243 244Initializes a **Verify** instance by using the public key. 245 246**Since**: 12 247 248**Parameters** 249 250| Name | Description | 251| -------- | -------- | 252| ctx | Pointer to the **Verify** instance. | 253| pubKey | Pointer to the public key. | 254 255**Returns** 256 257[OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode): 258 259**0**: The operation is successful. 260 261**401**: Invalid parameters are detected. 262 263**801**: The operation is not supported. 264 265**17620001**: A memory error occurred. 266 267**17630001**: Failed to call an API of a third-party algorithm library. 268 269**See** 270 271[OH_CryptoVerify_Update](#oh_cryptoverify_update) 272 273[OH_CryptoVerify_Final](#oh_cryptoverify_final) 274 275 276### OH_CryptoVerify_Recover() 277 278``` 279OH_Crypto_ErrCode OH_CryptoVerify_Recover (OH_CryptoVerify *ctx, Crypto_DataBlob *signData, Crypto_DataBlob *rawSignData ) 280``` 281 282**Description** 283 284Restores the signature data. 285 286**Since**: 12 287 288**Parameters** 289 290| Name | Description | 291| -------- | -------- | 292| ctx | Pointer to the **Verify** instance. | 293| signData | Pointer to the signature data to be restored. | 294| rawSignData | Pointer to the raw data restored. | 295 296**Returns** 297 298[OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode): 299 300**0**: The operation is successful. 301 302**401**: Invalid parameters are detected. 303 304**801**: The operation is not supported. 305 306**17620001**: A memory error occurred. 307 308**17630001**: Failed to call an API of a third-party algorithm library. 309 310 311### OH_CryptoVerify_SetParam() 312 313``` 314OH_Crypto_ErrCode OH_CryptoVerify_SetParam (OH_CryptoVerify *ctx, CryptoSignature_ParamType type, Crypto_DataBlob *value ) 315``` 316 317**Description** 318 319Sets a signature verification parameter. 320 321**Since**: 12 322 323**Parameters** 324 325| Name | Description | 326| -------- | -------- | 327| ctx | Pointer to the **Verify** instance. | 328| type | Name of the signature verification parameter to set. | 329| value | Pointer to the value of the signature verification parameter to set. | 330 331**Returns** 332 333[OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode): 334 335**0**: The operation is successful. 336 337**401**: Invalid parameters are detected. 338 339**801**: The operation is not supported. 340 341**17620001**: A memory error occurred. 342 343**17630001**: Failed to call an API of a third-party algorithm library. 344 345 346### OH_CryptoVerify_Update() 347 348``` 349OH_Crypto_ErrCode OH_CryptoVerify_Update (OH_CryptoVerify *ctx, Crypto_DataBlob *in ) 350``` 351 352**Description** 353 354Updates the data to be verified. 355 356**Since**: 12 357 358**Parameters** 359 360| Name | Description | 361| -------- | -------- | 362| ctx | Pointer to the **Verify** instance. | 363| in | Pointer to the data to pass in. | 364 365**Returns** 366 367[OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode): 368 369**0**: The operation is successful. 370 371**401**: Invalid parameters are detected. 372 373**801**: The operation is not supported. 374 375**17620001**: A memory error occurred. 376 377**17630001**: Failed to call an API of a third-party algorithm library. 378 379**See** 380 381[OH_CryptoVerify_Init](#oh_cryptoverify_init) 382 383[OH_CryptoVerify_Final](#oh_cryptoverify_final) 384