• 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 RDB
18  * @{
19  *
20  * @brief The relational database (RDB) store manages data based on relational models.
21  * With the underlying SQLite database, the RDB store provides a complete mechanism for managing local databases.
22  * To satisfy different needs in complicated scenarios, the RDB store offers a series of APIs for performing operations
23  * such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements.
24  *
25  * @since 10
26  */
27 
28 /**
29  * @file oh_rdb_crypto_param.h
30  *
31  * @brief Provides functions and enumerations related to cryptographic parameters of the relational database.
32  *
33  * @kit ArkData
34  * @library libnative_rdb_ndk.z.so
35  * @syscap SystemCapability.DistributedDataManager.RelationalStore.Core
36  *
37  * @since 20
38  */
39 
40 #ifndef OH_RDB_CRYPTO_PARAM_H
41 #define OH_RDB_CRYPTO_PARAM_H
42 
43 #include <inttypes.h>
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /**
50  * @brief Enumerates the database encryption algorithms.
51  *
52  * @since 20
53  */
54 typedef enum Rdb_EncryptionAlgo {
55     /**
56      * @brief Indicates the database is encrypted using RDB_AES_256_GCM.
57      */
58     RDB_AES_256_GCM = 0,
59     /**
60      * @brief Indicates the database is encrypted using RDB_AES_256_CBC.
61      */
62     RDB_AES_256_CBC,
63 } Rdb_EncryptionAlgo;
64 
65 /**
66  * @brief Enumerates the supported HMAC algorithm when opening a database.
67  *
68  * @since 20
69  */
70 typedef enum Rdb_HmacAlgo {
71     /**
72      * @brief RDB_HMAC_SHA1 algorithm.
73      */
74     RDB_HMAC_SHA1 = 0,
75     /**
76      * @brief RDB_HMAC_SHA256 algorithm.
77      */
78     RDB_HMAC_SHA256,
79     /**
80      * @brief RDB_HMAC_SHA512 algorithm.
81      */
82     RDB_HMAC_SHA512,
83 } Rdb_HmacAlgo;
84 
85 /**
86  * @brief Enumerates the supported KDF algorithm when opening a database.
87  *
88  * @since 20
89  */
90 typedef enum Rdb_KdfAlgo {
91     /**
92      * @brief RDB_KDF_SHA1 algorithm.
93      */
94     RDB_KDF_SHA1 = 0,
95     /**
96      * @brief RDB_KDF_SHA256 algorithm.
97      */
98     RDB_KDF_SHA256,
99     /**
100      * @brief RDB_KDF_SHA512 algorithm.
101      */
102     RDB_KDF_SHA512,
103 } Rdb_KdfAlgo;
104 
105 /**
106  * @brief Specifies the cryptographic parameters used when opening an encrypted database.
107  *
108  * @since 20
109  */
110 typedef struct OH_Rdb_CryptoParam OH_Rdb_CryptoParam;
111 
112 /**
113  * @brief Creates an OH_Rdb_CryptoParam instance object.
114  *
115  * @return Returns a pointer to OH_Rdb_CryptoParam instance when the execution is successful.
116  * Otherwise, nullptr is returned. The memory must be released through the OH_Rdb_DestroyCryptoParam
117  * interface after the use is complete.
118  * @see OH_Rdb_DestroyCryptoParam.
119  * @since 20
120  */
121 OH_Rdb_CryptoParam *OH_Rdb_CreateCryptoParam(void);
122 
123 /**
124  * @brief Destroys an OH_Rdb_CryptoParam instance object.
125  *
126  * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam.
127  * @return Returns the error code.
128  *         Returns {@link RDB_OK} if the execution is successful.
129  *         Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter.
130  * @since 20
131  */
132 int OH_Rdb_DestroyCryptoParam(OH_Rdb_CryptoParam *param);
133 
134 /**
135  * @brief Sets key data to the OH_Rdb_CryptoParam object.
136  *
137  * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam.
138  * @param key Represents a pointer to array data.
139  * @param length Represents the size of key array.
140  * @return Returns the error code.
141  *         Returns {@link RDB_OK} if the execution is successful.
142  *         Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter.
143  * @since 20
144  */
145 int OH_Crypto_SetEncryptionKey(OH_Rdb_CryptoParam *param, const uint8_t *key, int32_t length);
146 
147 /**
148  * @brief Sets the number of KDF iterations used when opening an encrypted database.
149  *
150  * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam.
151  * @param iteration Represents iterations times.
152  * @return Returns the error code.
153  *         Returns {@link RDB_OK} if the execution is successful.
154  *         Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter.
155  * @since 20
156  */
157 int OH_Crypto_SetIteration(OH_Rdb_CryptoParam *param, int64_t iteration);
158 
159 /**
160  * @brief Sets the encryption algorithm when opening an encrypted database.
161  *
162  * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam.
163  * @param algo Represents the encryption algorithm.
164  * @return Returns the error code.
165  *         Returns {@link RDB_OK} if the execution is successful.
166  *         Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter.
167  * @since 20
168  */
169 int OH_Crypto_SetEncryptionAlgo(OH_Rdb_CryptoParam *param, int32_t algo);
170 
171 /**
172  * @brief Sets the HMAC algorithm when opening an encrypted database.
173  *
174  * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam.
175  * @param algo Represents the HMAC algorithm.
176  * @return Returns the error code.
177  *         Returns {@link RDB_OK} if the execution is successful.
178  *         Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter.
179  * @since 20
180  */
181 int OH_Crypto_SetHmacAlgo(OH_Rdb_CryptoParam *param, int32_t algo);
182 
183 /**
184  * @brief Sets the KDF algorithm when opening an encrypted database.
185  *
186  * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam.
187  * @param algo Represents the KDF algorithm.
188  * @return Returns the error code.
189  *         Returns {@link RDB_OK} if the execution is successful.
190  *         Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter.
191  * @since 20
192  */
193 int OH_Crypto_SetKdfAlgo(OH_Rdb_CryptoParam *param, int32_t algo);
194 
195 /**
196  * @brief Sets the page size used when opening an encrypted database.
197  *
198  * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam.
199  * @param size Represents the page size.
200  * @return Returns the error code.
201  *         Returns {@link RDB_OK} if the execution is successful.
202  *         Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter.
203  * @since 20
204  */
205 int OH_Crypto_SetCryptoPageSize(OH_Rdb_CryptoParam *param, int64_t size);
206 
207 #ifdef __cplusplus
208 };
209 #endif
210 #endif
211 /** @} */
212