• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup CryptoAsymKeyApi
18  * @{
19  *
20  * @brief Describe the features provided by the openHarmony asymmetric key related interface for applications.
21  *
22  * @since 12
23  */
24 
25 /**
26  * @file crypto_asym_key.h
27  *
28  * @brief Defines the AsymKey APIs.
29  *
30  * @library libohcrypto.so
31  * @kit CryptoArchitectureKit
32  * @syscap SystemCapability.Security.CryptoFramework
33  * @since 12
34  */
35 
36 #ifndef CRYPTO_ASYM_KEY_H
37 #define CRYPTO_ASYM_KEY_H
38 
39 #include "crypto_common.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /**
46  * @brief Define the key pair structure.
47  *
48  * @since 12
49  */
50 typedef struct OH_CryptoKeyPair OH_CryptoKeyPair;
51 
52 /**
53  * @brief Define the public key structure.
54  *
55  * @since 12
56  */
57 typedef struct OH_CryptoPubKey OH_CryptoPubKey;
58 
59 /**
60  * @brief Defines the private key structure.
61  *
62  * @since 20
63  */
64 typedef struct OH_CryptoPrivKey OH_CryptoPrivKey;
65 
66 /**
67  * @brief Define the asymmetric key parameter types.
68  *
69  * @since 12
70  */
71 typedef enum {
72     /** Indicates the DSA prime p. */
73     CRYPTO_DSA_P_DATABLOB = 101,
74     /** Indicates the DSA sub-prime q. */
75     CRYPTO_DSA_Q_DATABLOB = 102,
76     /** Indicates the DSA base g. */
77     CRYPTO_DSA_G_DATABLOB = 103,
78     /** Indicates the DSA private key. */
79     CRYPTO_DSA_SK_DATABLOB = 104,
80     /** Indicates the DSA public key. */
81     CRYPTO_DSA_PK_DATABLOB = 105,
82 
83     /** Indicates the prime p of an elliptic curve (EC) prime finite field. */
84     CRYPTO_ECC_FP_P_DATABLOB = 201,
85     /** Indicates the first coefficient a of this elliptic curve. */
86     CRYPTO_ECC_A_DATABLOB = 202,
87     /** Indicates the second coefficient b of this elliptic curve. */
88     CRYPTO_ECC_B_DATABLOB = 203,
89     /** Indicates the affine x-coordinate of base point g. */
90     CRYPTO_ECC_G_X_DATABLOB = 204,
91     /** Indicates the affine y-coordinate of base point g. */
92     CRYPTO_ECC_G_Y_DATABLOB = 205,
93     /** Indicates the order of the base point g. */
94     CRYPTO_ECC_N_DATABLOB = 206,
95     /** Indicates the cofactor of the elliptic curve. */
96     CRYPTO_ECC_H_INT = 207,
97     /** Indicates the private value of the ECC private key. */
98     CRYPTO_ECC_SK_DATABLOB = 208,
99     /** Indicates the affine x-coordinate of a point, which is the public point of an ECC public key. */
100     CRYPTO_ECC_PK_X_DATABLOB = 209,
101     /** Indicates the affine y-coordinate of a point, which is the public point of an ECC public key. */
102     CRYPTO_ECC_PK_Y_DATABLOB = 210,
103     /** Indicates an elliptic curve finite field type. */
104     CRYPTO_ECC_FIELD_TYPE_STR = 211,
105     /** Indicates the field size in bits. */
106     CRYPTO_ECC_FIELD_SIZE_INT = 212,
107     /** Indicates the curve name according to SECG (Standards for Efficient Cryptography Group). */
108     CRYPTO_ECC_CURVE_NAME_STR = 213,
109 
110     /** Indicates the modulus n of RSA algorithm. */
111     CRYPTO_RSA_N_DATABLOB = 301,
112     /** Indicates the private exponent d of RSA algorithm. */
113     CRYPTO_RSA_D_DATABLOB = 302,
114     /** Indicates the public exponent e of RSA algorithm. */
115     CRYPTO_RSA_E_DATABLOB = 303,
116 
117     /** Indicates the prime p of DH algorithm. */
118     CRYPTO_DH_P_DATABLOB = 401,
119     /** Indicates the generator g of DH algorithm. */
120     CRYPTO_DH_G_DATABLOB = 402,
121     /** Indicates the number of bits of the private key length used in the DH algorithm. */
122     CRYPTO_DH_L_INT = 403,
123     /** Indicates the private value of the DH private key. */
124     CRYPTO_DH_SK_DATABLOB = 404,
125     /** Indicates the public value of the DH public key. */
126     CRYPTO_DH_PK_DATABLOB = 405,
127 
128     /** Indicates the private value of the ED25519 private key. */
129     CRYPTO_ED25519_SK_DATABLOB = 501,
130     /** Indicates the public value of the ED25519 public key. */
131     CRYPTO_ED25519_PK_DATABLOB = 502,
132     /** Indicates the private value of the X25519 private key. */
133     CRYPTO_X25519_SK_DATABLOB = 601,
134     /** Indicates the public value of the X25519 public key. */
135     CRYPTO_X25519_PK_DATABLOB = 602,
136 } CryptoAsymKey_ParamType;
137 
138 /**
139  * @brief Define the encoding type.
140  *
141  * @since 12
142  */
143 typedef enum {
144     /** PEM format */
145     CRYPTO_PEM = 0,
146     /** DER format */
147     CRYPTO_DER = 1,
148 } Crypto_EncodingType;
149 
150 /**
151  * @brief Define the asymmetric key generator structure.
152  *
153  * @since 12
154  */
155 typedef struct OH_CryptoAsymKeyGenerator OH_CryptoAsymKeyGenerator;
156 
157 /**
158  * @brief Create an asymmetric key generator according to the given algorithm name.
159  *
160  * @param algoName Indicates the algorithm name for generating the generator. Example RSA1024|PRIMES_2.
161  * @param ctx Indicates the pointer to asymmetric key generator context.
162  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
163  *         {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid.
164  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
165  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
166  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
167  * @since 12
168  */
169 OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_Create(const char *algoName, OH_CryptoAsymKeyGenerator **ctx);
170 
171 /**
172  * @brief Generate an asymmetric key(a key pair).
173  *
174  * @param ctx Indicates the asymmetric key generator context.
175  * @param keyCtx Indicates the pointer to the asyKey context.
176  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
177  *         {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid.
178  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
179  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
180  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
181  * @since 12
182  */
183 OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_Generate(OH_CryptoAsymKeyGenerator *ctx, OH_CryptoKeyPair **keyCtx);
184 
185 /**
186  * @brief Convert the asymmetric key data to a key pair.
187  *
188  * @param ctx Indicates the asymmetric key generator context.
189  * @param type Indicates the encryption encoding type.
190  * @param pubKeyData Indicates the public key data.
191  * @param priKeyData Indicates the private key data.
192  * @param keyCtx Indicates the pointer to the keyPair instance.
193  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
194  *         {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid.
195  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
196  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
197  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
198  * @since 12
199  */
200 OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_Convert(OH_CryptoAsymKeyGenerator *ctx, Crypto_EncodingType type,
201     Crypto_DataBlob *pubKeyData, Crypto_DataBlob *priKeyData, OH_CryptoKeyPair **keyCtx);
202 
203 /**
204  * @brief Get the algorithm name of the asymmetric key generator.
205  *
206  * @param ctx Indicates the asymmetric key generator context.
207  * @return Returns the asymmetric key algorithm name.
208  * @since 12
209  */
210 const char *OH_CryptoAsymKeyGenerator_GetAlgoName(OH_CryptoAsymKeyGenerator *ctx);
211 
212 /**
213  * @brief Destroy the asymmetric key generator.
214  *
215  * @param ctx Indicates the asymmetric key generator context.
216  * @since 12
217  */
218 void OH_CryptoAsymKeyGenerator_Destroy(OH_CryptoAsymKeyGenerator *ctx);
219 
220 /**
221  * @brief Destroy the key pair.
222  *
223  * @param keyCtx Indicates the keyPair context.
224  * @since 12
225  */
226 void OH_CryptoKeyPair_Destroy(OH_CryptoKeyPair *keyCtx);
227 
228 /**
229  * @brief Get the public key of the key pair.
230  *
231  * @param keyCtx Indicates the keyPair context.
232  * @return Return the public key context from the key pair.
233  * @since 12
234  */
235 OH_CryptoPubKey *OH_CryptoKeyPair_GetPubKey(OH_CryptoKeyPair *keyCtx);
236 
237 /**
238  * @brief Gets the private key of the key pair.
239  *
240  * @param keyCtx Indicates the keyPair context.
241  * @return Return the private key context from the key pair.
242  * @since 20
243  */
244 OH_CryptoPrivKey *OH_CryptoKeyPair_GetPrivKey(OH_CryptoKeyPair *keyCtx);
245 
246 /**
247  * @brief Encode the public key.
248  *
249  * @param key Indicates the public key.
250  * @param type Indicates the pubkey type.
251  * @param encodingStandard Indicates the encoding standard.
252  * @param out Indicates the encoded result.
253  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
254  *         {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid.
255  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
256  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
257  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
258  * @since 12
259  */
260 OH_Crypto_ErrCode OH_CryptoPubKey_Encode(OH_CryptoPubKey *key, Crypto_EncodingType type,
261     const char *encodingStandard, Crypto_DataBlob *out);
262 
263 /**
264  * @brief Get the specified param of the public key.
265  *
266  * @param key Indicates the public key.
267  * @param item Indicates the asymmetric key param type.
268  * @param value Indicates the output data.
269  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
270  *         {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid.
271  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
272  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
273  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
274  * @since 12
275  */
276 OH_Crypto_ErrCode OH_CryptoPubKey_GetParam(OH_CryptoPubKey *key, CryptoAsymKey_ParamType item, Crypto_DataBlob *value);
277 
278 /**
279  * @brief Sets the password to the asymmetric key generator context.
280  *
281  * Call this method to set the password if you need to convert encrypted private key data to a key pair using
282  * {@link OH_CryptoAsymKeyGenerator_Convert}.\n
283  *
284  * @param ctx Indicates the asymmetric key generator context.
285  * @param password Indicates the password.
286  * @param passwordLen Indicates the password length.
287  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
288  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
289  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
290  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
291  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
292  * @since 20
293  */
294 OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_SetPassword(OH_CryptoAsymKeyGenerator *ctx, const unsigned char *password,
295     uint32_t passwordLen);
296 
297 /**
298  * @brief Defines the private key encoding params structure.
299  *
300  * @since 20
301  */
302 typedef struct OH_CryptoPrivKeyEncodingParams OH_CryptoPrivKeyEncodingParams;
303 
304 /**
305  * @brief Defines the private key encoding param type.
306  *
307  * @since 20
308  */
309 typedef enum {
310     /** Indicates the password string. */
311     CRYPTO_PRIVATE_KEY_ENCODING_PASSWORD_STR = 0,
312 
313     /** Indicates the symmetric cipher string. */
314     CRYPTO_PRIVATE_KEY_ENCODING_SYMMETRIC_CIPHER_STR = 1,
315 } CryptoPrivKeyEncoding_ParamType;
316 
317 /**
318  * @brief Creates private key encoding params.
319  *
320  * @param ctx Indicates the private key encoding params.
321  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
322  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
323  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
324  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
325  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
326  * @since 20
327  */
328 OH_Crypto_ErrCode OH_CryptoPrivKeyEncodingParams_Create(OH_CryptoPrivKeyEncodingParams **ctx);
329 
330 /**
331  * @brief Sets the private key encoding params.
332  *
333  * @param ctx Indicates the private key encoding params.
334  * @param type Indicates the private key encoding param type.
335  * @param value Indicates the private key encoding params value.
336  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
337  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
338  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
339  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
340  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
341  * @since 20
342  */
343 OH_Crypto_ErrCode OH_CryptoPrivKeyEncodingParams_SetParam(OH_CryptoPrivKeyEncodingParams *ctx,
344     CryptoPrivKeyEncoding_ParamType type, Crypto_DataBlob *value);
345 
346 /**
347  * @brief Destroys the private key encoding params.
348  *
349  * @param ctx Indicates the private key encoding params.
350  * @since 20
351  */
352 void OH_CryptoPrivKeyEncodingParams_Destroy(OH_CryptoPrivKeyEncodingParams *ctx);
353 
354 /**
355  * @brief Encodes the private key.
356  *
357  * @param key Indicates the private key.
358  * @param type Indicates the private encoding type.
359  * @param encodingStandard Indicates the encoding standard, such as "PKCS8".
360  * @param params Indicates the private key encoding params, it can be NULL, and if you want encypt the private key,
361  * you should set this param.
362  * @param out Indicates the encoded result.
363  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
364  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
365  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
366  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
367  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
368  * @since 20
369  */
370 OH_Crypto_ErrCode OH_CryptoPrivKey_Encode(OH_CryptoPrivKey *key, Crypto_EncodingType type,
371     const char *encodingStandard, OH_CryptoPrivKeyEncodingParams *params, Crypto_DataBlob *out);
372 
373 /**
374  * @brief Gets the specified param of the private key.
375  *
376  * @param key Indicates the private key.
377  * @param item Indicates the asymmetric key param type.
378  * @param value Indicates the output data.
379  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
380  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
381  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
382  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
383  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
384  * @since 20
385  */
386 OH_Crypto_ErrCode OH_CryptoPrivKey_GetParam(OH_CryptoPrivKey *key, CryptoAsymKey_ParamType item,
387     Crypto_DataBlob *value);
388 
389 /**
390  * @brief Defines the asymmetric key spec structure.
391  *
392  * @since 20
393  */
394 typedef struct OH_CryptoAsymKeySpec OH_CryptoAsymKeySpec;
395 
396 /**
397  * @brief Defines the asymmetric key spec type.
398  *
399  * @since 20
400  */
401 typedef enum {
402     /** Common parameters spec. */
403     CRYPTO_ASYM_KEY_COMMON_PARAMS_SPEC = 0,
404     /** Private key spec. */
405     CRYPTO_ASYM_KEY_PRIVATE_KEY_SPEC = 1,
406     /** Public key spec. */
407     CRYPTO_ASYM_KEY_PUBLIC_KEY_SPEC = 2,
408     /** Key pair spec. */
409     CRYPTO_ASYM_KEY_KEY_PAIR_SPEC = 3,
410 } CryptoAsymKeySpec_Type;
411 
412 /**
413  * @brief Generates an EC common parameters spec.
414  *
415  * @param curveName Indicates the ECC curve name.
416  * @param spec Indicates the pointer to the EC common parameters spec.
417  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
418  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
419  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
420  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
421  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
422  * @since 20
423  */
424 OH_Crypto_ErrCode OH_CryptoAsymKeySpec_GenEcCommonParamsSpec(const char *curveName, OH_CryptoAsymKeySpec **spec);
425 
426 /**
427  * @brief Generates a DH common parameters spec.
428  *
429  * @param pLen Indicates the byte length of the prime p.
430  * @param skLen Indicates the byte length of the private key.
431  * @param spec Indicates the pointer to the DH common parameters spec.
432  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
433  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
434  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
435  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
436  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
437  * @since 20
438  */
439 OH_Crypto_ErrCode OH_CryptoAsymKeySpec_GenDhCommonParamsSpec(int pLen, int skLen, OH_CryptoAsymKeySpec **spec);
440 
441 /**
442  * @brief Creates an asymmetric key spec according to the given algorithm name and spec type.
443  *
444  * @param algoName Indicates the algorithm name for generating the spec. Example RSA.
445  * @param type Indicates the asymmetric key spec type.
446  * @param spec Indicates the pointer to the asymmetric key spec.
447  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
448  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
449  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
450  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
451  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
452  * @since 20
453  */
454 OH_Crypto_ErrCode OH_CryptoAsymKeySpec_Create(const char *algoName, CryptoAsymKeySpec_Type type,
455     OH_CryptoAsymKeySpec **spec);
456 
457 /**
458  * @brief Sets the specified parameter to the asymmetric key spec.
459  *
460  * @param spec Indicates the asymmetric key spec.
461  * @param type Indicates the asymmetric key param type.
462  * @param value Indicates the input data.
463  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
464  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
465  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
466  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
467  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
468  * @since 20
469  */
470 OH_Crypto_ErrCode OH_CryptoAsymKeySpec_SetParam(OH_CryptoAsymKeySpec *spec, CryptoAsymKey_ParamType type,
471     Crypto_DataBlob *value);
472 
473 /**
474  * @brief Sets the common parameters spec to the asymmetric key spec.
475  *
476  * @param spec Indicates the asymmetric key spec.
477  * @param commonParamsSpec Indicates the common parameters spec.
478  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
479  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
480  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
481  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
482  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
483  * @since 20
484  */
485 OH_Crypto_ErrCode OH_CryptoAsymKeySpec_SetCommonParamsSpec(OH_CryptoAsymKeySpec *spec,
486     OH_CryptoAsymKeySpec *commonParamsSpec);
487 
488 /**
489  * @brief Gets the specified parameter from the asymmetric key spec.
490  *
491  * @param spec Indicates the asymmetric key spec.
492  * @param type Indicates the asymmetric key param type.
493  * @param value Indicates the output data.
494  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
495  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
496  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
497  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
498  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
499  * @since 20
500  */
501 OH_Crypto_ErrCode OH_CryptoAsymKeySpec_GetParam(OH_CryptoAsymKeySpec *spec, CryptoAsymKey_ParamType type,
502     Crypto_DataBlob *value);
503 
504 /**
505  * @brief Destroys the asymmetric key spec.
506  *
507  * @param spec Indicates the asymmetric key spec.
508  * @since 20
509  */
510 void OH_CryptoAsymKeySpec_Destroy(OH_CryptoAsymKeySpec *spec);
511 
512 /**
513  * @brief Defines the asymmetric key generator with spec.
514  *
515  * @since 20
516  */
517 typedef struct OH_CryptoAsymKeyGeneratorWithSpec OH_CryptoAsymKeyGeneratorWithSpec;
518 
519 /**
520  * @brief Creates an asymmetric key generator with spec.
521  *
522  * @param keySpec Indicates the asymmetric key spec.
523  * @param generator Indicates the asymmetric key generator with spec.
524  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
525  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
526  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
527  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
528  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
529  * @since 20
530  */
531 OH_Crypto_ErrCode OH_CryptoAsymKeyGeneratorWithSpec_Create(OH_CryptoAsymKeySpec *keySpec,
532     OH_CryptoAsymKeyGeneratorWithSpec **generator);
533 
534 /**
535  * @brief Generates a key pair according to the asymmetric key spec.
536  *
537  * @param generator Indicates the asymmetric key generator with spec.
538  * @param keyPair Indicates the pointer to the key pair.
539  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
540  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
541  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
542  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
543  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
544  * @since 20
545  */
546 OH_Crypto_ErrCode OH_CryptoAsymKeyGeneratorWithSpec_GenKeyPair(OH_CryptoAsymKeyGeneratorWithSpec *generator,
547     OH_CryptoKeyPair **keyPair);
548 
549 /**
550  * @brief Destroys the asymmetric key generator with spec.
551  *
552  * @param generator Indicates the asymmetric key generator with spec.
553  * @since 20
554  */
555 void OH_CryptoAsymKeyGeneratorWithSpec_Destroy(OH_CryptoAsymKeyGeneratorWithSpec *generator);
556 
557 /**
558  * @brief Defines the EC point structure.
559  *
560  * @since 20
561  */
562 typedef struct OH_CryptoEcPoint OH_CryptoEcPoint;
563 
564 /**
565  * @brief Creates an EC point.
566  *
567  * @param curveName Indicates the curve name.
568  * @param ecKeyData Indicates the EC point data, supports "04 || x || y", "02 || x" or "03 || x" format.
569  * If ecKeyData param is NULL, an empty EC point spec will be created.
570  * @param point Indicates the pointer to the EC point.
571  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
572  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
573  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
574  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
575  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
576  * @since 20
577  */
578 OH_Crypto_ErrCode OH_CryptoEcPoint_Create(const char *curveName, Crypto_DataBlob *ecKeyData, OH_CryptoEcPoint **point);
579 
580 /**
581  * @brief Gets the x and y coordinate of the EC point.
582  *
583  * @param point Indicates the EC point.
584  * @param x Indicates the x coordinate of the EC point, it can be NULL.
585  * @param y Indicates the y coordinate of the EC point, it can be NULL.
586  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
587  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
588  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
589  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
590  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
591  * @since 20
592  */
593 OH_Crypto_ErrCode OH_CryptoEcPoint_GetCoordinate(OH_CryptoEcPoint *point, Crypto_DataBlob *x, Crypto_DataBlob *y);
594 
595 /**
596  * @brief Sets the x and y coordinate to the EC point.
597  *
598  * @param point Indicates the EC point.
599  * @param x Indicates the x coordinate of the EC point.
600  * @param y Indicates the y coordinate of the EC point.
601  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
602  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
603  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
604  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
605  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
606  * @since 20
607  */
608 OH_Crypto_ErrCode OH_CryptoEcPoint_SetCoordinate(OH_CryptoEcPoint *point, Crypto_DataBlob *x, Crypto_DataBlob *y);
609 
610 /**
611  * @brief Encodes the EC point to the specified format.
612  *
613  * @param point Indicates the EC point.
614  * @param format Indicates the encoding format, supports "UNCOMPRESSED" and "COMPRESSED".
615  * @param out Indicates the encoded ec point data.
616  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
617  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
618  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
619  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
620  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
621  * @since 20
622  */
623 OH_Crypto_ErrCode OH_CryptoEcPoint_Encode(OH_CryptoEcPoint *point, const char *format, Crypto_DataBlob *out);
624 
625 /**
626  * @brief Destroys the EC point.
627  *
628  * @param point Indicates the EC point.
629  * @since 20
630  */
631 void OH_CryptoEcPoint_Destroy(OH_CryptoEcPoint *point);
632 
633 #ifdef __cplusplus
634 }
635 #endif
636 
637 /** @} */
638 #endif /* CRYPTO_ASYM_KEY_H */
639