• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 CryptoKeyAgreementApi
18  * @{
19  *
20  * @brief Describes key agreement algorithm interface provided to applications.
21  *
22  * @since 20
23  */
24 
25 /**
26  * @file crypto_key_agreement.h
27  *
28  * @brief Defines the key agreement APIs.
29  *
30  * @library libohcrypto.so
31  * @kit CryptoArchitectureKit
32  * @syscap SystemCapability.Security.CryptoFramework
33  * @since 20
34  */
35 
36 #ifndef CRYPTO_KEY_AGREEMENT_H
37 #define CRYPTO_KEY_AGREEMENT_H
38 
39 #include "crypto_common.h"
40 #include "crypto_asym_key.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**
47  * @brief Defines the key agreement structure.
48  *
49  * @since 20
50  */
51 typedef struct OH_CryptoKeyAgreement OH_CryptoKeyAgreement;
52 
53 /**
54  * @brief Creates a key agreement context according to the given algorithm name.
55  *
56  * @param algoName Indicates the algorithm name used to generate a key agreement context. e.g. "ECC", "X25519".
57  * @param ctx Indicates the key agreement context.
58  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
59  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
60  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
61  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
62  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
63  * @since 20
64  */
65 OH_Crypto_ErrCode OH_CryptoKeyAgreement_Create(const char *algoName, OH_CryptoKeyAgreement **ctx);
66 
67 /**
68  * @brief Generates a secret value.
69  *
70  * @param ctx Indicates the key agreement context.
71  * @param privkey Indicates the private key.
72  * @param pubkey Indicates the public key.
73  * @param secret Indicates the secret value.
74  * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful.
75  *         {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported.
76  *         {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed.
77  *         {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed.
78  *         {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed.
79  * @since 20
80  */
81 OH_Crypto_ErrCode OH_CryptoKeyAgreement_GenerateSecret(OH_CryptoKeyAgreement *ctx, OH_CryptoPrivKey *privkey,
82     OH_CryptoPubKey *pubkey, Crypto_DataBlob *secret);
83 
84 /**
85  * @brief Destroys the key agreement context.
86  *
87  * @param ctx Indicates the key agreement context.
88  * @since 20
89  */
90 void OH_CryptoKeyAgreement_Destroy(OH_CryptoKeyAgreement *ctx);
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
96 #endif /* CRYPTO_KEY_AGREEMENT_H */
97 /** @} */
98