1526fd984Sopenharmony_ci/* 2526fd984Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 3526fd984Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4526fd984Sopenharmony_ci * you may not use this file except in compliance with the License. 5526fd984Sopenharmony_ci * You may obtain a copy of the License at 6526fd984Sopenharmony_ci * 7526fd984Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8526fd984Sopenharmony_ci * 9526fd984Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10526fd984Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11526fd984Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12526fd984Sopenharmony_ci * See the License for the specific language governing permissions and 13526fd984Sopenharmony_ci * limitations under the License. 14526fd984Sopenharmony_ci */ 15526fd984Sopenharmony_ci 16526fd984Sopenharmony_ci#ifndef NATIVE_HUKS_PARAM_H 17526fd984Sopenharmony_ci#define NATIVE_HUKS_PARAM_H 18526fd984Sopenharmony_ci 19526fd984Sopenharmony_ci/** 20526fd984Sopenharmony_ci * @addtogroup HuksParamSetApi 21526fd984Sopenharmony_ci * @{ 22526fd984Sopenharmony_ci * 23526fd984Sopenharmony_ci * @brief Defines the capabilities of OpenHarmony Universal KeyStore (HUKS) parameter sets. 24526fd984Sopenharmony_ci * The HUKS APIs can be used to perform parameter set lifecycle management, 25526fd984Sopenharmony_ci * including initializing a parameter set, adding parameters to a parameter set, constructing 26526fd984Sopenharmony_ci * a parameter set, and destroying a parameter set. 27526fd984Sopenharmony_ci * They can also be used to obtain parameters, copy parameter sets, and check parameter validity. 28526fd984Sopenharmony_ci * 29526fd984Sopenharmony_ci * @syscap SystemCapability.Security.Huks 30526fd984Sopenharmony_ci * @since 9 31526fd984Sopenharmony_ci * @version 1.0 32526fd984Sopenharmony_ci */ 33526fd984Sopenharmony_ci 34526fd984Sopenharmony_ci/** 35526fd984Sopenharmony_ci * @file native_huks_param.h 36526fd984Sopenharmony_ci * 37526fd984Sopenharmony_ci * @brief Provides APIs for constructing, using, and destroying parameter sets. 38526fd984Sopenharmony_ci * 39526fd984Sopenharmony_ci * include "huks/include/native_huks_type.h" 40526fd984Sopenharmony_ci * @kit Universal Keystore Kit 41526fd984Sopenharmony_ci * @since 9 42526fd984Sopenharmony_ci * @version 1.0 43526fd984Sopenharmony_ci */ 44526fd984Sopenharmony_ci 45526fd984Sopenharmony_ci#include "native_huks_type.h" 46526fd984Sopenharmony_ci 47526fd984Sopenharmony_ci#ifdef __cplusplus 48526fd984Sopenharmony_ciextern "C" { 49526fd984Sopenharmony_ci#endif 50526fd984Sopenharmony_ci 51526fd984Sopenharmony_ci/** 52526fd984Sopenharmony_ci * @brief Initializes a parameter set. 53526fd984Sopenharmony_ci * 54526fd984Sopenharmony_ci * @param paramSet Indicates the double pointer to the parameter set to initialize. 55526fd984Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the initialization is successful. 56526fd984Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_INSUFFICIENT_MEMORY} 12000014 - If the memory is insufficient. 57526fd984Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If the paramset is null. 58526fd984Sopenharmony_ci * @since 9 59526fd984Sopenharmony_ci * @version 1.0 60526fd984Sopenharmony_ci */ 61526fd984Sopenharmony_cistruct OH_Huks_Result OH_Huks_InitParamSet(struct OH_Huks_ParamSet **paramSet); 62526fd984Sopenharmony_ci 63526fd984Sopenharmony_ci/** 64526fd984Sopenharmony_ci * @brief Adds parameters to a parameter set. 65526fd984Sopenharmony_ci * 66526fd984Sopenharmony_ci * @param paramSet Indicates the pointer to the parameter set to which parameters are to be added. 67526fd984Sopenharmony_ci * @param params Indicates the pointer to the array of parameters to add. 68526fd984Sopenharmony_ci * @param paramCnt Indicates the number of parameters to add. 69526fd984Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the operation is successful. 70526fd984Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If params is null or paramSet is invalid. 71526fd984Sopenharmony_ci * @since 9 72526fd984Sopenharmony_ci * @version 1.0 73526fd984Sopenharmony_ci */ 74526fd984Sopenharmony_cistruct OH_Huks_Result OH_Huks_AddParams(struct OH_Huks_ParamSet *paramSet, 75526fd984Sopenharmony_ci const struct OH_Huks_Param *params, uint32_t paramCnt); 76526fd984Sopenharmony_ci 77526fd984Sopenharmony_ci/** 78526fd984Sopenharmony_ci * @brief Constructs a parameter set. 79526fd984Sopenharmony_ci * 80526fd984Sopenharmony_ci * @param paramSet Indicates the double pointer to the parameter set to construct. 81526fd984Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the operation is successful. 82526fd984Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If paramSet is invalid. 83526fd984Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_INSUFFICIENT_MEMORY} 12000014 - If the memory is insufficient. 84526fd984Sopenharmony_ci * @since 9 85526fd984Sopenharmony_ci * @version 1.0 86526fd984Sopenharmony_ci */ 87526fd984Sopenharmony_cistruct OH_Huks_Result OH_Huks_BuildParamSet(struct OH_Huks_ParamSet **paramSet); 88526fd984Sopenharmony_ci 89526fd984Sopenharmony_ci/** 90526fd984Sopenharmony_ci * @brief Destroys a parameter set. 91526fd984Sopenharmony_ci * 92526fd984Sopenharmony_ci * @param paramSet Indicates the double pointer to the parameter set to destroy. 93526fd984Sopenharmony_ci * @since 9 94526fd984Sopenharmony_ci * @version 1.0 95526fd984Sopenharmony_ci */ 96526fd984Sopenharmony_civoid OH_Huks_FreeParamSet(struct OH_Huks_ParamSet **paramSet); 97526fd984Sopenharmony_ci 98526fd984Sopenharmony_ci/** 99526fd984Sopenharmony_ci * @brief Copies a parameter set (deep copy). 100526fd984Sopenharmony_ci * 101526fd984Sopenharmony_ci * @param fromParamSet Indicates the pointer to the parameter set to copy. 102526fd984Sopenharmony_ci * @param fromParamSetSize Indicates the memory size occupied by the source parameter set. 103526fd984Sopenharmony_ci * @param paramSet Indicates the double pointer to the new parameter set generated. 104526fd984Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the operation is successful. 105526fd984Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If fromParamSet or fromParamSetSize 106526fd984Sopenharmony_ci * or paramSet is invalid. 107526fd984Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_INSUFFICIENT_MEMORY} 12000014 - If the memory is insufficient. 108526fd984Sopenharmony_ci * @since 9 109526fd984Sopenharmony_ci * @version 1.0 110526fd984Sopenharmony_ci */ 111526fd984Sopenharmony_cistruct OH_Huks_Result OH_Huks_CopyParamSet(const struct OH_Huks_ParamSet *fromParamSet, 112526fd984Sopenharmony_ci uint32_t fromParamSetSize, struct OH_Huks_ParamSet **paramSet); 113526fd984Sopenharmony_ci 114526fd984Sopenharmony_ci/** 115526fd984Sopenharmony_ci * @brief Obtains parameters from a parameter set. 116526fd984Sopenharmony_ci * 117526fd984Sopenharmony_ci * @param paramSet Indicates the pointer to the target parameter set. 118526fd984Sopenharmony_ci * @param tag Indicates the value of the parameter to be obtained. 119526fd984Sopenharmony_ci * @param param Indicates the double pointer to the parameter obtained. 120526fd984Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the operation is successful, 121526fd984Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If paramSet or param is invalid, 122526fd984Sopenharmony_ci * or if the param doesn't exist in the pararmset. 123526fd984Sopenharmony_ci * @since 9 124526fd984Sopenharmony_ci * @version 1.0 125526fd984Sopenharmony_ci */ 126526fd984Sopenharmony_cistruct OH_Huks_Result OH_Huks_GetParam(const struct OH_Huks_ParamSet *paramSet, uint32_t tag, 127526fd984Sopenharmony_ci struct OH_Huks_Param **param); 128526fd984Sopenharmony_ci 129526fd984Sopenharmony_ci/** 130526fd984Sopenharmony_ci * @brief Refreshes data of the <b>Blob</b> type in a parameter set. 131526fd984Sopenharmony_ci * 132526fd984Sopenharmony_ci * @param paramSet Indicates the pointer to the target parameter set. 133526fd984Sopenharmony_ci * @param isCopy Specifies whether to copy the data of the <b>Blob</b> type to the parameter set. 134526fd984Sopenharmony_ci * If yes, the data of the <b>Blob</b> type will be copied to the parameter set. 135526fd984Sopenharmony_ci * Otherwise, only the address of the <b>Blob</b> data will be refreshed. 136526fd984Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If operation is successful. 137526fd984Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If paramSet is invalid. 138526fd984Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_INSUFFICIENT_MEMORY} 12000014 - If the memory is insufficient. 139526fd984Sopenharmony_ci * @since 9 140526fd984Sopenharmony_ci * @version 1.0 141526fd984Sopenharmony_ci */ 142526fd984Sopenharmony_cistruct OH_Huks_Result OH_Huks_FreshParamSet(struct OH_Huks_ParamSet *paramSet, bool isCopy); 143526fd984Sopenharmony_ci 144526fd984Sopenharmony_ci/** 145526fd984Sopenharmony_ci * @brief Checks whether the parameters in a parameter set are valid. 146526fd984Sopenharmony_ci * 147526fd984Sopenharmony_ci * @param paramSet Indicates the pointer to the parameter set to check. 148526fd984Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the parameters in the parameter set are valid. 149526fd984Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If paramSet is invalid or 150526fd984Sopenharmony_ci * the parameter set has invalid, duplicate, or incorrect tags. 151526fd984Sopenharmony_ci * @since 9 152526fd984Sopenharmony_ci * @version 1.0 153526fd984Sopenharmony_ci */ 154526fd984Sopenharmony_cistruct OH_Huks_Result OH_Huks_IsParamSetTagValid(const struct OH_Huks_ParamSet *paramSet); 155526fd984Sopenharmony_ci 156526fd984Sopenharmony_ci/** 157526fd984Sopenharmony_ci * @brief Checks whether a parameter set is of the valid size. 158526fd984Sopenharmony_ci * 159526fd984Sopenharmony_ci * @param paramSet Indicates the pointer to the parameter set to check. 160526fd984Sopenharmony_ci * @param size Indicates the memory size occupied by the parameter set. 161526fd984Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the parameter set is of the valid size. 162526fd984Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If paramSet is invalid. 163526fd984Sopenharmony_ci * @since 9 164526fd984Sopenharmony_ci * @version 1.0 165526fd984Sopenharmony_ci */ 166526fd984Sopenharmony_cistruct OH_Huks_Result OH_Huks_IsParamSetValid(const struct OH_Huks_ParamSet *paramSet, uint32_t size); 167526fd984Sopenharmony_ci 168526fd984Sopenharmony_ci/** 169526fd984Sopenharmony_ci * @brief Checks whether two parameters are the same. 170526fd984Sopenharmony_ci * 171526fd984Sopenharmony_ci * @param baseParam Indicates the pointer to the first parameter. 172526fd984Sopenharmony_ci * @param param Indicates the pointer to the second parameter. 173526fd984Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the two parameters are the same. 174526fd984Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If one of the paramSet is invalid, 175526fd984Sopenharmony_ci * or if the params don't match, or if the tag inside is invalid. 176526fd984Sopenharmony_ci * @since 9 177526fd984Sopenharmony_ci * @version 1.0 178526fd984Sopenharmony_ci */ 179526fd984Sopenharmony_cistruct OH_Huks_Result OH_Huks_CheckParamMatch(const struct OH_Huks_Param *baseParam, const struct OH_Huks_Param *param); 180526fd984Sopenharmony_ci 181526fd984Sopenharmony_ci/** 182526fd984Sopenharmony_ci * @brief Destroys a parameter set. 183526fd984Sopenharmony_ci * 184526fd984Sopenharmony_ci * @param keyAliasSet Indicates the pointer to the parameter set to destroy. 185526fd984Sopenharmony_ci * @since 12 186526fd984Sopenharmony_ci * @version 1.0 187526fd984Sopenharmony_ci */ 188526fd984Sopenharmony_civoid OH_Huks_FreeKeyAliasSet(struct OH_Huks_KeyAliasSet *keyAliasSet); 189526fd984Sopenharmony_ci 190526fd984Sopenharmony_ci#ifdef __cplusplus 191526fd984Sopenharmony_ci} 192526fd984Sopenharmony_ci#endif 193526fd984Sopenharmony_ci 194526fd984Sopenharmony_ci/** @} */ 195526fd984Sopenharmony_ci#endif /* NATIVE_HUKS_PARAM_H */ 196