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 * @since 20 59 */ 60 RDB_AES_256_GCM = 0, 61 /** 62 * @brief Indicates the database is encrypted using RDB_AES_256_CBC. 63 * 64 * @since 20 65 */ 66 RDB_AES_256_CBC, 67 } Rdb_EncryptionAlgo; 68 69 /** 70 * @brief Enumerates the supported HMAC algorithm when opening a database. 71 * 72 * @since 20 73 */ 74 typedef enum Rdb_HmacAlgo { 75 /** 76 * @brief RDB_HMAC_SHA1 algorithm. 77 * 78 * @since 20 79 */ 80 RDB_HMAC_SHA1 = 0, 81 /** 82 * @brief RDB_HMAC_SHA256 algorithm. 83 * 84 * @since 20 85 */ 86 RDB_HMAC_SHA256, 87 /** 88 * @brief RDB_HMAC_SHA512 algorithm. 89 * 90 * @since 20 91 */ 92 RDB_HMAC_SHA512, 93 } Rdb_HmacAlgo; 94 95 /** 96 * @brief Enumerates the supported KDF algorithm when opening a database. 97 * 98 * @since 20 99 */ 100 typedef enum Rdb_KdfAlgo { 101 /** 102 * @brief RDB_KDF_SHA1 algorithm. 103 * 104 * @since 20 105 */ 106 RDB_KDF_SHA1 = 0, 107 /** 108 * @brief RDB_KDF_SHA256 algorithm. 109 * 110 * @since 20 111 */ 112 RDB_KDF_SHA256, 113 /** 114 * @brief RDB_KDF_SHA512 algorithm. 115 * 116 * @since 20 117 */ 118 RDB_KDF_SHA512, 119 } Rdb_KdfAlgo; 120 121 /** 122 * @brief Specifies the cryptographic parameters used when opening an encrypted database. 123 * 124 * @since 20 125 */ 126 typedef struct OH_Rdb_CryptoParam OH_Rdb_CryptoParam; 127 128 /** 129 * @brief Creates an OH_Rdb_CryptoParam instance object. 130 * 131 * @return Returns a pointer to OH_Rdb_CryptoParam instance when the execution is successful. 132 * Otherwise, nullptr is returned. The memory must be released through the OH_Rdb_DestroyCryptoParam 133 * interface after the use is complete. 134 * @see OH_Rdb_DestroyCryptoParam. 135 * @since 20 136 */ 137 OH_Rdb_CryptoParam *OH_Rdb_CreateCryptoParam(void); 138 139 /** 140 * @brief Destroys an OH_Rdb_CryptoParam instance object. 141 * 142 * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam. 143 * @return Returns the error code. 144 * Returns {@link RDB_OK} if the execution is successful. 145 * Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter. 146 * @since 20 147 */ 148 int OH_Rdb_DestroyCryptoParam(OH_Rdb_CryptoParam *param); 149 150 /** 151 * @brief Sets key data to the OH_Rdb_CryptoParam object. 152 * 153 * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam. 154 * @param key Represents a pointer to array data. 155 * @param length Represents the size of key array. 156 * @return Returns the error code. 157 * Returns {@link RDB_OK} if the execution is successful. 158 * Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter. 159 * @since 20 160 */ 161 int OH_Crypto_SetEncryptionKey(OH_Rdb_CryptoParam *param, const uint8_t *key, int32_t length); 162 163 /** 164 * @brief Sets the number of KDF iterations used when opening an encrypted database. 165 * 166 * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam. 167 * @param iteration Represents a pointer to array data. 168 * @return Returns the error code. 169 * Returns {@link RDB_OK} if the execution is successful. 170 * Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter. 171 * @since 20 172 */ 173 int OH_Crypto_SetIteration(OH_Rdb_CryptoParam *param, int64_t iteration); 174 175 /** 176 * @brief Sets the encryption algorithm when opening an encrypted database. 177 * 178 * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam. 179 * @param algo Represents the encryption algorithm. 180 * @return Returns the error code. 181 * Returns {@link RDB_OK} if the execution is successful. 182 * Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter. 183 * @since 20 184 */ 185 int OH_Crypto_SetEncryptionAlgo(OH_Rdb_CryptoParam *param, int32_t algo); 186 187 /** 188 * @brief Sets the HMAC algorithm when opening an encrypted database. 189 * 190 * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam. 191 * @param algo Represents the HMAC algorithm. 192 * @return Returns the error code. 193 * Returns {@link RDB_OK} if the execution is successful. 194 * Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter. 195 * @since 20 196 */ 197 int OH_Crypto_SetHmacAlgo(OH_Rdb_CryptoParam *param, int32_t algo); 198 199 /** 200 * @brief Sets the KDF algorithm when opening an encrypted database. 201 * 202 * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam. 203 * @param algo Represents the KDF algorithm. 204 * @return Returns the error code. 205 * Returns {@link RDB_OK} if the execution is successful. 206 * Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter. 207 * @since 20 208 */ 209 int OH_Crypto_SetKdfAlgo(OH_Rdb_CryptoParam *param, int32_t algo); 210 211 /** 212 * @brief Sets the page size used when opening an encrypted database. 213 * 214 * @param param Represents a pointer to an instance of OH_Rdb_CryptoParam. 215 * @param size Represents the page size. 216 * @return Returns the error code. 217 * Returns {@link RDB_OK} if the execution is successful. 218 * Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter. 219 * @since 20 220 */ 221 int OH_Crypto_SetCryptoPageSize(OH_Rdb_CryptoParam *param, int64_t size); 222 223 #ifdef __cplusplus 224 }; 225 #endif 226 #endif 227 /** @} */ 228