17777dab0Sopenharmony_ci/* 27777dab0Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 37777dab0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 47777dab0Sopenharmony_ci * you may not use this file except in compliance with the License. 57777dab0Sopenharmony_ci * You may obtain a copy of the License at 67777dab0Sopenharmony_ci * 77777dab0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 87777dab0Sopenharmony_ci * 97777dab0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 107777dab0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 117777dab0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127777dab0Sopenharmony_ci * See the License for the specific language governing permissions and 137777dab0Sopenharmony_ci * limitations under the License. 147777dab0Sopenharmony_ci */ 157777dab0Sopenharmony_ci 167777dab0Sopenharmony_ci/** 177777dab0Sopenharmony_ci * @addtogroup CryptoSymKeyApi 187777dab0Sopenharmony_ci * @{ 197777dab0Sopenharmony_ci * 207777dab0Sopenharmony_ci * @brief Describe openHarmony symmetric key related features interfaces provide for applications. 217777dab0Sopenharmony_ci * 227777dab0Sopenharmony_ci * @since 12 237777dab0Sopenharmony_ci */ 247777dab0Sopenharmony_ci 257777dab0Sopenharmony_ci/** 267777dab0Sopenharmony_ci * @file crypto_sym_key.h 277777dab0Sopenharmony_ci * 287777dab0Sopenharmony_ci * @brief Defines the symmetric key APIs. 297777dab0Sopenharmony_ci * 307777dab0Sopenharmony_ci * @library libohcrypto.so 317777dab0Sopenharmony_ci * @kit CryptoArchitectureKit 327777dab0Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 337777dab0Sopenharmony_ci * @since 12 347777dab0Sopenharmony_ci */ 357777dab0Sopenharmony_ci 367777dab0Sopenharmony_ci#ifndef CRYPTO_SYM_KEY_H 377777dab0Sopenharmony_ci#define CRYPTO_SYM_KEY_H 387777dab0Sopenharmony_ci 397777dab0Sopenharmony_ci#include "crypto_common.h" 407777dab0Sopenharmony_ci 417777dab0Sopenharmony_ci#ifdef __cplusplus 427777dab0Sopenharmony_ciextern "C" { 437777dab0Sopenharmony_ci#endif 447777dab0Sopenharmony_ci 457777dab0Sopenharmony_ci/** 467777dab0Sopenharmony_ci * @brief Define the symmetric key structure. 477777dab0Sopenharmony_ci * 487777dab0Sopenharmony_ci * @since 12 497777dab0Sopenharmony_ci */ 507777dab0Sopenharmony_citypedef struct OH_CryptoSymKey OH_CryptoSymKey; 517777dab0Sopenharmony_ci 527777dab0Sopenharmony_ci/** 537777dab0Sopenharmony_ci * @brief Define the symmetric key generator structure. 547777dab0Sopenharmony_ci * 557777dab0Sopenharmony_ci * @since 12 567777dab0Sopenharmony_ci */ 577777dab0Sopenharmony_citypedef struct OH_CryptoSymKeyGenerator OH_CryptoSymKeyGenerator; 587777dab0Sopenharmony_ci 597777dab0Sopenharmony_ci/** 607777dab0Sopenharmony_ci * @brief Create a symmetric key generator according to the given algorithm name. Example AES256. 617777dab0Sopenharmony_ci * 627777dab0Sopenharmony_ci * @param algoName Indicates the algorithm name for generating the generator. 637777dab0Sopenharmony_ci * @param ctx Indicates the pointer to the symmetric key generator context. 647777dab0Sopenharmony_ci * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. 657777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid. 667777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. 677777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. 687777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed. 697777dab0Sopenharmony_ci * @since 12 707777dab0Sopenharmony_ci */ 717777dab0Sopenharmony_ciOH_Crypto_ErrCode OH_CryptoSymKeyGenerator_Create(const char *algoName, OH_CryptoSymKeyGenerator **ctx); 727777dab0Sopenharmony_ci 737777dab0Sopenharmony_ci/** 747777dab0Sopenharmony_ci * @brief Generate a symmetric key. 757777dab0Sopenharmony_ci * 767777dab0Sopenharmony_ci * @param ctx Indicates the Symmetric key generator context. 777777dab0Sopenharmony_ci * @param keyCtx Indicates the pointer to the symmetric key context. 787777dab0Sopenharmony_ci * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. 797777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid. 807777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. 817777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. 827777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed. 837777dab0Sopenharmony_ci * @since 12 847777dab0Sopenharmony_ci */ 857777dab0Sopenharmony_ciOH_Crypto_ErrCode OH_CryptoSymKeyGenerator_Generate(OH_CryptoSymKeyGenerator *ctx, OH_CryptoSymKey **keyCtx); 867777dab0Sopenharmony_ci 877777dab0Sopenharmony_ci/** 887777dab0Sopenharmony_ci * @brief Convert the symmetric key data to a key. 897777dab0Sopenharmony_ci * 907777dab0Sopenharmony_ci * @param ctx Indicates the symmetric key generator context. 917777dab0Sopenharmony_ci * @param keyData Indicates the data to generate the Symkey. 927777dab0Sopenharmony_ci * @param keyCtx Indicates the pointer to the symmetric key context. 937777dab0Sopenharmony_ci * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. 947777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid. 957777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. 967777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. 977777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed. 987777dab0Sopenharmony_ci * @since 12 997777dab0Sopenharmony_ci */ 1007777dab0Sopenharmony_ciOH_Crypto_ErrCode OH_CryptoSymKeyGenerator_Convert(OH_CryptoSymKeyGenerator *ctx, 1017777dab0Sopenharmony_ci const Crypto_DataBlob *keyData, OH_CryptoSymKey **keyCtx); 1027777dab0Sopenharmony_ci 1037777dab0Sopenharmony_ci/** 1047777dab0Sopenharmony_ci * @brief Get the algorithm name of the symmetric key generator. 1057777dab0Sopenharmony_ci * 1067777dab0Sopenharmony_ci * @param ctx Indicates the symmetric key generator context. 1077777dab0Sopenharmony_ci * @return Return symmetric key algorithm name. 1087777dab0Sopenharmony_ci * @since 12 1097777dab0Sopenharmony_ci */ 1107777dab0Sopenharmony_ciconst char *OH_CryptoSymKeyGenerator_GetAlgoName(OH_CryptoSymKeyGenerator *ctx); 1117777dab0Sopenharmony_ci 1127777dab0Sopenharmony_ci/** 1137777dab0Sopenharmony_ci * @brief Destroy the symmetric key generator. 1147777dab0Sopenharmony_ci * 1157777dab0Sopenharmony_ci * @param ctx Indicates the symmetric key generator context. 1167777dab0Sopenharmony_ci * @since 12 1177777dab0Sopenharmony_ci */ 1187777dab0Sopenharmony_civoid OH_CryptoSymKeyGenerator_Destroy(OH_CryptoSymKeyGenerator *ctx); 1197777dab0Sopenharmony_ci 1207777dab0Sopenharmony_ci/** 1217777dab0Sopenharmony_ci * @brief Get the symmetric key algorithm name from a symmetric key. 1227777dab0Sopenharmony_ci * 1237777dab0Sopenharmony_ci * @param keyCtx Indicates the symmetric key context. 1247777dab0Sopenharmony_ci * @return Return algorithm name. 1257777dab0Sopenharmony_ci * @since 12 1267777dab0Sopenharmony_ci */ 1277777dab0Sopenharmony_ciconst char *OH_CryptoSymKey_GetAlgoName(OH_CryptoSymKey *keyCtx); 1287777dab0Sopenharmony_ci 1297777dab0Sopenharmony_ci/** 1307777dab0Sopenharmony_ci * @brief Get the symmetric key data from a symmetric key. 1317777dab0Sopenharmony_ci * 1327777dab0Sopenharmony_ci * @param keyCtx Indicates the symmetric key context. 1337777dab0Sopenharmony_ci * @param out Indicate to obtain the result. 1347777dab0Sopenharmony_ci * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. 1357777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid. 1367777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. 1377777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. 1387777dab0Sopenharmony_ci * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed. 1397777dab0Sopenharmony_ci * @since 12 1407777dab0Sopenharmony_ci */ 1417777dab0Sopenharmony_ciOH_Crypto_ErrCode OH_CryptoSymKey_GetKeyData(OH_CryptoSymKey *keyCtx, Crypto_DataBlob *out); 1427777dab0Sopenharmony_ci 1437777dab0Sopenharmony_ci/** 1447777dab0Sopenharmony_ci * @brief Destroy the symmetric key. 1457777dab0Sopenharmony_ci * 1467777dab0Sopenharmony_ci * @param keyCtx Indicates the symmetric key context. 1477777dab0Sopenharmony_ci * @since 12 1487777dab0Sopenharmony_ci */ 1497777dab0Sopenharmony_civoid OH_CryptoSymKey_Destroy(OH_CryptoSymKey *keyCtx); 1507777dab0Sopenharmony_ci 1517777dab0Sopenharmony_ci#ifdef __cplusplus 1527777dab0Sopenharmony_ci} 1537777dab0Sopenharmony_ci#endif 1547777dab0Sopenharmony_ci 1557777dab0Sopenharmony_ci/** @} */ 1567777dab0Sopenharmony_ci#endif /* CRYPTO_SYM_KEY_H */ 157