From 42926f3f87a9f9a03dfe3916c4b04eb2279ecb7e Mon Sep 17 00:00:00 2001 From: "@lwx1140380" Date: Tue, 19 Jul 2022 10:13:13 +0800 Subject: [PATCH 01/17] =?UTF-8?q?fix=EF=BC=9AMissing=20@}=20at=20the=20end?= =?UTF-8?q?=20of=20Codec=20HDI=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: @lwx1140380 --- en/device_api/hdi/codec/codec_callback_if.h | 1 + en/device_api/hdi/codec/codec_component_if.h | 1 + zh-cn/device_api/hdi/codec/codec_callback_if.h | 3 ++- zh-cn/device_api/hdi/codec/codec_component_if.h | 3 ++- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/en/device_api/hdi/codec/codec_callback_if.h b/en/device_api/hdi/codec/codec_callback_if.h index 24ad92bd..e47081b2 100644 --- a/en/device_api/hdi/codec/codec_callback_if.h +++ b/en/device_api/hdi/codec/codec_callback_if.h @@ -154,3 +154,4 @@ void CodecCallbackTypeRelease(struct CodecCallbackType *instance); #endif /* __cplusplus */ #endif // CODEC_CALLBACK_TYPE_H +/** @} */ diff --git a/en/device_api/hdi/codec/codec_component_if.h b/en/device_api/hdi/codec/codec_component_if.h index c566230d..97e0256a 100644 --- a/en/device_api/hdi/codec/codec_component_if.h +++ b/en/device_api/hdi/codec/codec_component_if.h @@ -450,3 +450,4 @@ void CodecComponentTypeRelease(struct CodecComponentType *instance); #endif /* __cplusplus */ #endif // CODEC_COMPONENT_H +/** @} */ diff --git a/zh-cn/device_api/hdi/codec/codec_callback_if.h b/zh-cn/device_api/hdi/codec/codec_callback_if.h index 52c236ff..94ba6a72 100644 --- a/zh-cn/device_api/hdi/codec/codec_callback_if.h +++ b/zh-cn/device_api/hdi/codec/codec_callback_if.h @@ -156,4 +156,5 @@ void CodecCallbackTypeRelease(struct CodecCallbackType *instance); } #endif /* __cplusplus */ -#endif // CODEC_CALLBACK_IF_H \ No newline at end of file +#endif // CODEC_CALLBACK_IF_H +/** @} */ diff --git a/zh-cn/device_api/hdi/codec/codec_component_if.h b/zh-cn/device_api/hdi/codec/codec_component_if.h index a4a1766d..26578bbd 100644 --- a/zh-cn/device_api/hdi/codec/codec_component_if.h +++ b/zh-cn/device_api/hdi/codec/codec_component_if.h @@ -431,4 +431,5 @@ void CodecComponentTypeRelease(struct CodecComponentType *instance); } #endif /* __cplusplus */ -#endif // CODEC_COMPONENT_IF_H \ No newline at end of file +#endif // CODEC_COMPONENT_IF_H +/** @} */ -- Gitee From 8329a2cbfd86b7f5345a8d6a47fa066ee266a60a Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Mon, 25 Jul 2022 10:58:01 +0800 Subject: [PATCH 02/17] capi last Signed-off-by: zqr2001 <1805768383@qq.com> --- .../security/huks/native_huks_api.h | 188 +++ .../security/huks/native_huks_param.h | 154 +++ .../security/huks/native_huks_type.h | 1005 +++++++++++++++++ .../security/huks/native_huks_type_inner.h | 31 + 4 files changed, 1378 insertions(+) create mode 100644 zh-cn/native_sdk/security/huks/native_huks_api.h create mode 100644 zh-cn/native_sdk/security/huks/native_huks_param.h create mode 100644 zh-cn/native_sdk/security/huks/native_huks_type.h create mode 100644 zh-cn/native_sdk/security/huks/native_huks_type_inner.h diff --git a/zh-cn/native_sdk/security/huks/native_huks_api.h b/zh-cn/native_sdk/security/huks/native_huks_api.h new file mode 100644 index 00000000..cde82d8e --- /dev/null +++ b/zh-cn/native_sdk/security/huks/native_huks_api.h @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup huks + * @{ + * + * @brief 描述huks向应用提供密钥库能力,包括密钥管理及密钥的密码学操作等功能。 + * 管理的密钥可以由应用导入或者由应用调用HUKS接口生成。 + * + * @since 8 + * @version 1.0 + */ + +/** + * @file native_huks_api.h + * + * @brief 声明用于访问huks的API。 + * + * @since 8 + * @version 1.0 + */ + +#ifndef _NATIVE_HUKS_API_H_ +#define _NATIVE_HUKS_API_H_ + +#include "native_hks_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 获取huks的版本信息。 + * + * @param sdkVersion 用于存储获取到的版本信息。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_GetSdkVersion(struct OH_Huks_Blob *sdkVersion); + +/** + * @brief 生成密钥。 + * + * @param keyAlias 表示给要生成的密钥取的别名。 + * @param paramSetIn 表示生成密钥需要的输入参数集。 + * @param paramSetOut 生成密钥为临时类型时存放着密钥数据;非临时类型可为空。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_GenerateKey(const struct OH_Huks_Blob *keyAlias, + const struct OH_Huks_ParamSet *paramSetIn, struct OH_Huks_ParamSet *paramSetOut); + +/** + * @brief 导入密钥。 + * + * @param keyAlias 表示给要导入的密钥取的别名。 + * @param paramSet 表示导入密钥需要的输入参数集。 + * @param key 表示导入的密钥数据。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_ImportKey(const struct OH_Huks_Blob *keyAlias, + const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *key); + +/** + * @brief 导出公钥。 + * + * @param keyAlias 表示要导出公钥对应的密钥别名。 + * @param paramSet 表示导出公钥需要的输入参数集。 + * @param key 表示要导入的密钥数据。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_ExportPublicKey(const struct OH_Huks_Blob *keyAlias, + const struct OH_Huks_ParamSet *paramSet, struct OH_Huks_Blob *key); + +/** + * @brief 删除密钥。 + * + * @param keyAlias 表示要删除密钥的别名。 + * @param paramSet 表示要删除密钥需要的输入参数集。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_DeleteKey(const struct OH_Huks_Blob *keyAlias, + const struct OH_Huks_ParamSet *paramSet); + +/** + * @brief 获取生成密钥时的参数集。 + * + * @param keyAlias 表示要获取参数集的密钥别名 + * @param paramSetIn 表示要获取参数集需要的输入参数集。 + * @param paramSetOut 表示获取到的输出参数集。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_GetKeyParamSet(const struct OH_Huks_Blob *keyAlias, + const struct OH_Huks_ParamSet *paramSetIn, struct OH_Huks_ParamSet *paramSetOut); + +/** + * @brief 查询存储中密钥是否存在。 + * + * @param keyAlias 表示密钥别名。 + * @param paramSet 表示查询需要的输入参数集。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_KeyExist(const struct OH_Huks_Blob *keyAlias, + const struct OH_Huks_ParamSet *paramSet); + +/** + * @brief 使用密钥对数据进行算法操作的init动作。 + * + * @param keyAlias 表示使用密钥的别名。 + * @param paramSet 表示init需要的输入参数集。 + * @param handle 表示使init、update、finish和abort联系起来的输出特征值。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_Init(const struct OH_Huks_Blob *keyAlias, + const struct OH_Huks_ParamSet *paramSet, struct OH_Huks_Blob *handle); + +/** + * @brief 使用密钥对数据进行算法操作的update动作。 + * + * @param handle 表示使init、update、finish和abort联系起来的输入特征值。 + * @param paramSet 表示update需要的输入参数集。 + * @param inData 表示要处理的输入数据,如果数据过大,可分片多次调用update。 + * @param outData 表示经过算法操作处理后的输出数据。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_Update(const struct OH_Huks_Blob *handle, + const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *outData); + +/** + * @brief 使用密钥对数据进行算法操作的finish动作。 + * + * @param handle 表示使init、update、finish和abort联系起来的输入特征值。 + * @param paramSet 表示finish需要的输入参数集。 + * @param inData 表示要处理的输入数据。 + * @param outData 表示经过算法操作处理后的输出数据。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_Finish(const struct OH_Huks_Blob *handle, + const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *outData); + +/** + * @brief update、finish异常退出的清理动作。 + * + * @param handle 表示使init、update、finish和abort联系起来的输入特征值。 + * @param paramSet 表示abort需要的输入参数集。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_Abort(const struct OH_Huks_Blob *handle, + const struct OH_Huks_ParamSet *paramSet); + +#ifdef __cplusplus +} +#endif + +#endif /* NATIVE_HUKS_API_H */ diff --git a/zh-cn/native_sdk/security/huks/native_huks_param.h b/zh-cn/native_sdk/security/huks/native_huks_param.h new file mode 100644 index 00000000..5da98b19 --- /dev/null +++ b/zh-cn/native_sdk/security/huks/native_huks_param.h @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file native_huks_param.h + * + * @brief 提供参数集构造、使用和销毁的API。 + * + * @since 8 + * @version 1.0 + */ + +#ifndef NATIVE_HUKS_PARAM_H +#define NATIVE_HUKS_PARAM_H + +#include "native_hks_type.h" + +#define OH_HUKS_PARAM_SET_MAX_SIZE (4 * 1024 * 1024) +#define OH_HUKS_DEFAULT_PARAM_SET_SIZE 512 +#define OH_HUKS_DEFAULT_PARAM_CNT ((uint32_t)(OH_HUKS_DEFAULT_PARAM_SET_SIZE / sizeof(struct OH_Huks_Param))) +#define OH_HUKS_TAG_TYPE_MASK (0xF << 28) + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 初始化参数集。 + * + * @param paramSet 表示指向要初始化的参数集的指针。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_InitParamSet(struct OH_Huks_ParamSet **paramSet); + +/** + * @brief 添加参数到参数集里面。 + * + * @param paramSet 表示指向要被添加参数的参数集的指针。 + * @param params 表示指向要添加的参数的指针。 + * @param paramCnt 表示要添加参数的个数。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_AddParams(struct OH_Huks_ParamSet *paramSet, + const struct OH_Huks_Param *params, uint32_t paramCnt); + +/** + * @brief 构造正式的参数集。 + * + * @param paramSet 表示指向要被正式构造的参数集的指针。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_BuildParamSet(struct OH_Huks_ParamSet **paramSet); + +/** + * @brief 销毁参数集。 + * + * @param paramSet 表示指向要被销毁的参数集的指针。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT void OH_Huks_FreeParamSet(struct OH_Huks_ParamSet **paramSet); + +/** + * @brief 复制参数集。 + * + * @param fromParamSet 表示指向要被复制的参数集的指针。 + * @param fromParamSetSize 表示被复制的参数集占用内存的大小。 + * @param paramSet 表示指向生成新的参数集的指针。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_GetParamSet(const struct OH_Huks_ParamSet *fromParamSet, + uint32_t fromParamSetSize, struct OH_Huks_ParamSet **paramSet); + +/** + * @brief 从参数集中获取参数。 + * + * @param paramSet 表示指向参数集的指针。 + * @param tag 表示要获取的参数对应的特征值。 + * @param param 表示指向获取到的参数的指针。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_GetParam(const struct OH_Huks_ParamSet *paramSet, uint32_t tag, + struct OH_Huks_Param **param); + +/** + * @brief 刷新参数集。 + * + * @param paramSet 表示指向参数集的指针。 + * @param isCopy 表示是否要刷新参数集内存中的struct HksBlob型的参数数据。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_FreshParamSet(struct OH_Huks_ParamSet *paramSet, bool isCopy); + +/** + * @brief 检查参数集中的参数是否有效、是否有重复。 + * + * @param paramSet 表示指向参数集的指针。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +int32_t OH_Huks_CheckParamSetTag(const struct OH_Huks_ParamSet *paramSet); + +/** + * @brief 检查参数集是否有效。 + * + * @param paramSet 表示指向参数集的指针。 + * @param size 表示参数集占用的内存大小。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +int32_t OH_Huks_CheckParamSet(const struct OH_Huks_ParamSet *paramSet, uint32_t size); + +/** + * @brief 比较两个参数是否相同 + * + * @param baseParam 表示指向被比较的参数的指针。 + * @param param 表示指向比较的参数的指针。 + * @return 返回执行的状态代码。 + * @since 8 + * @version 1.0 + */ +int32_t OH_Huks_CheckParamMatch(const struct OH_Huks_Param *baseParam, const struct OH_Huks_Param *param); + +#ifdef __cplusplus +} +#endif + +#endif /* NATIVE_HUKS_PARAM_H */ \ No newline at end of file diff --git a/zh-cn/native_sdk/security/huks/native_huks_type.h b/zh-cn/native_sdk/security/huks/native_huks_type.h new file mode 100644 index 00000000..0d0550f7 --- /dev/null +++ b/zh-cn/native_sdk/security/huks/native_huks_type.h @@ -0,0 +1,1005 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file native_huks_type.h + * + * @brief 提供huks中的枚举变量、结构体定义与宏定义。 + * + * @since 8 + * @version 1.0 + */ + +#ifndef _NATIVE_HUKS_TYPE_H_ +#define _NATIVE_HUKS_TYPE_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef OH_HUKS_API_PUBLIC + #if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(__ICCARM__) /* __ICCARM__ for iar */ + #define OH_HUKS_API_EXPORT + #else + #define OH_HUKS_API_EXPORT __attribute__ ((visibility("default"))) + #endif +#else + #define OH_HUKS_API_EXPORT __attribute__ ((visibility("default"))) +#endif + +#define OH_HUKS_SDK_VERSION "2.0.0.4" + + +/** + * @brief Align to 4-tuple。 + * + * Before calling this function, ensure that the size does not overflow after 3 is added. + * + * @since 8 + * @version 1.0 + */ +#define OH_HUKS_DEFAULT_ALIGN_MASK_SIZE 3 + +#define OH_HUKS_AE_TAG_LEN 16 +#define OH_HUKS_BITS_PER_BYTE 8 +#define OH_HUKS_MAX_KEY_SIZE 2048 +#define OH_HUKS_AE_TAG_LEN 16 +#define OH_HUKS_AE_NONCE_LEN 12 +#define OH_HUKS_MAX_KEY_ALIAS_LEN 64 +#define OH_HUKS_MAX_PROCESS_NAME_LEN 50 +#define OH_HUKS_MAX_RANDOM_LEN 1024 +#define OH_HUKS_SIGNATURE_MIN_SIZE 64 +#define OH_HUKS_MAX_OUT_BLOB_SIZE (5 * 1024 * 1024) +#define OH_HUKS_WRAPPED_FORMAT_MAX_SIZE (1024 * 1024) +#define OH_HUKS_IMPORT_WRAPPED_KEY_TOTAL_BLOBS 10 + +/** + * @brief 枚举密钥用途。 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_KeyPurpose { + /** 加密, 支持的密钥类型有RSA、EC、AES和SM4。 */ + OH_HUKS_KEY_PURPOSE_ENCRYPT = 1, + /** 解密, 支持的密钥类型有RSA、EC、AES和SM4。 */ + OH_HUKS_KEY_PURPOSE_DECRYPT = 2, + /** 签名, 支持的密钥类型有RSA和EC。 */ + OH_HUKS_KEY_PURPOSE_SIGN = 4, + /** 验签, 支持的密钥类型有RSA和EC。 */ + OH_HUKS_KEY_PURPOSE_VERIFY = 8, + /** 派生, 支持的密钥类型有EC。 */ + OH_HUKS_KEY_PURPOSE_DERIVE = 16, + /** 包装, 支持的密钥类型有wrap。 */ + OH_HUKS_KEY_PURPOSE_WRAP = 32, + /** 解包, 支持的密钥类型有unwrap。 */ + OH_HUKS_KEY_PURPOSE_UNWRAP = 64, + /** 消息认证码。 */ + OH_HUKS_KEY_PURPOSE_MAC = 128, + /** 协商。 */ + OH_HUKS_KEY_PURPOSE_AGREE = 256, +}; + +/** + * @brief 枚举摘要算法类型。 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_KeyDigest { + /** 不使用摘要。 */ + OH_HUKS_DIGEST_NONE = 0, + /** 信息摘要MD5。 */ + OH_HUKS_DIGEST_MD5 = 1, + /** 国密摘要SM3。 */ + OH_HUKS_DIGEST_SM3 = 2, + /** 安全哈希SHA1。 */ + OH_HUKS_DIGEST_SHA1 = 10, + /** 安全哈希SHA224。 */ + OH_HUKS_DIGEST_SHA224 = 11, + /** 安全哈希SHA256。 */ + OH_HUKS_DIGEST_SHA256 = 12, + /** 安全哈希SHA384。 */ + OH_HUKS_DIGEST_SHA384 = 13, + /** 安全哈希SHA512。 */ + OH_HUKS_DIGEST_SHA512 = 14, +}; + +/** + * @brief 枚举数据填充方式。 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_KeyPadding { + /** 不填充。 */ + OH_HUKS_PADDING_NONE = 0, + /** 最优非对称加密填充。 */ + OH_HUKS_PADDING_OAEP = 1, + /** 概率签名方案填充。 */ + OH_HUKS_PADDING_PSS = 2, + /** 公钥加密标准PKCS1_V1_5填充。 */ + OH_HUKS_PADDING_PKCS1_V1_5 = 3, + /** 公钥加密标准PKCS5填充。 */ + OH_HUKS_PADDING_PKCS5 = 4, + /** 公钥加密标准PKCS7填充。 */ + OH_HUKS_PADDING_PKCS7 = 5, +}; + +/** + * @brief 枚举加密工作模式。 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_CipherMode { + /** 电子密码本模式。 */ + OH_HUKS_MODE_ECB = 1, + /** 密文分组链接模式。 */ + OH_HUKS_MODE_CBC = 2, + /** 计数器模式。 */ + OH_HUKS_MODE_CTR = 3, + /** 输出反馈模。 */ + OH_HUKS_MODE_OFB = 4, + /** 认证加密CCM模式。 */ + OH_HUKS_MODE_CCM = 31, + /** 认证加密GCM模式。 */ + OH_HUKS_MODE_GCM = 32, +}; + +/** + * @brief 枚举不同算法支持的密钥长度。 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_KeySize { + /** RSA算法支持的密钥长度为1024位。 */ + OH_HUKS_RSA_KEY_SIZE_1024 = 1024, + /** RSA算法支持的密钥长度为2048位。 */ + OH_HUKS_RSA_KEY_SIZE_2048 = 2048, + /** RSA算法支持的密钥长度为3072位。 */ + OH_HUKS_RSA_KEY_SIZE_3072 = 3072, + /** RSA算法支持的密钥长度为4096位。 */ + OH_HUKS_RSA_KEY_SIZE_4096 = 4096, + + /** ECC算法支持的密钥长度为256位。 */ + OH_HUKS_ECC_KEY_SIZE_256 = 256, + /** ECC算法支持的密钥长度为384位。 */ + OH_HUKS_ECC_KEY_SIZE_384 = 384, + /** ECC算法支持的密钥长度为521位。 */ + OH_HUKS_ECC_KEY_SIZE_521 = 521, + + /** AES算法支持的密钥长度为128位。 */ + OH_HUKS_AES_KEY_SIZE_128 = 128, + /** AES算法支持的密钥长度为192位。 */ + OH_HUKS_AES_KEY_SIZE_192 = 192, + /** AES算法支持的密钥长度为256位。 */ + OH_HUKS_AES_KEY_SIZE_256 = 256, + /** AES算法支持的密钥长度为512位。 */ + OH_HUKS_AES_KEY_SIZE_512 = 512, + + /** CURVE25519算法支持的密钥长度为256位。 */ + OH_HUKS_CURVE25519_KEY_SIZE_256 = 256, + + /** SM2算法支持的密钥长度为256位。 */ + OH_HUKS_SM2_KEY_SIZE_256 = 256, + /** SM4算法支持的密钥长度为128位。 */ + OH_HUKS_SM4_KEY_SIZE_128 = 128, +}; + +/** + * @brief 枚举支持的算法类型。 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_KeyAlg { + /** 非对称密钥算法RSA。 */ + OH_HUKS_ALG_RSA = 1, + /** 非对称密钥算法ECC。 */ + OH_HUKS_ALG_ECC = 2, + + /** 对称密钥算法AES。 */ + OH_HUKS_ALG_AES = 20, + /** 消息认证码算法HMAC。 */ + OH_HUKS_ALG_HMAC = 50, + /** 基于HMAC的密钥推导函数算法HKDF。 */ + OH_HUKS_ALG_HKDF = 51, + /** 伪随机函数以导出密钥算法PBKDF2。 */ + OH_HUKS_ALG_PBKDF2 = 52, + + /** 密钥协商算法ECDH。 */ + OH_HUKS_ALG_ECDH = 100, + /** 密钥协商算法X25519。 */ + OH_HUKS_ALG_X25519 = 101, + /** 签名验签算法ED25519。 */ + OH_HUKS_ALG_ED25519 = 102, + + /** 国密算法SM2。*/ + OH_HUKS_ALG_SM2 = 150, + /** 国密算法SM3。*/ + OH_HUKS_ALG_SM3 = 151, + /** 国密算法SM4。*/ + OH_HUKS_ALG_SM4 = 152, +}; + +/** + * @brief 枚举解包套件的算法类型 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_AlgSuite { + /** Algorithm suites of unwrapping wrapped-key by huks + * Unwrap suite of key agreement type + */ + /** WrappedData format(Bytes Array): + * | x25519_plain_pubkey_length (4 Byte) | x25519_plain_pubkey | agreekey_aad_length (4 Byte) | agreekey_aad + * | agreekey_nonce_length (4 Byte) | agreekey_nonce | agreekey_aead_tag_len(4 Byte) | agreekey_aead_tag + * | kek_enc_data_length (4 Byte) | kek_enc_data | kek_aad_length (4 Byte) | kek_aad + * | kek_nonce_length (4 Byte) | kek_nonce | kek_aead_tag_len (4 Byte) | kek_aead_tag + * | key_material_size_len (4 Byte) | key_material_size | key_mat_enc_length (4 Byte) | key_mat_enc_data + */ + OH_HUKS_UNWRAP_SUITE_X25519_AES_256_GCM_NOPADDING = 1, + + /* WrappedData format(Bytes Array): + * | ECC_plain_pubkey_length (4 Byte) | ECC_plain_pubkey | agreekey_aad_length (4 Byte) | agreekey_aad + * | agreekey_nonce_length (4 Byte) | agreekey_nonce | agreekey_aead_tag_len(4 Byte) | agreekey_aead_tag + * | kek_enc_data_length (4 Byte) | kek_enc_data | kek_aad_length (4 Byte) | kek_aad + * | kek_nonce_length (4 Byte) | kek_nonce | kek_aead_tag_len (4 Byte) | kek_aead_tag + * | key_material_size_len (4 Byte) | key_material_size | key_mat_enc_length (4 Byte) | key_mat_enc_data + */ + OH_HUKS_UNWRAP_SUITE_ECDH_AES_256_GCM_NOPADDING = 2, +}; + +/** + * @brief 枚举生成的密钥类型。 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_KeyGenerateType { + /** 默认类型。 */ + OH_HUKS_KEY_GENERATE_TYPE_DEFAULT = 0, + /** 派生类型。 */ + OH_HUKS_KEY_GENERATE_TYPE_DERIVE = 1, + /** 协商类型。 */ + OH_HUKS_KEY_GENERATE_TYPE_AGREE = 2, +}; + +/** + * @brief 枚举密钥的标记类型。 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_KeyFlag { + /** 导入密钥的标记。*/ + OH_HUKS_KEY_FLAG_IMPORT_KEY = 1, + /** 生成密钥的标记。*/ + OH_HUKS_KEY_FLAG_GENERATE_KEY = 2, + /** 协商密钥的标记。*/ + OH_HUKS_KEY_FLAG_AGREE_KEY = 3, + /** 派生密钥的标记。*/ + OH_HUKS_KEY_FLAG_DERIVE_KEY = 4, +}; + +/** + * @brief 枚举密钥的存储类型。 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_KeyStorageType { + /** 临时性存储。*/ + OH_HUKS_STORAGE_TEMP = 0, + /** 永久性存储。*/ + OH_HUKS_STORAGE_PERSISTENT = 1, +}; + +/** + * @brief 枚举导入密钥的类型。 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_ImportKeyType { + /** 公钥类型。 */ + OH_HUKS_KEY_TYPE_PUBLIC_KEY = 0, + /** 私钥类型。 */ + OH_HUKS_KEY_TYPE_PRIVATE_KEY = 1, + /** 密钥对类型。 */ + OH_HUKS_KEY_TYPE_KEY_PAIR = 2, +}; + +/** + * @brief 枚举状态返回码。 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_ErrorCode { + /** 成功。 */ + OH_HUKS_SUCCESS = 0, + /** 失败。 */ + OH_HUKS_FAILURE = -1, + /** 不好的状态。 */ + OH_HUKS_ERROR_BAD_STATE = -2, + /** 无效的参数。 */ + OH_HUKS_ERROR_INVALID_ARGUMENT = -3, + /** 不支持。 */ + OH_HUKS_ERROR_NOT_SUPPORTED = -4, + /** 没有权限。 */ + OH_HUKS_ERROR_NO_PERMISSION = -5, + /** 数据大小不足。 */ + OH_HUKS_ERROR_INSUFFICIENT_DATA = -6, + /** 缓存区过小。 */ + OH_HUKS_ERROR_BUFFER_TOO_SMALL = -7, + /** 内存不足。 */ + OH_HUKS_ERROR_INSUFFICIENT_MEMORY = -8, + /** 通信失败。 */ + OH_HUKS_ERROR_COMMUNICATION_FAILURE = -9, + /** 存储区出错。 */ + OH_HUKS_ERROR_STORAGE_FAILURE = -10, + /** 硬件出错。 */ + OH_HUKS_ERROR_HARDWARE_FAILURE = -11, + /** 已存在。 */ + OH_HUKS_ERROR_ALREADY_EXISTS = -12, + /** 不存在。 */ + OH_HUKS_ERROR_NOT_EXIST = -13, + /** 空指针。 */ + OH_HUKS_ERROR_NULL_POINTER = -14, + /** 获取到的文件大小失败。 */ + OH_HUKS_ERROR_FILE_SIZE_FAIL = -15, + /** 读文件失败。 */ + OH_HUKS_ERROR_READ_FILE_FAIL = -16, + /** 无效的公钥。 */ + OH_HUKS_ERROR_INVALID_PUBLIC_KEY = -17, + /** 无效的私钥。 */ + OH_HUKS_ERROR_INVALID_PRIVATE_KEY = -18, + /** 无效的密钥数据。 */ + OH_HUKS_ERROR_INVALID_KEY_INFO = -19, + /** 哈希值不相同。 */ + OH_HUKS_ERROR_HASH_NOT_EQUAL = -20, + /** 创建内存失败。 */ + OH_HUKS_ERROR_MALLOC_FAIL = -21, + /** 写文件失败。 */ + OH_HUKS_ERROR_WRITE_FILE_FAIL = -22, + /** 删除文件失败。 */ + OH_HUKS_ERROR_REMOVE_FILE_FAIL = -23, + /** 打开文件失败。 */ + OH_HUKS_ERROR_OPEN_FILE_FAIL = -24, + /** 关闭文件失败。 */ + OH_HUKS_ERROR_CLOSE_FILE_FAIL = -25, + /** 创建目录失败。 */ + OH_HUKS_ERROR_MAKE_DIR_FAIL = -26, + /** 无效的密钥文件。 */ + OH_HUKS_ERROR_INVALID_KEY_FILE = -27, + /** 进程间通信失败。 */ + OH_HUKS_ERROR_IPC_MSG_FAIL = -28, + /** 请求溢出。 */ + OH_HUKS_ERROR_REQUEST_OVERFLOWS = -29, + /** 参数不存在。 */ + OH_HUKS_ERROR_PARAM_NOT_EXIST = -30, + /** 引擎侧失败。 */ + OH_HUKS_ERROR_CRYPTO_ENGINE_ERROR = -31, + /** 通信超时。 */ + OH_HUKS_ERROR_COMMUNICATION_TIMEOUT = -32, + /** IPC初始化失败。 */ + OH_HUKS_ERROR_IPC_INIT_FAIL = -33, + /** IPC DLOPEN失败。 */ + OH_HUKS_ERROR_IPC_DLOPEN_FAIL = -34, + /** 溢出读数据报错。 */ + OH_HUKS_ERROR_EFUSE_READ_FAIL = -35, + /** 新的root密钥材料已存在。 */ + OH_HUKS_ERROR_NEW_ROOT_KEY_MATERIAL_EXIST = -36, + /** 更新root密钥材料失败。 */ + OH_HUKS_ERROR_UPDATE_ROOT_KEY_MATERIAL_FAIL = -37, + /** 验证失败。 */ + OH_HUKS_ERROR_VERIFICATION_FAILED = -38, + /** 会话数已达到极限。 */ + OH_HUKS_ERROR_SESSION_REACHED_LIMIT = -39, + + /** 获取算法参数失败。 */ + OH_HUKS_ERROR_CHECK_GET_ALG_FAIL = -100, + /** 获取密钥大小失败。 */ + OH_HUKS_ERROR_CHECK_GET_KEY_SIZE_FAIL = -101, + /** 获取填充方式失败。 */ + OH_HUKS_ERROR_CHECK_GET_PADDING_FAIL = -102, + /** 获取用途失败。 */ + OH_HUKS_ERROR_CHECK_GET_PURPOSE_FAIL = -103, + /** 获取摘要算法失败。 */ + OH_HUKS_ERROR_CHECK_GET_DIGEST_FAIL = -104, + /** 获取工作模式失败。 */ + OH_HUKS_ERROR_CHECK_GET_MODE_FAIL = -105, + /** 获取nonce值失败。 */ + OH_HUKS_ERROR_CHECK_GET_NONCE_FAIL = -106, + /** 获取认证数据失败。 */ + OH_HUKS_ERROR_CHECK_GET_AAD_FAIL = -107, + /** 获取IV值失败。 */ + OH_HUKS_ERROR_CHECK_GET_IV_FAIL = -108, + /** 获取AE标签值失败。 */ + OH_HUKS_ERROR_CHECK_GET_AE_TAG_FAIL = -109, + /** 获取盐值失败。 */ + OH_HUKS_ERROR_CHECK_GET_SALT_FAIL = -110, + /** 获取迭代值失败。 */ + OH_HUKS_ERROR_CHECK_GET_ITERATION_FAIL = -111, + /** 无效的算法。 */ + OH_HUKS_ERROR_INVALID_ALGORITHM = -112, + /** 无效的密钥长度。 */ + OH_HUKS_ERROR_INVALID_KEY_SIZE = -113, + /** 无效的填充方式。 */ + OH_HUKS_ERROR_INVALID_PADDING = -114, + /** 无效的用途。 */ + OH_HUKS_ERROR_INVALID_PURPOSE = -115, + /** 无效的工作模式。 */ + OH_HUKS_ERROR_INVALID_MODE = -116, + /** 无效的摘要算法。 */ + OH_HUKS_ERROR_INVALID_DIGEST = -117, + /** 无效的签名数据大小。 */ + OH_HUKS_ERROR_INVALID_SIGNATURE_SIZE = -118, + /** 无效的IV值。 */ + OH_HUKS_ERROR_INVALID_IV = -119, + /** 无效的AAD数据。 */ + OH_HUKS_ERROR_INVALID_AAD = -120, + /** 无效的NONCE值。 */ + OH_HUKS_ERROR_INVALID_NONCE = -121, + /** 无效的AE标签值。 */ + OH_HUKS_ERROR_INVALID_AE_TAG = -122, + /** 无效的盐值。 */ + OH_HUKS_ERROR_INVALID_SALT = -123, + /** 无效的迭代值。 */ + OH_HUKS_ERROR_INVALID_ITERATION = -124, + /** 无效的操作。 */ + OH_HUKS_ERROR_INVALID_OPERATION = -125, + /** 无效的数据包装格式。 */ + OH_HUKS_ERROR_INVALID_WRAPPED_FORMAT = -126, + /** 无效的密钥使用。 */ + OH_HUKS_ERROR_INVALID_USAGE_OF_KEY = -127, + + /** 内部出错。 */ + OH_HUKS_ERROR_INTERNAL_ERROR = -999, + /** 未知出错。 */ + OH_HUKS_ERROR_UNKNOWN_ERROR = -1000, +}; + +/** + * @brief 枚举标签类型。 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_TagType { + /** 无效类型。 */ + OH_HUKS_TAG_TYPE_INVALID = 0 << 28, + /** int类型。 */ + OH_HUKS_TAG_TYPE_INT = 1 << 28, + /** uint类型。 */ + OH_HUKS_TAG_TYPE_UINT = 2 << 28, + /** ulong类型。 */ + OH_HUKS_TAG_TYPE_ULONG = 3 << 28, + /** bool类型。 */ + OH_HUKS_TAG_TYPE_BOOL = 4 << 28, + /** bytes类型。 */ + OH_HUKS_TAG_TYPE_BYTES = 5 << 28, +}; + +/** + * @brief 枚举发送消息的方式 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_SendType { + /** 异步。 */ + OH_HUKS_SEND_TYPE_ASYNC = 0, + /** 同步。 */ + OH_HUKS_SEND_TYPE_SYNC, +}; + +/** + * @brief 枚举标签值。 + * + * @since 8 + * @version 1.0 + */ +enum OH_Huks_Tag { + /** 无效标签值。 */ + OH_HUKS_TAG_INVALID = OH_HUKS_TAG_TYPE_INVALID | 0, + + /** 基础算法中用到的标签值是从1到200。 */ + /** 算法类型。 */ + OH_HUKS_TAG_ALGORITHM = OH_HUKS_TAG_TYPE_UINT | 1, + /** 用途。 */ + OH_HUKS_TAG_PURPOSE = OH_HUKS_TAG_TYPE_UINT | 2, + /** 密钥长度 。 */ + OH_HUKS_TAG_KEY_SIZE = OH_HUKS_TAG_TYPE_UINT | 3, + /** 摘要算法。 */ + OH_HUKS_TAG_DIGEST = OH_HUKS_TAG_TYPE_UINT | 4, + /** 填充方式。 */ + OH_HUKS_TAG_PADDING = OH_HUKS_TAG_TYPE_UINT | 5, + /** 工作模式。 */ + OH_HUKS_TAG_BLOCK_MODE = OH_HUKS_TAG_TYPE_UINT | 6, + /** 密钥类型。 */ + OH_HUKS_TAG_KEY_TYPE = OH_HUKS_TAG_TYPE_UINT | 7, + /** 认证数据。 */ + OH_HUKS_TAG_ASSOCIATED_DATA = OH_HUKS_TAG_TYPE_BYTES | 8, + /** NONCE值。 */ + OH_HUKS_TAG_NONCE = OH_HUKS_TAG_TYPE_BYTES | 9, + /** IV矢量。 */ + OH_HUKS_TAG_IV = OH_HUKS_TAG_TYPE_BYTES | 10, + + /** 用于密钥派生的标签值。 */ + /** 派生信息。 */ + OH_HUKS_TAG_INFO = OH_HUKS_TAG_TYPE_BYTES | 11, + /** 派生盐值。 */ + OH_HUKS_TAG_SALT = OH_HUKS_TAG_TYPE_BYTES | 12, + /** 派生密码。 */ + OH_HUKS_TAG_PWD = OH_HUKS_TAG_TYPE_BYTES | 13, + /** 派生迭代数。 */ + OH_HUKS_TAG_ITERATION = OH_HUKS_TAG_TYPE_UINT | 14, + + /** 生成密钥的类型,类型可在枚举OH_Huks_KeyGenerateType中选择。 */ + OH_HUKS_TAG_KEY_GENERATE_TYPE = OH_HUKS_TAG_TYPE_UINT | 15, + /** 派生main密钥。 */ + OH_HUKS_TAG_DERIVE_MAIN_KEY = OH_HUKS_TAG_TYPE_BYTES | 16, + /** 派生因素。 */ + OH_HUKS_TAG_DERIVE_FACTOR = OH_HUKS_TAG_TYPE_BYTES | 17, + /** 派生算法。 */ + OH_HUKS_TAG_DERIVE_ALG = OH_HUKS_TAG_TYPE_UINT | 18, + /** 协商算法。 */ + OH_HUKS_TAG_AGREE_ALG = OH_HUKS_TAG_TYPE_UINT | 19, + /** 是否带有用于协商的公钥。 */ + OH_HUKS_TAG_AGREE_PUBLIC_KEY_IS_KEY_ALIAS = OH_HUKS_TAG_TYPE_BOOL | 20, + /** 用于协商的私钥别名。 */ + OH_HUKS_TAG_AGREE_PRIVATE_KEY_ALIAS = OH_HUKS_TAG_TYPE_BYTES | 21, + /** 用于协商的公钥。 */ + OH_HUKS_TAG_AGREE_PUBLIC_KEY = OH_HUKS_TAG_TYPE_BYTES | 22, + /** 密钥别名。 */ + OH_HUKS_TAG_KEY_ALIAS = OH_HUKS_TAG_TYPE_BYTES | 23, + /** 派生密钥大小。 */ + OH_HUKS_TAG_DERIVE_KEY_SIZE = OH_HUKS_TAG_TYPE_UINT | 24, + /** 导入密钥类型, 类型可在枚举OH_Huks_ImportKeyType中选择。 */ + OH_HUKS_TAG_IMPORT_KEY_TYPE = OH_HUKS_TAG_TYPE_UINT | 25, + /** 解包套件算法。 */ + OH_HUKS_TAG_UNWRAP_ALGORITHM_SUITE = OH_HUKS_TAG_TYPE_UINT | 26, + + /** + * Key authentication related TAG: 201 - 300 + * + * Start of validity + */ + /** 密钥认证需要用到的标签值从201到300。 */ + /** 活跃时间。 */ + OH_HUKS_TAG_ACTIVE_DATETIME = OH_HUKS_TAG_TYPE_ULONG | 201, + + /** Date when new "messages" should not be created. */ + /** 发放过期日期。 */ + OH_HUKS_TAG_ORIGINATION_EXPIRE_DATETIME = OH_HUKS_TAG_TYPE_ULONG | 202, + + /** Date when existing "messages" should not be used. */ + /** 使用过期日期。 */ + OH_HUKS_TAG_USAGE_EXPIRE_DATETIME = OH_HUKS_TAG_TYPE_ULONG | 203, + + /** 密钥创建的时间。 */ + OH_HUKS_TAG_CREATION_DATETIME = OH_HUKS_TAG_TYPE_ULONG | 204, + + /** Other authentication related TAG: 301 - 500 */ + /** 所有使用者。 */ + OH_HUKS_TAG_ALL_USERS = OH_HUKS_TAG_TYPE_BOOL | 301, + /** 用户ID。 */ + OH_HUKS_TAG_USER_ID = OH_HUKS_TAG_TYPE_UINT | 302, + /** 无认证请求。 */ + OH_HUKS_TAG_NO_AUTH_REQUIRED = OH_HUKS_TAG_TYPE_BOOL | 303, + /** 用户认证类型。 */ + OH_HUKS_TAG_USER_AUTH_TYPE = OH_HUKS_TAG_TYPE_UINT | 304, + /** 认证超时。 */ + OH_HUKS_TAG_AUTH_TIMEOUT = OH_HUKS_TAG_TYPE_UINT | 305, + /** 认证token。 */ + OH_HUKS_TAG_AUTH_TOKEN = OH_HUKS_TAG_TYPE_BYTES | 306, + + /** Attestation related TAG: 501 - 600 */ + /** 挑战值。 */ + OH_HUKS_TAG_ATTESTATION_CHALLENGE = OH_HUKS_TAG_TYPE_BYTES | 501, + /** 应用ID。 */ + OH_HUKS_TAG_ATTESTATION_APPLICATION_ID = OH_HUKS_TAG_TYPE_BYTES | 502, + /** 商标名。 */ + OH_HUKS_TAG_ATTESTATION_ID_BRAND = OH_HUKS_TAG_TYPE_BYTES | 503, + /** 设备名。 */ + OH_HUKS_TAG_ATTESTATION_ID_DEVICE = OH_HUKS_TAG_TYPE_BYTES | 504, + /** 产品名。 */ + OH_HUKS_TAG_ATTESTATION_ID_PRODUCT = OH_HUKS_TAG_TYPE_BYTES | 505, + /** 序号。 */ + OH_HUKS_TAG_ATTESTATION_ID_SERIAL = OH_HUKS_TAG_TYPE_BYTES | 506, + /** IMEI。 */ + OH_HUKS_TAG_ATTESTATION_ID_IMEI = OH_HUKS_TAG_TYPE_BYTES | 507, + /** MEID。 */ + OH_HUKS_TAG_ATTESTATION_ID_MEID = OH_HUKS_TAG_TYPE_BYTES | 508, + /** 生产商。 */ + OH_HUKS_TAG_ATTESTATION_ID_MANUFACTURER = OH_HUKS_TAG_TYPE_BYTES | 509, + /** 模型。 */ + OH_HUKS_TAG_ATTESTATION_ID_MODEL = OH_HUKS_TAG_TYPE_BYTES | 510, + /** 别名。 */ + OH_HUKS_TAG_ATTESTATION_ID_ALIAS = OH_HUKS_TAG_TYPE_BYTES | 511, + /** SOCID。 */ + OH_HUKS_TAG_ATTESTATION_ID_SOCID = OH_HUKS_TAG_TYPE_BYTES | 512, + /** UDID。 */ + OH_HUKS_TAG_ATTESTATION_ID_UDID = OH_HUKS_TAG_TYPE_BYTES | 513, + /** 安全等级信息。 */ + OH_HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO = OH_HUKS_TAG_TYPE_BYTES | 514, + /** 版本信息。 */ + OH_HUKS_TAG_ATTESTATION_ID_VERSION_INFO = OH_HUKS_TAG_TYPE_BYTES | 515, + + /** + * Other reserved TAG: 601 - 1000 + * + * Extention TAG: 1001 - 9999 + */ + /** 是否密钥别名。 */ + OH_HUKS_TAG_IS_KEY_ALIAS = OH_HUKS_TAG_TYPE_BOOL | 1001, + /** 密钥存储标记, 类型可在枚举OH_Huks_KeyStorageType选择。 */ + OH_HUKS_TAG_KEY_STORAGE_FLAG = OH_HUKS_TAG_TYPE_UINT | 1002, + /** 是否运行打包数据。 */ + OH_HUKS_TAG_IS_ALLOWED_WRAP = OH_HUKS_TAG_TYPE_BOOL | 1003, + /** 打包数据类型。 */ + OH_HUKS_TAG_KEY_WRAP_TYPE = OH_HUKS_TAG_TYPE_UINT | 1004, + /** 密钥认证ID。 */ + OH_HUKS_TAG_KEY_AUTH_ID = OH_HUKS_TAG_TYPE_BYTES | 1005, + /** 密钥作用。 */ + OH_HUKS_TAG_KEY_ROLE = OH_HUKS_TAG_TYPE_UINT | 1006, + /** 密钥标记, , 类型可在枚举OH_Huks_KeyFlag选择。 */ + OH_HUKS_TAG_KEY_FLAG = OH_HUKS_TAG_TYPE_UINT | 1007, + /** 是否异步。 */ + OH_HUKS_TAG_IS_ASYNCHRONIZED = OH_HUKS_TAG_TYPE_UINT | 1008, + /** 安全密钥别名。 */ + OH_HUKS_TAG_SECURE_KEY_ALIAS = OH_HUKS_TAG_TYPE_BOOL | 1009, + /** 安全密钥UUID。 */ + OH_HUKS_TAG_SECURE_KEY_UUID = OH_HUKS_TAG_TYPE_BYTES | 1010, + /** 密钥领域。 */ + OH_HUKS_TAG_KEY_DOMAIN = OH_HUKS_TAG_TYPE_UINT | 1011, + + /** huks内部使用的标签值是从10001到10999 */ + /** 进程名。 */ + OH_HUKS_TAG_PROCESS_NAME = OH_HUKS_TAG_TYPE_BYTES | 10001, + /** 数据包名。 */ + OH_HUKS_TAG_PACKAGE_NAME = OH_HUKS_TAG_TYPE_BYTES | 10002, + /** 访问时间。 */ + OH_HUKS_TAG_ACCESS_TIME = OH_HUKS_TAG_TYPE_UINT | 10003, + /** 使用时间。 */ + OH_HUKS_TAG_USES_TIME = OH_HUKS_TAG_TYPE_UINT | 10004, + /** 密码算法的CTX。 */ + OH_HUKS_TAG_CRYPTO_CTX = OH_HUKS_TAG_TYPE_ULONG | 10005, + /** 密钥数据。 */ + OH_HUKS_TAG_KEY = OH_HUKS_TAG_TYPE_BYTES | 10006, + /** 密钥数据的版本。 */ + OH_HUKS_TAG_KEY_VERSION = OH_HUKS_TAG_TYPE_UINT | 10007, + /** 负荷数据的长度。 */ + OH_HUKS_TAG_PAYLOAD_LEN = OH_HUKS_TAG_TYPE_UINT | 10008, + /** AEAD。 */ + OH_HUKS_TAG_AE_TAG = OH_HUKS_TAG_TYPE_BYTES | 10009, + /** 是否密钥的handle值。 */ + OH_HUKS_TAG_IS_KEY_HANDLE = OH_HUKS_TAG_TYPE_ULONG | 10010, + + /** os版本。 */ + OH_HUKS_TAG_OS_VERSION = OH_HUKS_TAG_TYPE_UINT | 10101, + /** os补丁等级。 */ + OH_HUKS_TAG_OS_PATCHLEVEL = OH_HUKS_TAG_TYPE_UINT | 10102, + + /** + * Reversed TAGs for SOTER: 11000 - 12000 + * + * Other TAGs: 20001 - N + * TAGs used for paramSetOut + */ + /** 对称密钥数据 */ + OH_HUKS_TAG_SYMMETRIC_KEY_DATA = OH_HUKS_TAG_TYPE_BYTES | 20001, + /** 非对称公钥数据。 */ + OH_HUKS_TAG_ASYMMETRIC_PUBLIC_KEY_DATA = OH_HUKS_TAG_TYPE_BYTES | 20002, + /** 非对称私钥数据。 */ + OH_HUKS_TAG_ASYMMETRIC_PRIVATE_KEY_DATA = OH_HUKS_TAG_TYPE_BYTES | 20003, +}; + +/** + * @brief 定义存放数据的结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_Blob { + /** 数据大小 */ + uint32_t size; + /** 指向数据内存的指针 */ + uint8_t *data; +}; + +/** + * @brief 定义参数集中的参数结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_Param { + /** 标签值 */ + uint32_t tag; +/** + * @brief 定义参数联合体。 + * + * @since 8 + * @version 1.0 + */ + union { + /** bool型参数。 */ + bool boolParam; + /** int32_t型参数。 */ + int32_t int32Param; + /** uint32_t型参数。 */ + uint32_t uint32Param; + /** uint64_t型参数。 */ + uint64_t uint64Param; + /** struct OH_Huks_Blob型参数。 */ + struct OH_Huks_Blob blob; + }; +}; + +/** + * @brief 定义参数集的结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_ParamSet { + /** 参数集的内存大小。 */ + uint32_t paramSetSize; + /** 参数的个数。*/ + uint32_t paramsCnt; + /** 参数数组。*/ + struct OH_Huks_Param params[]; +}; + +/** + * @brief 定义证书链的结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_CertChain { + /** 指向证书数据的指针。 */ + struct OH_Huks_Blob *certs; + /** 证书本数。 */ + uint32_t certsCount; +}; + +/** + * @brief 定义密钥信息的结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_KeyInfo { + /** 密钥的别名。 */ + struct OH_Huks_Blob alias; + /** 指向密钥参数集的指针。 */ + struct OH_Huks_ParamSet *paramSet; +}; + +/** + * @brief 定义公钥信息的结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_PubKeyInfo { + /** 公钥的算法类型。 */ + enum OH_Huks_KeyAlg keyAlg; + /** 公钥的长度。 */ + uint32_t keySize; + /** n或X值的长度。 */ + uint32_t nOrXSize; + /** e或Y值的长度。 */ + uint32_t eOrYSize; + /** 占位符大小。 */ + uint32_t placeHolder; +}; + +/** + * @brief 定义Rsa密钥的结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_KeyMaterialRsa { + /** 密钥的算法类型。 */ + enum OH_Huks_KeyAlg keyAlg; + /** 密钥的长度。 */ + uint32_t keySize; + /** n值的长度。 */ + uint32_t nSize; + /** e值的长度。 */ + uint32_t eSize; + /** d值的长度。 */ + uint32_t dSize; +}; + +/** + * @brief 定义Ecc密钥的结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_KeyMaterialEcc { + /** 密钥的算法类型。 */ + enum OH_Huks_KeyAlg keyAlg; + /** 密钥的长度。 */ + uint32_t keySize; + /** x值的长度。 */ + uint32_t xSize; + /** y值的长度。 */ + uint32_t ySize; + /** z值的长度。 */ + uint32_t zSize; +}; + +/** + * @brief 定义Dsa密钥的结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_KeyMaterialDsa { + /** 密钥的算法类型。 */ + enum OH_Huks_KeyAlg keyAlg; + /** 密钥的长度。 */ + uint32_t keySize; + /** x值的长度。 */ + uint32_t xSize; + /** y值的长度。 */ + uint32_t ySize; + /** p值的长度。 */ + uint32_t pSize; + /** q值的长度。 */ + uint32_t qSize; + /** g值的长度。 */ + uint32_t gSize; +}; + +/** + * @brief 定义Dh密钥的结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_KeyMaterialDh { + /** 密钥的算法类型。 */ + enum OH_Huks_KeyAlg keyAlg; + /** Dh密钥的长度。 */ + uint32_t keySize; + /** 公钥的长度。 */ + uint32_t pubKeySize; + /** 私钥的长度。 */ + uint32_t priKeySize; + /** 保留。 */ + uint32_t reserved; +}; + +/** + * @brief 定义25519类型密钥的结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_KeyMaterial25519 { + /** 密钥的算法类型。 */ + enum OH_Huks_KeyAlg keyAlg; + /** 25519类型密钥的长度。 */ + uint32_t keySize; + /** 公钥的长度。 */ + uint32_t pubKeySize; + /** 私钥的长度。 */ + uint32_t priKeySize; + /** 保留。 */ + uint32_t reserved; +}; + +#define OH_HUKS_DERIVE_DEFAULT_SALT_LEN 16 +#define OH_HUKS_HMAC_DIGEST_SHA512_LEN 64 +#define OH_HUKS_DEFAULT_RANDOM_LEN 16 +#define OH_HUKS_MAX_KEY_AUTH_ID_LEN 64 +#define OH_HUKS_KEY_MATERIAL_NUM 3 +#define OH_HUKS_MAX_KEY_LEN ((((4096) + OH_HUKS_BITS_PER_BYTE - 1) / OH_HUKS_BITS_PER_BYTE) * OH_HUKS_KEY_MATERIAL_NUM) +#define OH_HUKS_MAX_KEY_MATERIAL_LEN (sizeof(struct OH_Huks_PubKeyInfo) + OH_HUKS_MAX_KEY_LEN + OH_HUKS_AE_TAG_LEN) + +/** + * @brief 定义存储区头部信息的结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_StoreHeaderInfo { + /** 版本号。 */ + uint16_t version; + /** 存储的密钥数量。 */ + uint16_t keyCount; + /** 存储的密钥总的内存大小。 */ + uint32_t totalLen; + /** 存储的密封算法。 */ + uint32_t sealingAlg; + /** 存储的盐值。 */ + uint8_t salt[OH_HUKS_DERIVE_DEFAULT_SALT_LEN]; + /** 存储的hmac摘要值。 */ + uint8_t hmac[OH_HUKS_HMAC_DIGEST_SHA512_LEN]; +}; + +/** + * @brief 定义存储密钥的信息的结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_StoreKeyInfo { + /** 当前密钥信息的内存大小。 */ + uint16_t keyInfoLen; + /** 加密后的密钥长度。 */ + uint16_t keySize; + /** 密钥的随机值。 */ + uint8_t random[OH_HUKS_DEFAULT_RANDOM_LEN]; + /** 标记是导入的密钥还是业务生成的密钥。 */ + uint8_t flag; /* import or generate key */ + /** 密钥算法类型。 */ + uint8_t keyAlg; + /** 密钥工作模式。 */ + uint8_t keyMode; + /** 摘要算法。 */ + uint8_t digest; + /** 数据填充方式。 */ + uint8_t padding; + /** 保留。 */ + uint8_t rsv; + /** 密钥长度,该值来源于输入参数集。 */ + uint16_t keyLen; + /** 用途。 */ + uint32_t purpose; + /** 作用。*/ + uint32_t role; + /** 领域值。 */ + uint16_t domain; + /** 密钥别名数据的长度。 */ + uint8_t aliasSize; + /** 认证id的数据长度。 */ + uint8_t authIdSize; +}; + +/** + * @brief 定义25519类型算法协商密钥对的结构体类型。 + * + * @since 8 + * @version 1.0 + */ +struct OH_Huks_25519KeyPair { + /** 公钥占用内存的大小 */ + uint32_t publicBufferSize; + /** 私钥占用内存的大小 */ + uint32_t privateBufferSize; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* NATIVE_OH_HUKS_TYPE_H */ diff --git a/zh-cn/native_sdk/security/huks/native_huks_type_inner.h b/zh-cn/native_sdk/security/huks/native_huks_type_inner.h new file mode 100644 index 00000000..9a0b8b5d --- /dev/null +++ b/zh-cn/native_sdk/security/huks/native_huks_type_inner.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file native_huks_type_inner.h + * + * @brief 提供huks内部需要使用的头文件。 + * + * @since 8 + * @version 1.0 + */ + +#ifndef NATIVE_HUKS_TYPE_INNER_H +#define NATIVE_HUKS_TYPE_INNER_H + +#include "native_huks_type.h" +#include "securec.h" + +#endif /* NATIVE_HUKS_TYPE_INNER_H */ \ No newline at end of file -- Gitee From 82e7f621804c4f4ffca9078d900ab24c36e72b2a Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Tue, 2 Aug 2022 10:11:47 +0800 Subject: [PATCH 03/17] since 8 -> since 9 Signed-off-by: zqr2001 <1805768383@qq.com> --- .../security/huks/native_huks_api.h | 26 ++++---- .../security/huks/native_huks_param.h | 22 +++---- .../security/huks/native_huks_type.h | 64 +++++++++---------- .../security/huks/native_huks_type_inner.h | 2 +- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_api.h b/zh-cn/native_sdk/security/huks/native_huks_api.h index cde82d8e..c25538ae 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_api.h +++ b/zh-cn/native_sdk/security/huks/native_huks_api.h @@ -20,7 +20,7 @@ * @brief 描述huks向应用提供密钥库能力,包括密钥管理及密钥的密码学操作等功能。 * 管理的密钥可以由应用导入或者由应用调用HUKS接口生成。 * - * @since 8 + * @since 9 * @version 1.0 */ @@ -29,7 +29,7 @@ * * @brief 声明用于访问huks的API。 * - * @since 8 + * @since 9 * @version 1.0 */ @@ -47,7 +47,7 @@ extern "C" { * * @param sdkVersion 用于存储获取到的版本信息。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_GetSdkVersion(struct OH_Huks_Blob *sdkVersion); @@ -59,7 +59,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_GetSdkVersion(struct OH_Huks_Blob *sdkVersion * @param paramSetIn 表示生成密钥需要的输入参数集。 * @param paramSetOut 生成密钥为临时类型时存放着密钥数据;非临时类型可为空。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_GenerateKey(const struct OH_Huks_Blob *keyAlias, @@ -72,7 +72,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_GenerateKey(const struct OH_Huks_Blob *keyAli * @param paramSet 表示导入密钥需要的输入参数集。 * @param key 表示导入的密钥数据。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_ImportKey(const struct OH_Huks_Blob *keyAlias, @@ -85,7 +85,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_ImportKey(const struct OH_Huks_Blob *keyAlias * @param paramSet 表示导出公钥需要的输入参数集。 * @param key 表示要导入的密钥数据。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_ExportPublicKey(const struct OH_Huks_Blob *keyAlias, @@ -97,7 +97,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_ExportPublicKey(const struct OH_Huks_Blob *ke * @param keyAlias 表示要删除密钥的别名。 * @param paramSet 表示要删除密钥需要的输入参数集。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_DeleteKey(const struct OH_Huks_Blob *keyAlias, @@ -110,7 +110,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_DeleteKey(const struct OH_Huks_Blob *keyAlias * @param paramSetIn 表示要获取参数集需要的输入参数集。 * @param paramSetOut 表示获取到的输出参数集。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_GetKeyParamSet(const struct OH_Huks_Blob *keyAlias, @@ -122,7 +122,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_GetKeyParamSet(const struct OH_Huks_Blob *key * @param keyAlias 表示密钥别名。 * @param paramSet 表示查询需要的输入参数集。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_KeyExist(const struct OH_Huks_Blob *keyAlias, @@ -135,7 +135,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_KeyExist(const struct OH_Huks_Blob *keyAlias, * @param paramSet 表示init需要的输入参数集。 * @param handle 表示使init、update、finish和abort联系起来的输出特征值。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_Init(const struct OH_Huks_Blob *keyAlias, @@ -149,7 +149,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_Init(const struct OH_Huks_Blob *keyAlias, * @param inData 表示要处理的输入数据,如果数据过大,可分片多次调用update。 * @param outData 表示经过算法操作处理后的输出数据。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_Update(const struct OH_Huks_Blob *handle, @@ -163,7 +163,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_Update(const struct OH_Huks_Blob *handle, * @param inData 表示要处理的输入数据。 * @param outData 表示经过算法操作处理后的输出数据。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_Finish(const struct OH_Huks_Blob *handle, @@ -175,7 +175,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_Finish(const struct OH_Huks_Blob *handle, * @param handle 表示使init、update、finish和abort联系起来的输入特征值。 * @param paramSet 表示abort需要的输入参数集。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_Abort(const struct OH_Huks_Blob *handle, diff --git a/zh-cn/native_sdk/security/huks/native_huks_param.h b/zh-cn/native_sdk/security/huks/native_huks_param.h index 5da98b19..9b85660d 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_param.h +++ b/zh-cn/native_sdk/security/huks/native_huks_param.h @@ -18,7 +18,7 @@ * * @brief 提供参数集构造、使用和销毁的API。 * - * @since 8 + * @since 9 * @version 1.0 */ @@ -41,7 +41,7 @@ extern "C" { * * @param paramSet 表示指向要初始化的参数集的指针。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_InitParamSet(struct OH_Huks_ParamSet **paramSet); @@ -53,7 +53,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_InitParamSet(struct OH_Huks_ParamSet **paramS * @param params 表示指向要添加的参数的指针。 * @param paramCnt 表示要添加参数的个数。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_AddParams(struct OH_Huks_ParamSet *paramSet, @@ -64,7 +64,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_AddParams(struct OH_Huks_ParamSet *paramSet, * * @param paramSet 表示指向要被正式构造的参数集的指针。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_BuildParamSet(struct OH_Huks_ParamSet **paramSet); @@ -73,7 +73,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_BuildParamSet(struct OH_Huks_ParamSet **param * @brief 销毁参数集。 * * @param paramSet 表示指向要被销毁的参数集的指针。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT void OH_Huks_FreeParamSet(struct OH_Huks_ParamSet **paramSet); @@ -85,7 +85,7 @@ OH_HUKS_API_EXPORT void OH_Huks_FreeParamSet(struct OH_Huks_ParamSet **paramSet) * @param fromParamSetSize 表示被复制的参数集占用内存的大小。 * @param paramSet 表示指向生成新的参数集的指针。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_GetParamSet(const struct OH_Huks_ParamSet *fromParamSet, @@ -98,7 +98,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_GetParamSet(const struct OH_Huks_ParamSet *fr * @param tag 表示要获取的参数对应的特征值。 * @param param 表示指向获取到的参数的指针。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_GetParam(const struct OH_Huks_ParamSet *paramSet, uint32_t tag, @@ -110,7 +110,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_GetParam(const struct OH_Huks_ParamSet *param * @param paramSet 表示指向参数集的指针。 * @param isCopy 表示是否要刷新参数集内存中的struct HksBlob型的参数数据。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_FreshParamSet(struct OH_Huks_ParamSet *paramSet, bool isCopy); @@ -120,7 +120,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_FreshParamSet(struct OH_Huks_ParamSet *paramS * * @param paramSet 表示指向参数集的指针。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ int32_t OH_Huks_CheckParamSetTag(const struct OH_Huks_ParamSet *paramSet); @@ -131,7 +131,7 @@ int32_t OH_Huks_CheckParamSetTag(const struct OH_Huks_ParamSet *paramSet); * @param paramSet 表示指向参数集的指针。 * @param size 表示参数集占用的内存大小。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ int32_t OH_Huks_CheckParamSet(const struct OH_Huks_ParamSet *paramSet, uint32_t size); @@ -142,7 +142,7 @@ int32_t OH_Huks_CheckParamSet(const struct OH_Huks_ParamSet *paramSet, uint32_t * @param baseParam 表示指向被比较的参数的指针。 * @param param 表示指向比较的参数的指针。 * @return 返回执行的状态代码。 - * @since 8 + * @since 9 * @version 1.0 */ int32_t OH_Huks_CheckParamMatch(const struct OH_Huks_Param *baseParam, const struct OH_Huks_Param *param); diff --git a/zh-cn/native_sdk/security/huks/native_huks_type.h b/zh-cn/native_sdk/security/huks/native_huks_type.h index 0d0550f7..4d130758 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_type.h +++ b/zh-cn/native_sdk/security/huks/native_huks_type.h @@ -18,7 +18,7 @@ * * @brief 提供huks中的枚举变量、结构体定义与宏定义。 * - * @since 8 + * @since 9 * @version 1.0 */ @@ -51,7 +51,7 @@ extern "C" { * * Before calling this function, ensure that the size does not overflow after 3 is added. * - * @since 8 + * @since 9 * @version 1.0 */ #define OH_HUKS_DEFAULT_ALIGN_MASK_SIZE 3 @@ -72,7 +72,7 @@ extern "C" { /** * @brief 枚举密钥用途。 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_KeyPurpose { @@ -99,7 +99,7 @@ enum OH_Huks_KeyPurpose { /** * @brief 枚举摘要算法类型。 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_KeyDigest { @@ -124,7 +124,7 @@ enum OH_Huks_KeyDigest { /** * @brief 枚举数据填充方式。 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_KeyPadding { @@ -145,7 +145,7 @@ enum OH_Huks_KeyPadding { /** * @brief 枚举加密工作模式。 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_CipherMode { @@ -166,7 +166,7 @@ enum OH_Huks_CipherMode { /** * @brief 枚举不同算法支持的密钥长度。 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_KeySize { @@ -207,7 +207,7 @@ enum OH_Huks_KeySize { /** * @brief 枚举支持的算法类型。 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_KeyAlg { @@ -243,7 +243,7 @@ enum OH_Huks_KeyAlg { /** * @brief 枚举解包套件的算法类型 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_AlgSuite { @@ -272,7 +272,7 @@ enum OH_Huks_AlgSuite { /** * @brief 枚举生成的密钥类型。 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_KeyGenerateType { @@ -287,7 +287,7 @@ enum OH_Huks_KeyGenerateType { /** * @brief 枚举密钥的标记类型。 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_KeyFlag { @@ -304,7 +304,7 @@ enum OH_Huks_KeyFlag { /** * @brief 枚举密钥的存储类型。 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_KeyStorageType { @@ -317,7 +317,7 @@ enum OH_Huks_KeyStorageType { /** * @brief 枚举导入密钥的类型。 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_ImportKeyType { @@ -332,7 +332,7 @@ enum OH_Huks_ImportKeyType { /** * @brief 枚举状态返回码。 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_ErrorCode { @@ -483,7 +483,7 @@ enum OH_Huks_ErrorCode { /** * @brief 枚举标签类型。 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_TagType { @@ -504,7 +504,7 @@ enum OH_Huks_TagType { /** * @brief 枚举发送消息的方式 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_SendType { @@ -517,7 +517,7 @@ enum OH_Huks_SendType { /** * @brief 枚举标签值。 * - * @since 8 + * @since 9 * @version 1.0 */ enum OH_Huks_Tag { @@ -719,7 +719,7 @@ enum OH_Huks_Tag { /** * @brief 定义存放数据的结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_Blob { @@ -732,7 +732,7 @@ struct OH_Huks_Blob { /** * @brief 定义参数集中的参数结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_Param { @@ -741,7 +741,7 @@ struct OH_Huks_Param { /** * @brief 定义参数联合体。 * - * @since 8 + * @since 9 * @version 1.0 */ union { @@ -761,7 +761,7 @@ struct OH_Huks_Param { /** * @brief 定义参数集的结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_ParamSet { @@ -776,7 +776,7 @@ struct OH_Huks_ParamSet { /** * @brief 定义证书链的结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_CertChain { @@ -789,7 +789,7 @@ struct OH_Huks_CertChain { /** * @brief 定义密钥信息的结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_KeyInfo { @@ -802,7 +802,7 @@ struct OH_Huks_KeyInfo { /** * @brief 定义公钥信息的结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_PubKeyInfo { @@ -821,7 +821,7 @@ struct OH_Huks_PubKeyInfo { /** * @brief 定义Rsa密钥的结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_KeyMaterialRsa { @@ -840,7 +840,7 @@ struct OH_Huks_KeyMaterialRsa { /** * @brief 定义Ecc密钥的结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_KeyMaterialEcc { @@ -859,7 +859,7 @@ struct OH_Huks_KeyMaterialEcc { /** * @brief 定义Dsa密钥的结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_KeyMaterialDsa { @@ -882,7 +882,7 @@ struct OH_Huks_KeyMaterialDsa { /** * @brief 定义Dh密钥的结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_KeyMaterialDh { @@ -901,7 +901,7 @@ struct OH_Huks_KeyMaterialDh { /** * @brief 定义25519类型密钥的结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_KeyMaterial25519 { @@ -928,7 +928,7 @@ struct OH_Huks_KeyMaterial25519 { /** * @brief 定义存储区头部信息的结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_StoreHeaderInfo { @@ -949,7 +949,7 @@ struct OH_Huks_StoreHeaderInfo { /** * @brief 定义存储密钥的信息的结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_StoreKeyInfo { @@ -988,7 +988,7 @@ struct OH_Huks_StoreKeyInfo { /** * @brief 定义25519类型算法协商密钥对的结构体类型。 * - * @since 8 + * @since 9 * @version 1.0 */ struct OH_Huks_25519KeyPair { diff --git a/zh-cn/native_sdk/security/huks/native_huks_type_inner.h b/zh-cn/native_sdk/security/huks/native_huks_type_inner.h index 9a0b8b5d..315fe6ae 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_type_inner.h +++ b/zh-cn/native_sdk/security/huks/native_huks_type_inner.h @@ -18,7 +18,7 @@ * * @brief 提供huks内部需要使用的头文件。 * - * @since 8 + * @since 9 * @version 1.0 */ -- Gitee From 1c35d07ac129fd5ffd603525fde6d7dc36f004e4 Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Tue, 2 Aug 2022 16:17:08 +0800 Subject: [PATCH 04/17] =?UTF-8?q?GetParamSet=20->=20CopyParamSet=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=B3=E8=81=94=E5=87=BD=E6=95=B0=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zqr2001 <1805768383@qq.com> --- zh-cn/native_sdk/security/huks/native_huks_api.h | 11 +++++++++++ .../native_sdk/security/huks/native_huks_param.h | 15 +++++++++++++-- .../security/huks/native_huks_type_inner.h | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_api.h b/zh-cn/native_sdk/security/huks/native_huks_api.h index c25538ae..7a3ce8cf 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_api.h +++ b/zh-cn/native_sdk/security/huks/native_huks_api.h @@ -31,6 +31,17 @@ * * @since 9 * @version 1.0 + * + * @vee OH_Huks_GetSdkVersion + * @vee OH_Huks_GenerateKey + * @vee OH_Huks_ImportKey + * @vee OH_Huks_ExportPublicKey + * @vee OH_Huks_DeleteKey + * @vee OH_Huks_GetKeyParamSet + * @vee OH_Huks_KeyExist + * @vee OH_Huks_Init + * @vee OH_Huks_Update + * @vee OH_Huks_Abort */ #ifndef _NATIVE_HUKS_API_H_ diff --git a/zh-cn/native_sdk/security/huks/native_huks_param.h b/zh-cn/native_sdk/security/huks/native_huks_param.h index 9b85660d..749141b7 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_param.h +++ b/zh-cn/native_sdk/security/huks/native_huks_param.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,6 +20,17 @@ * * @since 9 * @version 1.0 + * + * @vee OH_Huks_InitParamSet + * @vee OH_Huks_AddParams + * @vee OH_Huks_BuildParamSet + * @vee OH_Huks_FreeParamSet + * @vee OH_Huks_CopyParamSet + * @vee OH_Huks_GetParam + * @vee OH_Huks_FreshParamSet + * @vee OH_Huks_CheckParamSetTag + * @vee OH_Huks_CheckParamSet + * @vee OH_Huks_CheckParamMatch */ #ifndef NATIVE_HUKS_PARAM_H @@ -88,7 +99,7 @@ OH_HUKS_API_EXPORT void OH_Huks_FreeParamSet(struct OH_Huks_ParamSet **paramSet) * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_GetParamSet(const struct OH_Huks_ParamSet *fromParamSet, +OH_HUKS_API_EXPORT int32_t OH_Huks_CopyParamSet(const struct OH_Huks_ParamSet *fromParamSet, uint32_t fromParamSetSize, struct OH_Huks_ParamSet **paramSet); /** diff --git a/zh-cn/native_sdk/security/huks/native_huks_type_inner.h b/zh-cn/native_sdk/security/huks/native_huks_type_inner.h index 315fe6ae..7bcaabe0 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_type_inner.h +++ b/zh-cn/native_sdk/security/huks/native_huks_type_inner.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From 350e0838e1c476b1e043eaf6b524043b9d02dc31 Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Tue, 2 Aug 2022 16:25:02 +0800 Subject: [PATCH 05/17] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zqr2001 <1805768383@qq.com> --- zh-cn/native_sdk/security/huks/native_huks_api.h | 2 +- zh-cn/native_sdk/security/huks/native_huks_param.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_api.h b/zh-cn/native_sdk/security/huks/native_huks_api.h index 7a3ce8cf..48e38594 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_api.h +++ b/zh-cn/native_sdk/security/huks/native_huks_api.h @@ -31,7 +31,7 @@ * * @since 9 * @version 1.0 - * + * * @vee OH_Huks_GetSdkVersion * @vee OH_Huks_GenerateKey * @vee OH_Huks_ImportKey diff --git a/zh-cn/native_sdk/security/huks/native_huks_param.h b/zh-cn/native_sdk/security/huks/native_huks_param.h index 749141b7..2f4929b1 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_param.h +++ b/zh-cn/native_sdk/security/huks/native_huks_param.h @@ -20,7 +20,7 @@ * * @since 9 * @version 1.0 - * + * * @vee OH_Huks_InitParamSet * @vee OH_Huks_AddParams * @vee OH_Huks_BuildParamSet -- Gitee From 5c6bfd36636dbb0339ecb781d13bd8a3476ab4e5 Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Tue, 2 Aug 2022 08:19:47 +0000 Subject: [PATCH 06/17] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20zh?= =?UTF-8?q?-cn/native=5Fsdk/security/huks/native=5Fhuks=5Ftype=5Finner.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zqr2001 <1805768383@qq.com> --- .../security/huks/native_huks_type_inner.h | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 zh-cn/native_sdk/security/huks/native_huks_type_inner.h diff --git a/zh-cn/native_sdk/security/huks/native_huks_type_inner.h b/zh-cn/native_sdk/security/huks/native_huks_type_inner.h deleted file mode 100644 index 7bcaabe0..00000000 --- a/zh-cn/native_sdk/security/huks/native_huks_type_inner.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file native_huks_type_inner.h - * - * @brief 提供huks内部需要使用的头文件。 - * - * @since 9 - * @version 1.0 - */ - -#ifndef NATIVE_HUKS_TYPE_INNER_H -#define NATIVE_HUKS_TYPE_INNER_H - -#include "native_huks_type.h" -#include "securec.h" - -#endif /* NATIVE_HUKS_TYPE_INNER_H */ \ No newline at end of file -- Gitee From 8e892ab7fbabdfac7fea15a07f424b99159c11f7 Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Tue, 2 Aug 2022 10:00:00 +0000 Subject: [PATCH 07/17] Signed-off-by: zqr2001 <1805768383@qq.com> --- zh-cn/native_sdk/security/huks/native_huks_api.h | 4 ++-- zh-cn/native_sdk/security/huks/native_huks_param.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_api.h b/zh-cn/native_sdk/security/huks/native_huks_api.h index 48e38594..aee13a9d 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_api.h +++ b/zh-cn/native_sdk/security/huks/native_huks_api.h @@ -38,7 +38,7 @@ * @vee OH_Huks_ExportPublicKey * @vee OH_Huks_DeleteKey * @vee OH_Huks_GetKeyParamSet - * @vee OH_Huks_KeyExist + * @vee OH_Huks_isKeyExist * @vee OH_Huks_Init * @vee OH_Huks_Update * @vee OH_Huks_Abort @@ -136,7 +136,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_GetKeyParamSet(const struct OH_Huks_Blob *key * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_KeyExist(const struct OH_Huks_Blob *keyAlias, +OH_HUKS_API_EXPORT int32_t OH_Huks_isKeyExist(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *paramSet); /** diff --git a/zh-cn/native_sdk/security/huks/native_huks_param.h b/zh-cn/native_sdk/security/huks/native_huks_param.h index 2f4929b1..0e11caab 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_param.h +++ b/zh-cn/native_sdk/security/huks/native_huks_param.h @@ -28,8 +28,8 @@ * @vee OH_Huks_CopyParamSet * @vee OH_Huks_GetParam * @vee OH_Huks_FreshParamSet - * @vee OH_Huks_CheckParamSetTag - * @vee OH_Huks_CheckParamSet + * @vee OH_Huks_isParamSetTagValid + * @vee OH_Huks_isParamSetValid * @vee OH_Huks_CheckParamMatch */ @@ -134,7 +134,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_FreshParamSet(struct OH_Huks_ParamSet *paramS * @since 9 * @version 1.0 */ -int32_t OH_Huks_CheckParamSetTag(const struct OH_Huks_ParamSet *paramSet); +int32_t OH_Huks_isParamSetTagValid(const struct OH_Huks_ParamSet *paramSet); /** * @brief 检查参数集是否有效。 @@ -145,7 +145,7 @@ int32_t OH_Huks_CheckParamSetTag(const struct OH_Huks_ParamSet *paramSet); * @since 9 * @version 1.0 */ -int32_t OH_Huks_CheckParamSet(const struct OH_Huks_ParamSet *paramSet, uint32_t size); +int32_t OH_Huks_isParamSetValid(const struct OH_Huks_ParamSet *paramSet, uint32_t size); /** * @brief 比较两个参数是否相同 -- Gitee From 4852b382ce184b756fdf0e2d97283fe3698fb773 Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Wed, 3 Aug 2022 10:07:55 +0800 Subject: [PATCH 08/17] agree -> negotiation Signed-off-by: zqr2001 <1805768383@qq.com> --- zh-cn/native_sdk/security/huks/native_huks_type.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_type.h b/zh-cn/native_sdk/security/huks/native_huks_type.h index 4d130758..2951185a 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_type.h +++ b/zh-cn/native_sdk/security/huks/native_huks_type.h @@ -281,7 +281,7 @@ enum OH_Huks_KeyGenerateType { /** 派生类型。 */ OH_HUKS_KEY_GENERATE_TYPE_DERIVE = 1, /** 协商类型。 */ - OH_HUKS_KEY_GENERATE_TYPE_AGREE = 2, + OH_HUKS_KEY_GENERATE_TYPE_NEGOTIATION = 2, }; /** @@ -296,7 +296,7 @@ enum OH_Huks_KeyFlag { /** 生成密钥的标记。*/ OH_HUKS_KEY_FLAG_GENERATE_KEY = 2, /** 协商密钥的标记。*/ - OH_HUKS_KEY_FLAG_AGREE_KEY = 3, + OH_HUKS_KEY_FLAG_NEGOTIATION_KEY = 3, /** 派生密钥的标记。*/ OH_HUKS_KEY_FLAG_DERIVE_KEY = 4, }; -- Gitee From 38b75e71cb38445eb53458a60b011cf5e329905f Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Wed, 3 Aug 2022 11:41:17 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E5=8E=BB=E9=99=A4iccarm=E5=92=8Cversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zqr2001 <1805768383@qq.com> --- .../native_sdk/security/huks/native_huks_type.h | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_type.h b/zh-cn/native_sdk/security/huks/native_huks_type.h index 2951185a..5677c5d9 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_type.h +++ b/zh-cn/native_sdk/security/huks/native_huks_type.h @@ -33,19 +33,6 @@ extern "C" { #endif -#ifndef OH_HUKS_API_PUBLIC - #if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(__ICCARM__) /* __ICCARM__ for iar */ - #define OH_HUKS_API_EXPORT - #else - #define OH_HUKS_API_EXPORT __attribute__ ((visibility("default"))) - #endif -#else - #define OH_HUKS_API_EXPORT __attribute__ ((visibility("default"))) -#endif - -#define OH_HUKS_SDK_VERSION "2.0.0.4" - - /** * @brief Align to 4-tuple。 * @@ -281,7 +268,7 @@ enum OH_Huks_KeyGenerateType { /** 派生类型。 */ OH_HUKS_KEY_GENERATE_TYPE_DERIVE = 1, /** 协商类型。 */ - OH_HUKS_KEY_GENERATE_TYPE_NEGOTIATION = 2, + OH_HUKS_KEY_GENERATE_TYPE_AGREE = 2, }; /** @@ -296,7 +283,7 @@ enum OH_Huks_KeyFlag { /** 生成密钥的标记。*/ OH_HUKS_KEY_FLAG_GENERATE_KEY = 2, /** 协商密钥的标记。*/ - OH_HUKS_KEY_FLAG_NEGOTIATION_KEY = 3, + OH_HUKS_KEY_FLAG_AGREE_KEY = 3, /** 派生密钥的标记。*/ OH_HUKS_KEY_FLAG_DERIVE_KEY = 4, }; -- Gitee From 66bd3123a225ab5817feadcfe3df1f1450513c57 Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Wed, 3 Aug 2022 14:46:03 +0800 Subject: [PATCH 10/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zqr2001 <1805768383@qq.com> --- .../security/huks/native_huks_type.h | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_type.h b/zh-cn/native_sdk/security/huks/native_huks_type.h index 5677c5d9..0f54c503 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_type.h +++ b/zh-cn/native_sdk/security/huks/native_huks_type.h @@ -46,7 +46,6 @@ extern "C" { #define OH_HUKS_AE_TAG_LEN 16 #define OH_HUKS_BITS_PER_BYTE 8 #define OH_HUKS_MAX_KEY_SIZE 2048 -#define OH_HUKS_AE_TAG_LEN 16 #define OH_HUKS_AE_NONCE_LEN 12 #define OH_HUKS_MAX_KEY_ALIAS_LEN 64 #define OH_HUKS_MAX_PROCESS_NAME_LEN 50 @@ -327,35 +326,35 @@ enum OH_Huks_ErrorCode { OH_HUKS_SUCCESS = 0, /** 失败。 */ OH_HUKS_FAILURE = -1, - /** 不好的状态。 */ + /** 错误的状态。 */ OH_HUKS_ERROR_BAD_STATE = -2, - /** 无效的参数。 */ + /** 无效的数据。 */ OH_HUKS_ERROR_INVALID_ARGUMENT = -3, /** 不支持。 */ OH_HUKS_ERROR_NOT_SUPPORTED = -4, - /** 没有权限。 */ + /** 没有许可。 */ OH_HUKS_ERROR_NO_PERMISSION = -5, - /** 数据大小不足。 */ + /** 数据空间大小不足。 */ OH_HUKS_ERROR_INSUFFICIENT_DATA = -6, /** 缓存区过小。 */ OH_HUKS_ERROR_BUFFER_TOO_SMALL = -7, /** 内存不足。 */ OH_HUKS_ERROR_INSUFFICIENT_MEMORY = -8, - /** 通信失败。 */ + /** 通讯失败。 */ OH_HUKS_ERROR_COMMUNICATION_FAILURE = -9, - /** 存储区出错。 */ + /** 存储故障。 */ OH_HUKS_ERROR_STORAGE_FAILURE = -10, - /** 硬件出错。 */ + /** 硬件故障。 */ OH_HUKS_ERROR_HARDWARE_FAILURE = -11, - /** 已存在。 */ + /** 已经存在。 */ OH_HUKS_ERROR_ALREADY_EXISTS = -12, /** 不存在。 */ OH_HUKS_ERROR_NOT_EXIST = -13, /** 空指针。 */ OH_HUKS_ERROR_NULL_POINTER = -14, - /** 获取到的文件大小失败。 */ + /** 文件大小失败。 */ OH_HUKS_ERROR_FILE_SIZE_FAIL = -15, - /** 读文件失败。 */ + /** 读取文件失败。 */ OH_HUKS_ERROR_READ_FILE_FAIL = -16, /** 无效的公钥。 */ OH_HUKS_ERROR_INVALID_PUBLIC_KEY = -17, @@ -363,9 +362,9 @@ enum OH_Huks_ErrorCode { OH_HUKS_ERROR_INVALID_PRIVATE_KEY = -18, /** 无效的密钥数据。 */ OH_HUKS_ERROR_INVALID_KEY_INFO = -19, - /** 哈希值不相同。 */ + /** 哈希值不相等。 */ OH_HUKS_ERROR_HASH_NOT_EQUAL = -20, - /** 创建内存失败。 */ + /** MALLOC失败。 */ OH_HUKS_ERROR_MALLOC_FAIL = -21, /** 写文件失败。 */ OH_HUKS_ERROR_WRITE_FILE_FAIL = -22, @@ -379,27 +378,27 @@ enum OH_Huks_ErrorCode { OH_HUKS_ERROR_MAKE_DIR_FAIL = -26, /** 无效的密钥文件。 */ OH_HUKS_ERROR_INVALID_KEY_FILE = -27, - /** 进程间通信失败。 */ + /** IPC信息失败。 */ OH_HUKS_ERROR_IPC_MSG_FAIL = -28, /** 请求溢出。 */ OH_HUKS_ERROR_REQUEST_OVERFLOWS = -29, /** 参数不存在。 */ OH_HUKS_ERROR_PARAM_NOT_EXIST = -30, - /** 引擎侧失败。 */ + /** CRYPTO ENGINE错误。 */ OH_HUKS_ERROR_CRYPTO_ENGINE_ERROR = -31, - /** 通信超时。 */ + /** 通讯超时。 */ OH_HUKS_ERROR_COMMUNICATION_TIMEOUT = -32, /** IPC初始化失败。 */ OH_HUKS_ERROR_IPC_INIT_FAIL = -33, /** IPC DLOPEN失败。 */ OH_HUKS_ERROR_IPC_DLOPEN_FAIL = -34, - /** 溢出读数据报错。 */ + /** EFUSE 读取失败。 */ OH_HUKS_ERROR_EFUSE_READ_FAIL = -35, - /** 新的root密钥材料已存在。 */ + /** 新的根密钥材料已存在。 */ OH_HUKS_ERROR_NEW_ROOT_KEY_MATERIAL_EXIST = -36, - /** 更新root密钥材料失败。 */ + /** 更新根密钥材料失败。 */ OH_HUKS_ERROR_UPDATE_ROOT_KEY_MATERIAL_FAIL = -37, - /** 验证失败。 */ + /** 验证证书链失败。 */ OH_HUKS_ERROR_VERIFICATION_FAILED = -38, /** 会话数已达到极限。 */ OH_HUKS_ERROR_SESSION_REACHED_LIMIT = -39, -- Gitee From 8c93b48df9b09248bab87071ea29c24771a18265 Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Wed, 3 Aug 2022 16:04:15 +0800 Subject: [PATCH 11/17] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=8E=A7=E5=88=B6tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zqr2001 <1805768383@qq.com> --- .../security/huks/native_huks_api.h | 2 +- .../security/huks/native_huks_type.h | 217 ++++++++++++------ 2 files changed, 148 insertions(+), 71 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_api.h b/zh-cn/native_sdk/security/huks/native_huks_api.h index aee13a9d..a14d1f08 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_api.h +++ b/zh-cn/native_sdk/security/huks/native_huks_api.h @@ -150,7 +150,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_isKeyExist(const struct OH_Huks_Blob *keyAlia * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_Init(const struct OH_Huks_Blob *keyAlias, - const struct OH_Huks_ParamSet *paramSet, struct OH_Huks_Blob *handle); + const struct OH_Huks_ParamSet *paramSet, struct OH_Huks_Blob *handle, struct HksBlob *token); /** * @brief 使用密钥对数据进行算法操作的update动作。 diff --git a/zh-cn/native_sdk/security/huks/native_huks_type.h b/zh-cn/native_sdk/security/huks/native_huks_type.h index 0f54c503..48ecbc1f 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_type.h +++ b/zh-cn/native_sdk/security/huks/native_huks_type.h @@ -54,6 +54,11 @@ extern "C" { #define OH_HUKS_MAX_OUT_BLOB_SIZE (5 * 1024 * 1024) #define OH_HUKS_WRAPPED_FORMAT_MAX_SIZE (1024 * 1024) #define OH_HUKS_IMPORT_WRAPPED_KEY_TOTAL_BLOBS 10 +#define TOKEN_CHALLENGE_LEN 32 +#define SHA256_SIGN_LEN 32 +#define TOKEN_SIZE 32 +#define MAX_AUTH_TIMEOUT_SECOND 60 +#define SECURE_SIGN_VERSION 0x01000001 /** * @brief 枚举密钥用途。 @@ -156,37 +161,50 @@ enum OH_Huks_CipherMode { * @version 1.0 */ enum OH_Huks_KeySize { - /** RSA算法支持的密钥长度为1024位。 */ + /** 使用RSA算法的密钥长度为512bit。 */ + OH_HUKS_RSA_KEY_SIZE_512 = 512, + /** 使用RSA算法的密钥长度为768bit。 */ + OH_HUKS_RSA_KEY_SIZE_768 = 768, + /** 使用RSA算法的密钥长度为1024bit。 */ OH_HUKS_RSA_KEY_SIZE_1024 = 1024, - /** RSA算法支持的密钥长度为2048位。 */ + /** 使用RSA算法的密钥长度为2048bit。 */ OH_HUKS_RSA_KEY_SIZE_2048 = 2048, - /** RSA算法支持的密钥长度为3072位。 */ + /** 使用RSA算法的密钥长度为3072bit。 */ OH_HUKS_RSA_KEY_SIZE_3072 = 3072, - /** RSA算法支持的密钥长度为4096位。 */ + /** 使用RSA算法的密钥长度为4096bit。 */ OH_HUKS_RSA_KEY_SIZE_4096 = 4096, - - /** ECC算法支持的密钥长度为256位。 */ + + /** 使用ECC算法的密钥长度为224bit。 */ + OH_HUKS_ECC_KEY_SIZE_224 = 224, + /** 使用ECC算法的密钥长度为256bit。 */ OH_HUKS_ECC_KEY_SIZE_256 = 256, - /** ECC算法支持的密钥长度为384位。 */ + /** 使用ECC算法的密钥长度为384bit。 */ OH_HUKS_ECC_KEY_SIZE_384 = 384, - /** ECC算法支持的密钥长度为521位。 */ + /** 使用ECC算法的密钥长度为521bit。 */ OH_HUKS_ECC_KEY_SIZE_521 = 521, - /** AES算法支持的密钥长度为128位。 */ + /** 使用AES算法的密钥长度为128bit。 */ OH_HUKS_AES_KEY_SIZE_128 = 128, - /** AES算法支持的密钥长度为192位。 */ + /** 使用AES算法的密钥长度为192bit。 */ OH_HUKS_AES_KEY_SIZE_192 = 192, - /** AES算法支持的密钥长度为256位。 */ + /** 使用AES算法的密钥长度为256bit。 */ OH_HUKS_AES_KEY_SIZE_256 = 256, - /** AES算法支持的密钥长度为512位。 */ + /** 使用AES算法的密钥长度为512bit。 */ OH_HUKS_AES_KEY_SIZE_512 = 512, - /** CURVE25519算法支持的密钥长度为256位。 */ + /** 使用CURVE25519算法的密钥长度为256bit。 */ OH_HUKS_CURVE25519_KEY_SIZE_256 = 256, - /** SM2算法支持的密钥长度为256位。 */ + /** 使用DH算法的密钥长度为2048bit。 */ + OH_HUKS_DH_KEY_SIZE_2048 = 2048, + /** 使用DH算法的密钥长度为3072bit。 */ + OH_HUKS_DH_KEY_SIZE_3072 = 3072, + /** 使用DH算法的密钥长度为4096bit。 */ + OH_HUKS_DH_KEY_SIZE_4096 = 4096, + + /** 使用SM2算法的密钥长度为256bit。 */ OH_HUKS_SM2_KEY_SIZE_256 = 256, - /** SM4算法支持的密钥长度为128位。 */ + /** 使用SM4算法支持的密钥长度为128位。 */ OH_HUKS_SM4_KEY_SIZE_128 = 128, }; @@ -197,10 +215,12 @@ enum OH_Huks_KeySize { * @version 1.0 */ enum OH_Huks_KeyAlg { - /** 非对称密钥算法RSA。 */ + /** 使用RSA算法。 */ OH_HUKS_ALG_RSA = 1, - /** 非对称密钥算法ECC。 */ + /** 使用ECC算法。 */ OH_HUKS_ALG_ECC = 2, + /** 使用DSA算法。 */ + OH_HUKS_ALG_DSA = 3, /** 对称密钥算法AES。 */ OH_HUKS_ALG_AES = 20, @@ -217,6 +237,8 @@ enum OH_Huks_KeyAlg { OH_HUKS_ALG_X25519 = 101, /** 签名验签算法ED25519。 */ OH_HUKS_ALG_ED25519 = 102, + /** 使用DH算法。 */ + OH_HUKS_ALG_DH = 103, /** 国密算法SM2。*/ OH_HUKS_ALG_SM2 = 150, @@ -402,67 +424,77 @@ enum OH_Huks_ErrorCode { OH_HUKS_ERROR_VERIFICATION_FAILED = -38, /** 会话数已达到极限。 */ OH_HUKS_ERROR_SESSION_REACHED_LIMIT = -39, + /** 获取当前用户安全属性信息失败。 */ + OH_HUKS_ERROR_GET_USERIAM_SECINFO_FAILED = -40, + /** 获取当前用户认证信息失败。 */ + OH_HUKS_ERROR_GET_USERIAM_AUTHINFO_FAILED = -41, + /** 不支持当前用户认证类型的访问控制。 */ + OH_HUKS_ERROR_USER_AUTH_TYPE_NOT_SUPPORT = -42, + /** 安全访问控制认证失败。 */ + OH_HUKS_ERROR_KEY_AUTH_FAILED = -43, + /** 设备当前未录入凭据。 */ + OH_HUKS_ERROR_DEVICE_NO_CREDENTIAL = -44, - /** 获取算法参数失败。 */ + /** 检查获取ALG失败。 */ OH_HUKS_ERROR_CHECK_GET_ALG_FAIL = -100, - /** 获取密钥大小失败。 */ + /** 检查获取密钥大小失败。 */ OH_HUKS_ERROR_CHECK_GET_KEY_SIZE_FAIL = -101, - /** 获取填充方式失败。 */ + /** 检查获取填充失败。 */ OH_HUKS_ERROR_CHECK_GET_PADDING_FAIL = -102, - /** 获取用途失败。 */ + /** 检查获取目的失败。 */ OH_HUKS_ERROR_CHECK_GET_PURPOSE_FAIL = -103, - /** 获取摘要算法失败。 */ + /** 检查获取摘要失败。 */ OH_HUKS_ERROR_CHECK_GET_DIGEST_FAIL = -104, - /** 获取工作模式失败。 */ + /** 检查获取模式失败。 */ OH_HUKS_ERROR_CHECK_GET_MODE_FAIL = -105, - /** 获取nonce值失败。 */ + /** 检查获取随机数失败。 */ OH_HUKS_ERROR_CHECK_GET_NONCE_FAIL = -106, - /** 获取认证数据失败。 */ + /** 检查获取AAD失败。 */ OH_HUKS_ERROR_CHECK_GET_AAD_FAIL = -107, - /** 获取IV值失败。 */ + /** 检查获取IV值失败。 */ OH_HUKS_ERROR_CHECK_GET_IV_FAIL = -108, - /** 获取AE标签值失败。 */ + /** 检查获取AE标记失败。 */ OH_HUKS_ERROR_CHECK_GET_AE_TAG_FAIL = -109, - /** 获取盐值失败。 */ + /** 检查获取SALT失败。 */ OH_HUKS_ERROR_CHECK_GET_SALT_FAIL = -110, - /** 获取迭代值失败。 */ + /** 检查获取迭代失败。 */ OH_HUKS_ERROR_CHECK_GET_ITERATION_FAIL = -111, /** 无效的算法。 */ OH_HUKS_ERROR_INVALID_ALGORITHM = -112, /** 无效的密钥长度。 */ OH_HUKS_ERROR_INVALID_KEY_SIZE = -113, - /** 无效的填充方式。 */ + /** 无效的填充。 */ OH_HUKS_ERROR_INVALID_PADDING = -114, - /** 无效的用途。 */ + /** 无效的目的。 */ OH_HUKS_ERROR_INVALID_PURPOSE = -115, - /** 无效的工作模式。 */ + /** 无效的模式。 */ OH_HUKS_ERROR_INVALID_MODE = -116, - /** 无效的摘要算法。 */ + /** 无效的摘要。 */ OH_HUKS_ERROR_INVALID_DIGEST = -117, - /** 无效的签名数据大小。 */ + /** 无效的签名大小。 */ OH_HUKS_ERROR_INVALID_SIGNATURE_SIZE = -118, /** 无效的IV值。 */ OH_HUKS_ERROR_INVALID_IV = -119, - /** 无效的AAD数据。 */ + /** 无效的AAD。 */ OH_HUKS_ERROR_INVALID_AAD = -120, - /** 无效的NONCE值。 */ + /** 无效的随机数。 */ OH_HUKS_ERROR_INVALID_NONCE = -121, - /** 无效的AE标签值。 */ + /** 无效的AE标签。 */ OH_HUKS_ERROR_INVALID_AE_TAG = -122, - /** 无效的盐值。 */ + /** 无效的SALT。 */ OH_HUKS_ERROR_INVALID_SALT = -123, - /** 无效的迭代值。 */ + /** 无效的迭代。 */ OH_HUKS_ERROR_INVALID_ITERATION = -124, /** 无效的操作。 */ OH_HUKS_ERROR_INVALID_OPERATION = -125, - /** 无效的数据包装格式。 */ + /** 导入加密密钥时,密钥格式错误。 */ OH_HUKS_ERROR_INVALID_WRAPPED_FORMAT = -126, - /** 无效的密钥使用。 */ + /** 导入加密密钥时,密钥用途错误。 */ OH_HUKS_ERROR_INVALID_USAGE_OF_KEY = -127, - /** 内部出错。 */ + /** 内部错误。 */ OH_HUKS_ERROR_INTERNAL_ERROR = -999, - /** 未知出错。 */ + /** 未知错误。 */ OH_HUKS_ERROR_UNKNOWN_ERROR = -1000, }; @@ -500,6 +532,78 @@ enum OH_Huks_SendType { OH_HUKS_SEND_TYPE_SYNC, }; + +/** + * @brief 用户认证类型 + * + * @since 9 + * @version 1.0 + */ +enum OH_Huks_UserAuthType { + /** 用户认证类型为指纹。 */ + OH_HUKS_USER_AUTH_TYPE_FINGERPRINT = 1 << 0, + /** 用户认证类型为人脸。 */ + OH_HUKS_USER_AUTH_TYPE_FACE = 1 << 1, + /** 用户认证类型为PIN码。 */ + OH_HUKS_USER_AUTH_TYPE_PIN = 1 << 2, +}; + +/** + * @brief 安全访问控制类型 + * + * @since 9 + * @version 1.0 + */ +enum OH_Huks_AuthAccessType { + /** 安全访问控制类型为清除密码后密钥无效。 */ + OH_HUKS_AUTH_ACCESS_INVALID_CLEAR_PASSWORD = 1 << 0, + /** 安全访问控制类型为新录入生物特征后密钥无效。 */ + OH_HUKS_AUTH_ACCESS_INVALID_NEW_BIO_ENROLL = 1 << 1, +}; + +/** + * @brief 密钥使用时生成challenge的类型 + * + * @since 9 + * @version 1.0 + */ +enum OH_Huks_ChallengeType { + /** challenge为普通类型,默认32字节。 */ + OH_HUKS_CHALLENGE_TYPE_NORMAL = 0, + /** challenge为用户自定义类型。支持使用多个密钥仅一次认证。 */ + OH_HUKS_CHALLENGE_TYPE_CUSTOM = 1, + /** 免challenge类型。 */ + OH_HUKS_CHALLENGE_TYPE_NONE = 2, +}; + +/** + * @brief challenge类型为用户自定义类型时,生成的challenge有效长度仅为8字节连续的数据,且仅支持4种位置。 + * + * @since 9 + * @version 1.0 + */ +enum OH_Huks_ChallengePosition { + /** 0~7字节为当前密钥的有效challenge。 */ + OH_HUKS_CHALLENGE_POS_0 = 0, + /** 8~15字节为当前密钥的有效challenge。 */ + OH_HUKS_CHALLENGE_POS_1, + /** 16~23字节为当前密钥的有效challenge。 */ + OH_HUKS_CHALLENGE_POS_2, + /** 24~31字节为当前密钥的有效challenge。 */ + OH_HUKS_CHALLENGE_POS_3, +}; + +/** + * @brief 生成或导入密钥时,指定该密钥的签名类型。 + * + * @since 9 + * @version 1.0 + */ +enum OH_Huks_SecureSignType { + /** 签名类型为携带认证信息。生成或导入密钥时指定该字段,则在使用密钥进行签名时,对待签名的数据添加认证信息后进行签名。 */ + OH_HUKS_SECURE_SIGN_WITH_AUTHINFO = 1, +}; + /** * @brief 枚举标签值。 * @@ -661,33 +765,6 @@ enum OH_Huks_Tag { /** 密钥领域。 */ OH_HUKS_TAG_KEY_DOMAIN = OH_HUKS_TAG_TYPE_UINT | 1011, - /** huks内部使用的标签值是从10001到10999 */ - /** 进程名。 */ - OH_HUKS_TAG_PROCESS_NAME = OH_HUKS_TAG_TYPE_BYTES | 10001, - /** 数据包名。 */ - OH_HUKS_TAG_PACKAGE_NAME = OH_HUKS_TAG_TYPE_BYTES | 10002, - /** 访问时间。 */ - OH_HUKS_TAG_ACCESS_TIME = OH_HUKS_TAG_TYPE_UINT | 10003, - /** 使用时间。 */ - OH_HUKS_TAG_USES_TIME = OH_HUKS_TAG_TYPE_UINT | 10004, - /** 密码算法的CTX。 */ - OH_HUKS_TAG_CRYPTO_CTX = OH_HUKS_TAG_TYPE_ULONG | 10005, - /** 密钥数据。 */ - OH_HUKS_TAG_KEY = OH_HUKS_TAG_TYPE_BYTES | 10006, - /** 密钥数据的版本。 */ - OH_HUKS_TAG_KEY_VERSION = OH_HUKS_TAG_TYPE_UINT | 10007, - /** 负荷数据的长度。 */ - OH_HUKS_TAG_PAYLOAD_LEN = OH_HUKS_TAG_TYPE_UINT | 10008, - /** AEAD。 */ - OH_HUKS_TAG_AE_TAG = OH_HUKS_TAG_TYPE_BYTES | 10009, - /** 是否密钥的handle值。 */ - OH_HUKS_TAG_IS_KEY_HANDLE = OH_HUKS_TAG_TYPE_ULONG | 10010, - - /** os版本。 */ - OH_HUKS_TAG_OS_VERSION = OH_HUKS_TAG_TYPE_UINT | 10101, - /** os补丁等级。 */ - OH_HUKS_TAG_OS_PATCHLEVEL = OH_HUKS_TAG_TYPE_UINT | 10102, - /** * Reversed TAGs for SOTER: 11000 - 12000 * -- Gitee From 3bef323b9669cb45c6d4d549d6f18782b03d4ba4 Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Wed, 3 Aug 2022 16:35:36 +0800 Subject: [PATCH 12/17] =?UTF-8?q?native=5Fhuks=5Fapi.h=20=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zqr2001 <1805768383@qq.com> --- .../security/huks/native_huks_api.h | 86 +++++++++++-------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_api.h b/zh-cn/native_sdk/security/huks/native_huks_api.h index a14d1f08..a12066c6 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_api.h +++ b/zh-cn/native_sdk/security/huks/native_huks_api.h @@ -54,10 +54,10 @@ extern "C" { #endif /** - * @brief 获取huks的版本信息。 + * @brief 获取当前系统sdk版本。 * * @param sdkVersion 用于存储获取到的版本信息。 - * @return 返回执行的状态代码。 + * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 * @since 9 * @version 1.0 */ @@ -66,10 +66,10 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_GetSdkVersion(struct OH_Huks_Blob *sdkVersion /** * @brief 生成密钥。 * - * @param keyAlias 表示给要生成的密钥取的别名。 - * @param paramSetIn 表示生成密钥需要的输入参数集。 + * @param keyAlias 表示给要生成的密钥的别名。 + * @param paramSetIn 表示生成密钥需要的TAG。 * @param paramSetOut 生成密钥为临时类型时存放着密钥数据;非临时类型可为空。 - * @return 返回执行的状态代码。 + * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 * @since 9 * @version 1.0 */ @@ -77,25 +77,40 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_GenerateKey(const struct OH_Huks_Blob *keyAli const struct OH_Huks_ParamSet *paramSetIn, struct OH_Huks_ParamSet *paramSetOut); /** - * @brief 导入密钥。 + * @brief 导入明文密钥。 * - * @param keyAlias 表示给要导入的密钥取的别名。 - * @param paramSet 表示导入密钥需要的输入参数集。 - * @param key 表示导入的密钥数据。 - * @return 返回执行的状态代码。 + * @param keyAlias 密钥别名,存放待导入密钥的别名。 + * @param paramSet 导入时所需TAG。 + * @param key 需要导入的加密的密钥数据。 + * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 * @since 9 * @version 1.0 */ OH_HUKS_API_EXPORT int32_t OH_Huks_ImportKey(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *key); +/** + * @brief 导入加密密钥。 + * + * @param keyAlias 密钥别名,存放待导入密钥的别名。 + * @param wrappingKeyAlias 密钥别名,对应密钥用于解密加密的密钥数据。表示导入密钥需要的输入参数集。 + * @param paramSet 导入时所需TAG。 + * @param key 需要导入的加密的密钥数据。 + * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 + * @since 9 + * @version 1.0 + */ +OH_HUKS_API_EXPORT int32_t OH_Huks_ImportWrappedKey(const struct OH_Huks_Blob *keyAlias, + const struct OH_Huks_Blob *wrappingKeyAlias, const struct OH_Huks_ParamSet *paramSet, + const struct OH_Huks_Blob *wrappedKeyData); + /** * @brief 导出公钥。 * - * @param keyAlias 表示要导出公钥对应的密钥别名。 - * @param paramSet 表示导出公钥需要的输入参数集。 + * @param keyAlias 表示要导出公钥对应的密钥别名,应与所用密钥生成时使用的别名相同。 + * @param paramSet 导出公钥需要的TAG(此处传空)。 * @param key 表示要导入的密钥数据。 - * @return 返回执行的状态代码。 + * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 * @since 9 * @version 1.0 */ @@ -105,9 +120,9 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_ExportPublicKey(const struct OH_Huks_Blob *ke /** * @brief 删除密钥。 * - * @param keyAlias 表示要删除密钥的别名。 - * @param paramSet 表示要删除密钥需要的输入参数集。 - * @return 返回执行的状态代码。 + * @param keyAlias 表示要删除密钥的别名,应与密钥生成时使用的别名相同。 + * @param paramSet 删除密钥需要的TAG(此处传空)。 + * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 * @since 9 * @version 1.0 */ @@ -115,12 +130,12 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_DeleteKey(const struct OH_Huks_Blob *keyAlias const struct OH_Huks_ParamSet *paramSet); /** - * @brief 获取生成密钥时的参数集。 + * @brief 获取密钥的参数集。 * * @param keyAlias 表示要获取参数集的密钥别名 - * @param paramSetIn 表示要获取参数集需要的输入参数集。 + * @param paramSetIn 表示要获取参数集需要的TAG(此处传空)。 * @param paramSetOut 表示获取到的输出参数集。 - * @return 返回执行的状态代码。 + * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 * @since 9 * @version 1.0 */ @@ -128,11 +143,11 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_GetKeyParamSet(const struct OH_Huks_Blob *key const struct OH_Huks_ParamSet *paramSetIn, struct OH_Huks_ParamSet *paramSetOut); /** - * @brief 查询存储中密钥是否存在。 + * @brief 判断密钥是否存在。 * - * @param keyAlias 表示密钥别名。 - * @param paramSet 表示查询需要的输入参数集。 - * @return 返回执行的状态代码。 + * @param keyAlias 表示要查找的密钥的别名。 + * @param paramSet 表示查询密钥需要的TAG(此处传空)。 + * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 * @since 9 * @version 1.0 */ @@ -140,12 +155,13 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_isKeyExist(const struct OH_Huks_Blob *keyAlia const struct OH_Huks_ParamSet *paramSet); /** - * @brief 使用密钥对数据进行算法操作的init动作。 + * @brief init操作密钥接口。 * - * @param keyAlias 表示使用密钥的别名。 - * @param paramSet 表示init需要的输入参数集。 + * @param keyAlias 表示init操作的密钥的别名。 + * @param paramSet 表示init操作的参数集合。 * @param handle 表示使init、update、finish和abort联系起来的输出特征值。 - * @return 返回执行的状态代码。 + * @param token 存放安全访问控制时传回的challenge + * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 * @since 9 * @version 1.0 */ @@ -153,13 +169,13 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_Init(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *paramSet, struct OH_Huks_Blob *handle, struct HksBlob *token); /** - * @brief 使用密钥对数据进行算法操作的update动作。 + * @brief update操作密钥接口。 * * @param handle 表示使init、update、finish和abort联系起来的输入特征值。 * @param paramSet 表示update需要的输入参数集。 * @param inData 表示要处理的输入数据,如果数据过大,可分片多次调用update。 - * @param outData 表示经过算法操作处理后的输出数据。 - * @return 返回执行的状态代码。 + * @param outData 表示经过update操作后的输出数据。 + * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 * @since 9 * @version 1.0 */ @@ -167,13 +183,13 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_Update(const struct OH_Huks_Blob *handle, const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *outData); /** - * @brief 使用密钥对数据进行算法操作的finish动作。 + * @brief finish操作密钥接口。 * * @param handle 表示使init、update、finish和abort联系起来的输入特征值。 * @param paramSet 表示finish需要的输入参数集。 * @param inData 表示要处理的输入数据。 - * @param outData 表示经过算法操作处理后的输出数据。 - * @return 返回执行的状态代码。 + * @param outData 表示经过finish操作处理后的输出数据。 + * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 * @since 9 * @version 1.0 */ @@ -181,11 +197,11 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_Finish(const struct OH_Huks_Blob *handle, const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *outData); /** - * @brief update、finish异常退出的清理动作。 + * @brief abort操作密钥接口。 * * @param handle 表示使init、update、finish和abort联系起来的输入特征值。 * @param paramSet 表示abort需要的输入参数集。 - * @return 返回执行的状态代码。 + * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 * @since 9 * @version 1.0 */ -- Gitee From 53f674f46a63668a2643d95b215ffa7db449a162 Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Wed, 3 Aug 2022 17:08:42 +0800 Subject: [PATCH 13/17] =?UTF-8?q?native=5Fhuks=5Ftype.h=20=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zqr2001 <1805768383@qq.com> --- .../security/huks/native_huks_api.h | 5 +- .../security/huks/native_huks_type.h | 198 +++++++++--------- 2 files changed, 103 insertions(+), 100 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_api.h b/zh-cn/native_sdk/security/huks/native_huks_api.h index a12066c6..0760ac34 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_api.h +++ b/zh-cn/native_sdk/security/huks/native_huks_api.h @@ -35,6 +35,7 @@ * @vee OH_Huks_GetSdkVersion * @vee OH_Huks_GenerateKey * @vee OH_Huks_ImportKey + * @vee OH_Huks_ImportWrappedKey * @vee OH_Huks_ExportPublicKey * @vee OH_Huks_DeleteKey * @vee OH_Huks_GetKeyParamSet @@ -108,8 +109,8 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_ImportWrappedKey(const struct OH_Huks_Blob *k * @brief 导出公钥。 * * @param keyAlias 表示要导出公钥对应的密钥别名,应与所用密钥生成时使用的别名相同。 - * @param paramSet 导出公钥需要的TAG(此处传空)。 - * @param key 表示要导入的密钥数据。 + * @param paramSet 导出公钥需要的TAG。 + * @param key 存放导出的公钥。 * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 * @since 9 * @version 1.0 diff --git a/zh-cn/native_sdk/security/huks/native_huks_type.h b/zh-cn/native_sdk/security/huks/native_huks_type.h index 48ecbc1f..32ef87e0 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_type.h +++ b/zh-cn/native_sdk/security/huks/native_huks_type.h @@ -61,96 +61,96 @@ extern "C" { #define SECURE_SIGN_VERSION 0x01000001 /** - * @brief 枚举密钥用途。 + * @brief 表示密钥用途。 * * @since 9 * @version 1.0 */ enum OH_Huks_KeyPurpose { - /** 加密, 支持的密钥类型有RSA、EC、AES和SM4。 */ + /** 表示密钥用于对明文进行加密操作。 */ OH_HUKS_KEY_PURPOSE_ENCRYPT = 1, - /** 解密, 支持的密钥类型有RSA、EC、AES和SM4。 */ + /** 表示密钥用于对密文进行解密操作。 */ OH_HUKS_KEY_PURPOSE_DECRYPT = 2, - /** 签名, 支持的密钥类型有RSA和EC。 */ + /** 表示密钥用于对数据进行签名。 */ OH_HUKS_KEY_PURPOSE_SIGN = 4, - /** 验签, 支持的密钥类型有RSA和EC。 */ + /** 表示密钥用于验证签名后的数据。 */ OH_HUKS_KEY_PURPOSE_VERIFY = 8, - /** 派生, 支持的密钥类型有EC。 */ + /** 表示密钥用于派生密钥。 */ OH_HUKS_KEY_PURPOSE_DERIVE = 16, - /** 包装, 支持的密钥类型有wrap。 */ + /** 表示密钥用于加密导出。 */ OH_HUKS_KEY_PURPOSE_WRAP = 32, - /** 解包, 支持的密钥类型有unwrap。 */ + /** 表示密钥加密导入。 */ OH_HUKS_KEY_PURPOSE_UNWRAP = 64, - /** 消息认证码。 */ + /** 表示密钥用于生成mac消息验证码。 */ OH_HUKS_KEY_PURPOSE_MAC = 128, - /** 协商。 */ + /** 表示密钥用于进行密钥协商。 */ OH_HUKS_KEY_PURPOSE_AGREE = 256, }; /** - * @brief 枚举摘要算法类型。 + * @brief 表示摘要算法类型。 * * @since 9 * @version 1.0 */ enum OH_Huks_KeyDigest { - /** 不使用摘要。 */ + /** 无摘要算法。 */ OH_HUKS_DIGEST_NONE = 0, - /** 信息摘要MD5。 */ + /** MD5摘要算法。 */ OH_HUKS_DIGEST_MD5 = 1, - /** 国密摘要SM3。 */ + /** SM3摘要算法。 */ OH_HUKS_DIGEST_SM3 = 2, - /** 安全哈希SHA1。 */ + /** SHA1摘要算法。 */ OH_HUKS_DIGEST_SHA1 = 10, - /** 安全哈希SHA224。 */ + /** SHA224摘要算法。 */ OH_HUKS_DIGEST_SHA224 = 11, - /** 安全哈希SHA256。 */ + /** SHA256摘要算法。 */ OH_HUKS_DIGEST_SHA256 = 12, - /** 安全哈希SHA384。 */ + /** SHA384摘要算法。 */ OH_HUKS_DIGEST_SHA384 = 13, - /** 安全哈希SHA512。 */ + /** SHA512摘要算法。 */ OH_HUKS_DIGEST_SHA512 = 14, }; /** - * @brief 枚举数据填充方式。 + * @brief 补齐算法。 * * @since 9 * @version 1.0 */ enum OH_Huks_KeyPadding { - /** 不填充。 */ + /** 不使用补齐算法。 */ OH_HUKS_PADDING_NONE = 0, - /** 最优非对称加密填充。 */ + /** 使用OAEP补齐算法。 */ OH_HUKS_PADDING_OAEP = 1, - /** 概率签名方案填充。 */ + /** 使用PSS补齐算法。 */ OH_HUKS_PADDING_PSS = 2, - /** 公钥加密标准PKCS1_V1_5填充。 */ + /** 使用PKCS1_V1_5补齐算法。 */ OH_HUKS_PADDING_PKCS1_V1_5 = 3, - /** 公钥加密标准PKCS5填充。 */ + /** 使用PKCS5补齐算法。 */ OH_HUKS_PADDING_PKCS5 = 4, - /** 公钥加密标准PKCS7填充。 */ + /** 使用PKCS7补齐算法。 */ OH_HUKS_PADDING_PKCS7 = 5, }; /** - * @brief 枚举加密工作模式。 + * @brief 加密工作模式。 * * @since 9 * @version 1.0 */ enum OH_Huks_CipherMode { - /** 电子密码本模式。 */ + /** 使用ECB加密模式。 */ OH_HUKS_MODE_ECB = 1, - /** 密文分组链接模式。 */ + /** 使用CBC加密模式。 */ OH_HUKS_MODE_CBC = 2, - /** 计数器模式。 */ + /** 使用CTR加密模式。 */ OH_HUKS_MODE_CTR = 3, - /** 输出反馈模。 */ + /** 使用OFB加密模式。 */ OH_HUKS_MODE_OFB = 4, - /** 认证加密CCM模式。 */ + /** 使用CCM加密模式。 */ OH_HUKS_MODE_CCM = 31, - /** 认证加密GCM模式。 */ + /** 使用GCM加密模式。 */ OH_HUKS_MODE_GCM = 32, }; @@ -278,62 +278,62 @@ enum OH_Huks_AlgSuite { }; /** - * @brief 枚举生成的密钥类型。 + * @brief 生成的密钥类型。 * * @since 9 * @version 1.0 */ enum OH_Huks_KeyGenerateType { - /** 默认类型。 */ + /** 默认生成的密钥。 */ OH_HUKS_KEY_GENERATE_TYPE_DEFAULT = 0, - /** 派生类型。 */ + /** 派生生成的密钥。 */ OH_HUKS_KEY_GENERATE_TYPE_DERIVE = 1, - /** 协商类型。 */ + /** 协商生成的密钥。 */ OH_HUKS_KEY_GENERATE_TYPE_AGREE = 2, }; /** - * @brief 枚举密钥的标记类型。 + * @brief 密钥的产生方式。 * * @since 9 * @version 1.0 */ enum OH_Huks_KeyFlag { - /** 导入密钥的标记。*/ + /** 通过导入公钥接口导入的密钥。*/ OH_HUKS_KEY_FLAG_IMPORT_KEY = 1, - /** 生成密钥的标记。*/ + /** 通过生成密钥接口生成的密钥。*/ OH_HUKS_KEY_FLAG_GENERATE_KEY = 2, - /** 协商密钥的标记。*/ + /** 通过生成密钥协商接口生成的密钥。*/ OH_HUKS_KEY_FLAG_AGREE_KEY = 3, - /** 派生密钥的标记。*/ + /** 通过生成密钥派生接口生成的密钥。*/ OH_HUKS_KEY_FLAG_DERIVE_KEY = 4, }; /** - * @brief 枚举密钥的存储类型。 + * @brief 密钥的存储方式。 * * @since 9 * @version 1.0 */ enum OH_Huks_KeyStorageType { - /** 临时性存储。*/ + /** 通过本地直接管理密钥。*/ OH_HUKS_STORAGE_TEMP = 0, - /** 永久性存储。*/ + /** 通过HUKS service管理密钥。*/ OH_HUKS_STORAGE_PERSISTENT = 1, }; /** - * @brief 枚举导入密钥的类型。 + * @brief 导入密钥的类型,默认为导入公钥,导入对称密钥时不需要该字段。 * * @since 9 * @version 1.0 */ enum OH_Huks_ImportKeyType { - /** 公钥类型。 */ + /** 导入的密钥类型为公钥。 */ OH_HUKS_KEY_TYPE_PUBLIC_KEY = 0, - /** 私钥类型。 */ + /** 导入的密钥类型为私钥。 */ OH_HUKS_KEY_TYPE_PRIVATE_KEY = 1, - /** 密钥对类型。 */ + /** 导入的密钥类型为公私钥对。 */ OH_HUKS_KEY_TYPE_KEY_PAIR = 2, }; @@ -499,40 +499,39 @@ enum OH_Huks_ErrorCode { }; /** - * @brief 枚举标签类型。 + * @brief Tag的数据类型。 * * @since 9 * @version 1.0 */ enum OH_Huks_TagType { - /** 无效类型。 */ + /** 表示非法的Tag类型。 */ OH_HUKS_TAG_TYPE_INVALID = 0 << 28, - /** int类型。 */ + /** 表示该Tag的数据类型为int类型的number。 */ OH_HUKS_TAG_TYPE_INT = 1 << 28, - /** uint类型。 */ + /** 表示该Tag的数据类型为uint类型的number。 */ OH_HUKS_TAG_TYPE_UINT = 2 << 28, - /** ulong类型。 */ + /** 表示该Tag的数据类型为bigint。 */ OH_HUKS_TAG_TYPE_ULONG = 3 << 28, - /** bool类型。 */ + /** 表示该Tag的数据类型为boolean。 */ OH_HUKS_TAG_TYPE_BOOL = 4 << 28, - /** bytes类型。 */ + /** 表示该Tag的数据类型为Uint8Array。 */ OH_HUKS_TAG_TYPE_BYTES = 5 << 28, }; /** - * @brief 枚举发送消息的方式 + * @brief 发送Tag的方式 * * @since 9 * @version 1.0 */ enum OH_Huks_SendType { - /** 异步。 */ + /** 表示异步发送TAG。 */ OH_HUKS_SEND_TYPE_ASYNC = 0, - /** 同步。 */ + /** 表示同步发送TAG。 */ OH_HUKS_SEND_TYPE_SYNC, }; - /** * @brief 用户认证类型 * @@ -605,16 +604,16 @@ enum OH_Huks_SecureSignType { }; /** - * @brief 枚举标签值。 + * @brief 调用参数的Tag。 * * @since 9 * @version 1.0 */ enum OH_Huks_Tag { - /** 无效标签值。 */ + /** 非法的Tag。 */ OH_HUKS_TAG_INVALID = OH_HUKS_TAG_TYPE_INVALID | 0, - /** 基础算法中用到的标签值是从1到200。 */ + /** 基础算法中用到的Tag从1到200。 */ /** 算法类型。 */ OH_HUKS_TAG_ALGORITHM = OH_HUKS_TAG_TYPE_UINT | 1, /** 用途。 */ @@ -623,17 +622,17 @@ enum OH_Huks_Tag { OH_HUKS_TAG_KEY_SIZE = OH_HUKS_TAG_TYPE_UINT | 3, /** 摘要算法。 */ OH_HUKS_TAG_DIGEST = OH_HUKS_TAG_TYPE_UINT | 4, - /** 填充方式。 */ + /** 补齐算法。 */ OH_HUKS_TAG_PADDING = OH_HUKS_TAG_TYPE_UINT | 5, - /** 工作模式。 */ + /** 加密模式。 */ OH_HUKS_TAG_BLOCK_MODE = OH_HUKS_TAG_TYPE_UINT | 6, /** 密钥类型。 */ OH_HUKS_TAG_KEY_TYPE = OH_HUKS_TAG_TYPE_UINT | 7, - /** 认证数据。 */ + /** 附加身份验证数据数据。 */ OH_HUKS_TAG_ASSOCIATED_DATA = OH_HUKS_TAG_TYPE_BYTES | 8, - /** NONCE值。 */ + /** 密钥加解密的字段。 */ OH_HUKS_TAG_NONCE = OH_HUKS_TAG_TYPE_BYTES | 9, - /** IV矢量。 */ + /** 初始化的向量。 */ OH_HUKS_TAG_IV = OH_HUKS_TAG_TYPE_BYTES | 10, /** 用于密钥派生的标签值。 */ @@ -643,18 +642,18 @@ enum OH_Huks_Tag { OH_HUKS_TAG_SALT = OH_HUKS_TAG_TYPE_BYTES | 12, /** 派生密码。 */ OH_HUKS_TAG_PWD = OH_HUKS_TAG_TYPE_BYTES | 13, - /** 派生迭代数。 */ + /** 派生迭代次数。 */ OH_HUKS_TAG_ITERATION = OH_HUKS_TAG_TYPE_UINT | 14, /** 生成密钥的类型,类型可在枚举OH_Huks_KeyGenerateType中选择。 */ OH_HUKS_TAG_KEY_GENERATE_TYPE = OH_HUKS_TAG_TYPE_UINT | 15, - /** 派生main密钥。 */ + /** 密钥派生时的主密钥。 */ OH_HUKS_TAG_DERIVE_MAIN_KEY = OH_HUKS_TAG_TYPE_BYTES | 16, - /** 派生因素。 */ + /** 派生时的派生因子。 */ OH_HUKS_TAG_DERIVE_FACTOR = OH_HUKS_TAG_TYPE_BYTES | 17, - /** 派生算法。 */ + /** 派生时的算法类型。 */ OH_HUKS_TAG_DERIVE_ALG = OH_HUKS_TAG_TYPE_UINT | 18, - /** 协商算法。 */ + /** 协商时的算法类型。 */ OH_HUKS_TAG_AGREE_ALG = OH_HUKS_TAG_TYPE_UINT | 19, /** 是否带有用于协商的公钥。 */ OH_HUKS_TAG_AGREE_PUBLIC_KEY_IS_KEY_ALIAS = OH_HUKS_TAG_TYPE_BOOL | 20, @@ -668,14 +667,9 @@ enum OH_Huks_Tag { OH_HUKS_TAG_DERIVE_KEY_SIZE = OH_HUKS_TAG_TYPE_UINT | 24, /** 导入密钥类型, 类型可在枚举OH_Huks_ImportKeyType中选择。 */ OH_HUKS_TAG_IMPORT_KEY_TYPE = OH_HUKS_TAG_TYPE_UINT | 25, - /** 解包套件算法。 */ + /** 导入加密密钥的套件。 */ OH_HUKS_TAG_UNWRAP_ALGORITHM_SUITE = OH_HUKS_TAG_TYPE_UINT | 26, - /** - * Key authentication related TAG: 201 - 300 - * - * Start of validity - */ /** 密钥认证需要用到的标签值从201到300。 */ /** 活跃时间。 */ OH_HUKS_TAG_ACTIVE_DATETIME = OH_HUKS_TAG_TYPE_ULONG | 201, @@ -692,7 +686,7 @@ enum OH_Huks_Tag { OH_HUKS_TAG_CREATION_DATETIME = OH_HUKS_TAG_TYPE_ULONG | 204, /** Other authentication related TAG: 301 - 500 */ - /** 所有使用者。 */ + /** 所有用户。 */ OH_HUKS_TAG_ALL_USERS = OH_HUKS_TAG_TYPE_BOOL | 301, /** 用户ID。 */ OH_HUKS_TAG_USER_ID = OH_HUKS_TAG_TYPE_UINT | 302, @@ -700,41 +694,49 @@ enum OH_Huks_Tag { OH_HUKS_TAG_NO_AUTH_REQUIRED = OH_HUKS_TAG_TYPE_BOOL | 303, /** 用户认证类型。 */ OH_HUKS_TAG_USER_AUTH_TYPE = OH_HUKS_TAG_TYPE_UINT | 304, - /** 认证超时。 */ + /** 认证超时的最大时间。 */ OH_HUKS_TAG_AUTH_TIMEOUT = OH_HUKS_TAG_TYPE_UINT | 305, - /** 认证token。 */ + /** 认证需要的AuthToken。 */ OH_HUKS_TAG_AUTH_TOKEN = OH_HUKS_TAG_TYPE_BYTES | 306, + /** 表示安全访问控制类型。从OH_Huks_AuthAccessType中选择,需要和用户认证类型同时设置。 */ + OH_HUKS_TAG_KEY_AUTH_ACCESS_TYPE = OH_HUKS_TAG_TYPE_UINT | 307, + /** 表示生成或导入密钥时,指定该密钥的签名类型。 */ + OH_HUKS_TAG_KEY_SECURE_SIGN_TYPE = OH_HUKS_TAG_TYPE_UINT | 308, + /** 表示密钥使用时生成的challenge类型。从OH_Huks_ChallengeType中选择。 */ + OH_HUKS_TAG_CHALLENGE_TYPE = OH_HUKS_TAG_TYPE_UINT | 309, + /** 表示challenge类型为用户自定义类型时,huks产生的challenge有效长度仅为8字节连续的数据。从OH_Huks_ChallengePosition中选择。 */ + OH_HUKS_TAG_CHALLENGE_POS = OH_HUKS_TAG_TYPE_UINT | 310, /** Attestation related TAG: 501 - 600 */ - /** 挑战值。 */ + /** attestation时的挑战值。 */ OH_HUKS_TAG_ATTESTATION_CHALLENGE = OH_HUKS_TAG_TYPE_BYTES | 501, - /** 应用ID。 */ + /** attestation时拥有该密钥的application的Id。 */ OH_HUKS_TAG_ATTESTATION_APPLICATION_ID = OH_HUKS_TAG_TYPE_BYTES | 502, - /** 商标名。 */ + /** 设备的品牌。 */ OH_HUKS_TAG_ATTESTATION_ID_BRAND = OH_HUKS_TAG_TYPE_BYTES | 503, - /** 设备名。 */ + /** 设备的设备ID。 */ OH_HUKS_TAG_ATTESTATION_ID_DEVICE = OH_HUKS_TAG_TYPE_BYTES | 504, - /** 产品名。 */ + /** 设备的产品名。 */ OH_HUKS_TAG_ATTESTATION_ID_PRODUCT = OH_HUKS_TAG_TYPE_BYTES | 505, - /** 序号。 */ + /** 设备的SN号。 */ OH_HUKS_TAG_ATTESTATION_ID_SERIAL = OH_HUKS_TAG_TYPE_BYTES | 506, - /** IMEI。 */ + /** 设备的IMEI号。 */ OH_HUKS_TAG_ATTESTATION_ID_IMEI = OH_HUKS_TAG_TYPE_BYTES | 507, - /** MEID。 */ + /** 设备的MEID号。 */ OH_HUKS_TAG_ATTESTATION_ID_MEID = OH_HUKS_TAG_TYPE_BYTES | 508, - /** 生产商。 */ + /** 设备的制造商。 */ OH_HUKS_TAG_ATTESTATION_ID_MANUFACTURER = OH_HUKS_TAG_TYPE_BYTES | 509, - /** 模型。 */ + /** 设备的型号。 */ OH_HUKS_TAG_ATTESTATION_ID_MODEL = OH_HUKS_TAG_TYPE_BYTES | 510, - /** 别名。 */ + /** attestation时的密钥别名。 */ OH_HUKS_TAG_ATTESTATION_ID_ALIAS = OH_HUKS_TAG_TYPE_BYTES | 511, - /** SOCID。 */ + /** 设备的SOCID。 */ OH_HUKS_TAG_ATTESTATION_ID_SOCID = OH_HUKS_TAG_TYPE_BYTES | 512, - /** UDID。 */ + /** 设备的UDID。 */ OH_HUKS_TAG_ATTESTATION_ID_UDID = OH_HUKS_TAG_TYPE_BYTES | 513, - /** 安全等级信息。 */ + /** attestation时的安全凭据。 */ OH_HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO = OH_HUKS_TAG_TYPE_BYTES | 514, - /** 版本信息。 */ + /** attestation时的版本号。 */ OH_HUKS_TAG_ATTESTATION_ID_VERSION_INFO = OH_HUKS_TAG_TYPE_BYTES | 515, /** @@ -742,7 +744,7 @@ enum OH_Huks_Tag { * * Extention TAG: 1001 - 9999 */ - /** 是否密钥别名。 */ + /** 是否使用生成key时传入的别名的Tag。 */ OH_HUKS_TAG_IS_KEY_ALIAS = OH_HUKS_TAG_TYPE_BOOL | 1001, /** 密钥存储标记, 类型可在枚举OH_Huks_KeyStorageType选择。 */ OH_HUKS_TAG_KEY_STORAGE_FLAG = OH_HUKS_TAG_TYPE_UINT | 1002, -- Gitee From d5e77f91c52e7e100a776409ee57ce9283fa3329 Mon Sep 17 00:00:00 2001 From: zhao_zhen_zhou Date: Wed, 3 Aug 2022 03:03:33 -0700 Subject: [PATCH 14/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhao_zhen_zhou --- .../security/huks/native_huks_api.h | 2 +- .../security/huks/native_huks_type.h | 108 +++++++++--------- 2 files changed, 56 insertions(+), 54 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_api.h b/zh-cn/native_sdk/security/huks/native_huks_api.h index 0760ac34..4a671f67 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_api.h +++ b/zh-cn/native_sdk/security/huks/native_huks_api.h @@ -94,7 +94,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_ImportKey(const struct OH_Huks_Blob *keyAlias * @brief 导入加密密钥。 * * @param keyAlias 密钥别名,存放待导入密钥的别名。 - * @param wrappingKeyAlias 密钥别名,对应密钥用于解密加密的密钥数据。表示导入密钥需要的输入参数集。 + * @param wrappingKeyAlias 密钥别名,对应密钥用于解密加密的密钥数据。 * @param paramSet 导入时所需TAG。 * @param key 需要导入的加密的密钥数据。 * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 diff --git a/zh-cn/native_sdk/security/huks/native_huks_type.h b/zh-cn/native_sdk/security/huks/native_huks_type.h index 32ef87e0..6d8356a3 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_type.h +++ b/zh-cn/native_sdk/security/huks/native_huks_type.h @@ -113,7 +113,7 @@ enum OH_Huks_KeyDigest { }; /** - * @brief 补齐算法。 + * @brief 表示补齐算法。 * * @since 9 * @version 1.0 @@ -134,7 +134,7 @@ enum OH_Huks_KeyPadding { }; /** - * @brief 加密工作模式。 + * @brief 表示加密工作模式。 * * @since 9 * @version 1.0 @@ -155,7 +155,7 @@ enum OH_Huks_CipherMode { }; /** - * @brief 枚举不同算法支持的密钥长度。 + * @brief 表示密钥长度。 * * @since 9 * @version 1.0 @@ -209,7 +209,7 @@ enum OH_Huks_KeySize { }; /** - * @brief 枚举支持的算法类型。 + * @brief 表示密钥使用的算法。 * * @since 9 * @version 1.0 @@ -222,34 +222,34 @@ enum OH_Huks_KeyAlg { /** 使用DSA算法。 */ OH_HUKS_ALG_DSA = 3, - /** 对称密钥算法AES。 */ + /** 使用AES算法。 */ OH_HUKS_ALG_AES = 20, - /** 消息认证码算法HMAC。 */ + /** 使用HMAC算法。 */ OH_HUKS_ALG_HMAC = 50, - /** 基于HMAC的密钥推导函数算法HKDF。 */ + /** 使用HKDF算法。 */ OH_HUKS_ALG_HKDF = 51, - /** 伪随机函数以导出密钥算法PBKDF2。 */ + /** 使用PBKDF2算法。 */ OH_HUKS_ALG_PBKDF2 = 52, - /** 密钥协商算法ECDH。 */ + /** 使用ECDH算法。 */ OH_HUKS_ALG_ECDH = 100, - /** 密钥协商算法X25519。 */ + /** 使用X25519算法。 */ OH_HUKS_ALG_X25519 = 101, - /** 签名验签算法ED25519。 */ + /** 使用ED25519算法。 */ OH_HUKS_ALG_ED25519 = 102, /** 使用DH算法。 */ OH_HUKS_ALG_DH = 103, - /** 国密算法SM2。*/ + /** 使用SM2算法。*/ OH_HUKS_ALG_SM2 = 150, - /** 国密算法SM3。*/ + /** 使用SM3算法。*/ OH_HUKS_ALG_SM3 = 151, - /** 国密算法SM4。*/ + /** 使用SM4算法。*/ OH_HUKS_ALG_SM4 = 152, }; /** - * @brief 枚举解包套件的算法类型 + * @brief 表示导入加密密钥的算法套件。 * * @since 9 * @version 1.0 @@ -265,6 +265,7 @@ enum OH_Huks_AlgSuite { * | kek_nonce_length (4 Byte) | kek_nonce | kek_aead_tag_len (4 Byte) | kek_aead_tag * | key_material_size_len (4 Byte) | key_material_size | key_mat_enc_length (4 Byte) | key_mat_enc_data */ + /** 导入加密密钥时,X25519密钥协商后使用AES-256 GCM加密。 */ OH_HUKS_UNWRAP_SUITE_X25519_AES_256_GCM_NOPADDING = 1, /* WrappedData format(Bytes Array): @@ -274,11 +275,12 @@ enum OH_Huks_AlgSuite { * | kek_nonce_length (4 Byte) | kek_nonce | kek_aead_tag_len (4 Byte) | kek_aead_tag * | key_material_size_len (4 Byte) | key_material_size | key_mat_enc_length (4 Byte) | key_mat_enc_data */ + /** 导入加密密钥时,ECDH密钥协商后使用AES-256 GCM加密。 */ OH_HUKS_UNWRAP_SUITE_ECDH_AES_256_GCM_NOPADDING = 2, }; /** - * @brief 生成的密钥类型。 + * @brief 表示生成的密钥类型。 * * @since 9 * @version 1.0 @@ -293,7 +295,7 @@ enum OH_Huks_KeyGenerateType { }; /** - * @brief 密钥的产生方式。 + * @brief 表示密钥的产生方式。 * * @since 9 * @version 1.0 @@ -310,7 +312,7 @@ enum OH_Huks_KeyFlag { }; /** - * @brief 密钥的存储方式。 + * @brief 表示密钥的存储方式。 * * @since 9 * @version 1.0 @@ -338,7 +340,7 @@ enum OH_Huks_ImportKeyType { }; /** - * @brief 枚举状态返回码。 + * @brief 表示状态返回码。 * * @since 9 * @version 1.0 @@ -499,7 +501,7 @@ enum OH_Huks_ErrorCode { }; /** - * @brief Tag的数据类型。 + * @brief 表示Tag的数据类型。 * * @since 9 * @version 1.0 @@ -520,7 +522,7 @@ enum OH_Huks_TagType { }; /** - * @brief 发送Tag的方式 + * @brief 表示发送Tag的方式 * * @since 9 * @version 1.0 @@ -533,7 +535,7 @@ enum OH_Huks_SendType { }; /** - * @brief 用户认证类型 + * @brief 表示用户认证类型 * * @since 9 * @version 1.0 @@ -548,7 +550,7 @@ enum OH_Huks_UserAuthType { }; /** - * @brief 安全访问控制类型 + * @brief 表示安全访问控制类型 * * @since 9 * @version 1.0 @@ -604,7 +606,7 @@ enum OH_Huks_SecureSignType { }; /** - * @brief 调用参数的Tag。 + * @brief 表示调用参数的Tag。 * * @since 9 * @version 1.0 @@ -616,7 +618,7 @@ enum OH_Huks_Tag { /** 基础算法中用到的Tag从1到200。 */ /** 算法类型。 */ OH_HUKS_TAG_ALGORITHM = OH_HUKS_TAG_TYPE_UINT | 1, - /** 用途。 */ + /** 密钥用途。 */ OH_HUKS_TAG_PURPOSE = OH_HUKS_TAG_TYPE_UINT | 2, /** 密钥长度 。 */ OH_HUKS_TAG_KEY_SIZE = OH_HUKS_TAG_TYPE_UINT | 3, @@ -628,15 +630,15 @@ enum OH_Huks_Tag { OH_HUKS_TAG_BLOCK_MODE = OH_HUKS_TAG_TYPE_UINT | 6, /** 密钥类型。 */ OH_HUKS_TAG_KEY_TYPE = OH_HUKS_TAG_TYPE_UINT | 7, - /** 附加身份验证数据数据。 */ + /** 附加身份验证数据。 */ OH_HUKS_TAG_ASSOCIATED_DATA = OH_HUKS_TAG_TYPE_BYTES | 8, /** 密钥加解密的字段。 */ OH_HUKS_TAG_NONCE = OH_HUKS_TAG_TYPE_BYTES | 9, /** 初始化的向量。 */ OH_HUKS_TAG_IV = OH_HUKS_TAG_TYPE_BYTES | 10, - /** 用于密钥派生的标签值。 */ - /** 派生信息。 */ + /** 用于密钥派生的Tag。 */ + /** 密钥派生时的info。 */ OH_HUKS_TAG_INFO = OH_HUKS_TAG_TYPE_BYTES | 11, /** 派生盐值。 */ OH_HUKS_TAG_SALT = OH_HUKS_TAG_TYPE_BYTES | 12, @@ -653,11 +655,11 @@ enum OH_Huks_Tag { OH_HUKS_TAG_DERIVE_FACTOR = OH_HUKS_TAG_TYPE_BYTES | 17, /** 派生时的算法类型。 */ OH_HUKS_TAG_DERIVE_ALG = OH_HUKS_TAG_TYPE_UINT | 18, - /** 协商时的算法类型。 */ + /** 密钥协商时的算法类型。 */ OH_HUKS_TAG_AGREE_ALG = OH_HUKS_TAG_TYPE_UINT | 19, - /** 是否带有用于协商的公钥。 */ + /** 密钥协商时的公钥别名。 */ OH_HUKS_TAG_AGREE_PUBLIC_KEY_IS_KEY_ALIAS = OH_HUKS_TAG_TYPE_BOOL | 20, - /** 用于协商的私钥别名。 */ + /** 密钥协商时的私钥别名。 */ OH_HUKS_TAG_AGREE_PRIVATE_KEY_ALIAS = OH_HUKS_TAG_TYPE_BYTES | 21, /** 用于协商的公钥。 */ OH_HUKS_TAG_AGREE_PUBLIC_KEY = OH_HUKS_TAG_TYPE_BYTES | 22, @@ -671,32 +673,32 @@ enum OH_Huks_Tag { OH_HUKS_TAG_UNWRAP_ALGORITHM_SUITE = OH_HUKS_TAG_TYPE_UINT | 26, /** 密钥认证需要用到的标签值从201到300。 */ - /** 活跃时间。 */ + /** 预留。 */ OH_HUKS_TAG_ACTIVE_DATETIME = OH_HUKS_TAG_TYPE_ULONG | 201, /** Date when new "messages" should not be created. */ - /** 发放过期日期。 */ + /** 预留。 */ OH_HUKS_TAG_ORIGINATION_EXPIRE_DATETIME = OH_HUKS_TAG_TYPE_ULONG | 202, /** Date when existing "messages" should not be used. */ - /** 使用过期日期。 */ + /** 预留。 */ OH_HUKS_TAG_USAGE_EXPIRE_DATETIME = OH_HUKS_TAG_TYPE_ULONG | 203, - /** 密钥创建的时间。 */ + /** 预留。 */ OH_HUKS_TAG_CREATION_DATETIME = OH_HUKS_TAG_TYPE_ULONG | 204, /** Other authentication related TAG: 301 - 500 */ - /** 所有用户。 */ + /** 预留。 */ OH_HUKS_TAG_ALL_USERS = OH_HUKS_TAG_TYPE_BOOL | 301, - /** 用户ID。 */ + /** 预留。 */ OH_HUKS_TAG_USER_ID = OH_HUKS_TAG_TYPE_UINT | 302, - /** 无认证请求。 */ + /** 预留。 */ OH_HUKS_TAG_NO_AUTH_REQUIRED = OH_HUKS_TAG_TYPE_BOOL | 303, /** 用户认证类型。 */ OH_HUKS_TAG_USER_AUTH_TYPE = OH_HUKS_TAG_TYPE_UINT | 304, - /** 认证超时的最大时间。 */ + /** 预留。 */ OH_HUKS_TAG_AUTH_TIMEOUT = OH_HUKS_TAG_TYPE_UINT | 305, - /** 认证需要的AuthToken。 */ + /** 预留。 */ OH_HUKS_TAG_AUTH_TOKEN = OH_HUKS_TAG_TYPE_BYTES | 306, /** 表示安全访问控制类型。从OH_Huks_AuthAccessType中选择,需要和用户认证类型同时设置。 */ OH_HUKS_TAG_KEY_AUTH_ACCESS_TYPE = OH_HUKS_TAG_TYPE_UINT | 307, @@ -746,25 +748,25 @@ enum OH_Huks_Tag { */ /** 是否使用生成key时传入的别名的Tag。 */ OH_HUKS_TAG_IS_KEY_ALIAS = OH_HUKS_TAG_TYPE_BOOL | 1001, - /** 密钥存储标记, 类型可在枚举OH_Huks_KeyStorageType选择。 */ + /** 密钥存储方式的Tag, 类型可在枚举OH_Huks_KeyStorageType选择。 */ OH_HUKS_TAG_KEY_STORAGE_FLAG = OH_HUKS_TAG_TYPE_UINT | 1002, - /** 是否运行打包数据。 */ + /** 预留。 */ OH_HUKS_TAG_IS_ALLOWED_WRAP = OH_HUKS_TAG_TYPE_BOOL | 1003, - /** 打包数据类型。 */ + /** 预留。 */ OH_HUKS_TAG_KEY_WRAP_TYPE = OH_HUKS_TAG_TYPE_UINT | 1004, - /** 密钥认证ID。 */ + /** 预留。 */ OH_HUKS_TAG_KEY_AUTH_ID = OH_HUKS_TAG_TYPE_BYTES | 1005, - /** 密钥作用。 */ + /** 预留。 */ OH_HUKS_TAG_KEY_ROLE = OH_HUKS_TAG_TYPE_UINT | 1006, - /** 密钥标记, , 类型可在枚举OH_Huks_KeyFlag选择。 */ + /** 密钥标志的Tag, 类型可在枚举OH_Huks_KeyFlag选择。 */ OH_HUKS_TAG_KEY_FLAG = OH_HUKS_TAG_TYPE_UINT | 1007, - /** 是否异步。 */ + /** 预留。 */ OH_HUKS_TAG_IS_ASYNCHRONIZED = OH_HUKS_TAG_TYPE_UINT | 1008, - /** 安全密钥别名。 */ + /** 预留。 */ OH_HUKS_TAG_SECURE_KEY_ALIAS = OH_HUKS_TAG_TYPE_BOOL | 1009, - /** 安全密钥UUID。 */ + /** 预留。 */ OH_HUKS_TAG_SECURE_KEY_UUID = OH_HUKS_TAG_TYPE_BYTES | 1010, - /** 密钥领域。 */ + /** 预留。 */ OH_HUKS_TAG_KEY_DOMAIN = OH_HUKS_TAG_TYPE_UINT | 1011, /** @@ -773,11 +775,11 @@ enum OH_Huks_Tag { * Other TAGs: 20001 - N * TAGs used for paramSetOut */ - /** 对称密钥数据 */ + /** 预留。 */ OH_HUKS_TAG_SYMMETRIC_KEY_DATA = OH_HUKS_TAG_TYPE_BYTES | 20001, - /** 非对称公钥数据。 */ + /** 预留。 */ OH_HUKS_TAG_ASYMMETRIC_PUBLIC_KEY_DATA = OH_HUKS_TAG_TYPE_BYTES | 20002, - /** 非对称私钥数据。 */ + /** 预留。 */ OH_HUKS_TAG_ASYMMETRIC_PRIVATE_KEY_DATA = OH_HUKS_TAG_TYPE_BYTES | 20003, }; -- Gitee From a50dfb8a2d34f11c9a456457f8a4b9f79712a3a2 Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Thu, 4 Aug 2022 11:49:54 +0800 Subject: [PATCH 15/17] =?UTF-8?q?=E5=AF=B9=E9=BD=90=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zqr2001 <1805768383@qq.com> --- zh-cn/native_sdk/security/huks/native_huks_api.h | 2 +- zh-cn/native_sdk/security/huks/native_huks_param.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_api.h b/zh-cn/native_sdk/security/huks/native_huks_api.h index 4a671f67..c3d622c7 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_api.h +++ b/zh-cn/native_sdk/security/huks/native_huks_api.h @@ -48,7 +48,7 @@ #ifndef _NATIVE_HUKS_API_H_ #define _NATIVE_HUKS_API_H_ -#include "native_hks_type.h" +#include "native_huks_type.h" #ifdef __cplusplus extern "C" { diff --git a/zh-cn/native_sdk/security/huks/native_huks_param.h b/zh-cn/native_sdk/security/huks/native_huks_param.h index 0e11caab..96391fb8 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_param.h +++ b/zh-cn/native_sdk/security/huks/native_huks_param.h @@ -36,7 +36,7 @@ #ifndef NATIVE_HUKS_PARAM_H #define NATIVE_HUKS_PARAM_H -#include "native_hks_type.h" +#include "native_huks_type.h" #define OH_HUKS_PARAM_SET_MAX_SIZE (4 * 1024 * 1024) #define OH_HUKS_DEFAULT_PARAM_SET_SIZE 512 -- Gitee From 8fba7e85c449afb57862f40f9552495c00a38f61 Mon Sep 17 00:00:00 2001 From: zqr2001 <1805768383@qq.com> Date: Thu, 4 Aug 2022 12:06:41 +0800 Subject: [PATCH 16/17] remove OH_HUKS_API_EXPORT Signed-off-by: zqr2001 <1805768383@qq.com> --- .../security/huks/native_huks_api.h | 24 +++++++++---------- .../security/huks/native_huks_param.h | 14 +++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_api.h b/zh-cn/native_sdk/security/huks/native_huks_api.h index c3d622c7..b23dbf5f 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_api.h +++ b/zh-cn/native_sdk/security/huks/native_huks_api.h @@ -62,7 +62,7 @@ extern "C" { * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_GetSdkVersion(struct OH_Huks_Blob *sdkVersion); +int32_t OH_Huks_GetSdkVersion(struct OH_Huks_Blob *sdkVersion); /** * @brief 生成密钥。 @@ -74,7 +74,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_GetSdkVersion(struct OH_Huks_Blob *sdkVersion * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_GenerateKey(const struct OH_Huks_Blob *keyAlias, +int32_t OH_Huks_GenerateKey(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *paramSetIn, struct OH_Huks_ParamSet *paramSetOut); /** @@ -87,7 +87,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_GenerateKey(const struct OH_Huks_Blob *keyAli * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_ImportKey(const struct OH_Huks_Blob *keyAlias, +int32_t OH_Huks_ImportKey(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *key); /** @@ -101,7 +101,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_ImportKey(const struct OH_Huks_Blob *keyAlias * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_ImportWrappedKey(const struct OH_Huks_Blob *keyAlias, +int32_t OH_Huks_ImportWrappedKey(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_Blob *wrappingKeyAlias, const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *wrappedKeyData); @@ -115,7 +115,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_ImportWrappedKey(const struct OH_Huks_Blob *k * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_ExportPublicKey(const struct OH_Huks_Blob *keyAlias, +int32_t OH_Huks_ExportPublicKey(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *paramSet, struct OH_Huks_Blob *key); /** @@ -127,7 +127,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_ExportPublicKey(const struct OH_Huks_Blob *ke * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_DeleteKey(const struct OH_Huks_Blob *keyAlias, +int32_t OH_Huks_DeleteKey(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *paramSet); /** @@ -140,7 +140,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_DeleteKey(const struct OH_Huks_Blob *keyAlias * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_GetKeyParamSet(const struct OH_Huks_Blob *keyAlias, +int32_t OH_Huks_GetKeyParamSet(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *paramSetIn, struct OH_Huks_ParamSet *paramSetOut); /** @@ -152,7 +152,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_GetKeyParamSet(const struct OH_Huks_Blob *key * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_isKeyExist(const struct OH_Huks_Blob *keyAlias, +int32_t OH_Huks_isKeyExist(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *paramSet); /** @@ -166,7 +166,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_isKeyExist(const struct OH_Huks_Blob *keyAlia * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_Init(const struct OH_Huks_Blob *keyAlias, +int32_t OH_Huks_Init(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *paramSet, struct OH_Huks_Blob *handle, struct HksBlob *token); /** @@ -180,7 +180,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_Init(const struct OH_Huks_Blob *keyAlias, * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_Update(const struct OH_Huks_Blob *handle, +int32_t OH_Huks_Update(const struct OH_Huks_Blob *handle, const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *outData); /** @@ -194,7 +194,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_Update(const struct OH_Huks_Blob *handle, * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_Finish(const struct OH_Huks_Blob *handle, +int32_t OH_Huks_Finish(const struct OH_Huks_Blob *handle, const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *outData); /** @@ -206,7 +206,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_Finish(const struct OH_Huks_Blob *handle, * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_Abort(const struct OH_Huks_Blob *handle, +int32_t OH_Huks_Abort(const struct OH_Huks_Blob *handle, const struct OH_Huks_ParamSet *paramSet); #ifdef __cplusplus diff --git a/zh-cn/native_sdk/security/huks/native_huks_param.h b/zh-cn/native_sdk/security/huks/native_huks_param.h index 96391fb8..464631c2 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_param.h +++ b/zh-cn/native_sdk/security/huks/native_huks_param.h @@ -55,7 +55,7 @@ extern "C" { * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_InitParamSet(struct OH_Huks_ParamSet **paramSet); +int32_t OH_Huks_InitParamSet(struct OH_Huks_ParamSet **paramSet); /** * @brief 添加参数到参数集里面。 @@ -67,7 +67,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_InitParamSet(struct OH_Huks_ParamSet **paramS * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_AddParams(struct OH_Huks_ParamSet *paramSet, +int32_t OH_Huks_AddParams(struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Param *params, uint32_t paramCnt); /** @@ -78,7 +78,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_AddParams(struct OH_Huks_ParamSet *paramSet, * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_BuildParamSet(struct OH_Huks_ParamSet **paramSet); +int32_t OH_Huks_BuildParamSet(struct OH_Huks_ParamSet **paramSet); /** * @brief 销毁参数集。 @@ -87,7 +87,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_BuildParamSet(struct OH_Huks_ParamSet **param * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT void OH_Huks_FreeParamSet(struct OH_Huks_ParamSet **paramSet); +void OH_Huks_FreeParamSet(struct OH_Huks_ParamSet **paramSet); /** * @brief 复制参数集。 @@ -99,7 +99,7 @@ OH_HUKS_API_EXPORT void OH_Huks_FreeParamSet(struct OH_Huks_ParamSet **paramSet) * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_CopyParamSet(const struct OH_Huks_ParamSet *fromParamSet, +int32_t OH_Huks_CopyParamSet(const struct OH_Huks_ParamSet *fromParamSet, uint32_t fromParamSetSize, struct OH_Huks_ParamSet **paramSet); /** @@ -112,7 +112,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_CopyParamSet(const struct OH_Huks_ParamSet *f * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_GetParam(const struct OH_Huks_ParamSet *paramSet, uint32_t tag, +int32_t OH_Huks_GetParam(const struct OH_Huks_ParamSet *paramSet, uint32_t tag, struct OH_Huks_Param **param); /** @@ -124,7 +124,7 @@ OH_HUKS_API_EXPORT int32_t OH_Huks_GetParam(const struct OH_Huks_ParamSet *param * @since 9 * @version 1.0 */ -OH_HUKS_API_EXPORT int32_t OH_Huks_FreshParamSet(struct OH_Huks_ParamSet *paramSet, bool isCopy); +int32_t OH_Huks_FreshParamSet(struct OH_Huks_ParamSet *paramSet, bool isCopy); /** * @brief 检查参数集中的参数是否有效、是否有重复。 -- Gitee From 89ee9232423eb1c95a09f8e9814ff4f6a18463cf Mon Sep 17 00:00:00 2001 From: zhao_zhen_zhou Date: Thu, 4 Aug 2022 03:42:34 -0700 Subject: [PATCH 17/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhao_zhen_zhou --- .../security/huks/native_huks_api.h | 2 +- .../security/huks/native_huks_param.h | 43 ++++++++++--------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/zh-cn/native_sdk/security/huks/native_huks_api.h b/zh-cn/native_sdk/security/huks/native_huks_api.h index b23dbf5f..112728d8 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_api.h +++ b/zh-cn/native_sdk/security/huks/native_huks_api.h @@ -55,7 +55,7 @@ extern "C" { #endif /** - * @brief 获取当前系统sdk版本。 + * @brief 获取huks SDK版本号。 * * @param sdkVersion 用于存储获取到的版本信息。 * @return 返回HUKS_SUCCESS时表示接口使用成功,其他时为错误。 diff --git a/zh-cn/native_sdk/security/huks/native_huks_param.h b/zh-cn/native_sdk/security/huks/native_huks_param.h index 464631c2..d1d3d716 100644 --- a/zh-cn/native_sdk/security/huks/native_huks_param.h +++ b/zh-cn/native_sdk/security/huks/native_huks_param.h @@ -48,9 +48,9 @@ extern "C" { #endif /** - * @brief 初始化参数集。 + * @brief 初始化OH_Huks_ParamSet结构体。 * - * @param paramSet 表示指向要初始化的参数集的指针。 + * @param paramSet 表示待初始化的结构体,必须为NULL。 * @return 返回执行的状态代码。 * @since 9 * @version 1.0 @@ -58,22 +58,23 @@ extern "C" { int32_t OH_Huks_InitParamSet(struct OH_Huks_ParamSet **paramSet); /** - * @brief 添加参数到参数集里面。 + * @brief 往OH_Huks_ParamSet里面添加参数,使用前需要调用OH_Huks_InitParamSet初始化结构体。 * - * @param paramSet 表示指向要被添加参数的参数集的指针。 - * @param params 表示指向要添加的参数的指针。 - * @param paramCnt 表示要添加参数的个数。 + * @param paramSet 表示添加参数之前的参数集,为调用OH_Huks_InitParamSet后的结构体。 + * @param params 表示待添加的一个或多个参数。 + * @param paramCnt 表示params里面对应的参数个数。 * @return 返回执行的状态代码。 * @since 9 * @version 1.0 */ + int32_t OH_Huks_AddParams(struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Param *params, uint32_t paramCnt); /** - * @brief 构造正式的参数集。 + * @brief 生成最终的参数集,在调用OH_Huks_InitParamSet、OH_Huks_AddParams后使用。 * - * @param paramSet 表示指向要被正式构造的参数集的指针。 + * @param paramSet 表示添加参数之后的入参参数集,为调用OH_Huks_InitParamSet、OH_Huks_AddParams后的结构体。 * @return 返回执行的状态代码。 * @since 9 * @version 1.0 @@ -81,9 +82,9 @@ int32_t OH_Huks_AddParams(struct OH_Huks_ParamSet *paramSet, int32_t OH_Huks_BuildParamSet(struct OH_Huks_ParamSet **paramSet); /** - * @brief 销毁参数集。 + * @brief 释放参数集。 * - * @param paramSet 表示指向要被销毁的参数集的指针。 + * @param paramSet 表示待释放的参数集。 * @since 9 * @version 1.0 */ @@ -92,9 +93,9 @@ void OH_Huks_FreeParamSet(struct OH_Huks_ParamSet **paramSet); /** * @brief 复制参数集。 * - * @param fromParamSet 表示指向要被复制的参数集的指针。 + * @param fromParamSet 表示要被复制的参数集。 * @param fromParamSetSize 表示被复制的参数集占用内存的大小。 - * @param paramSet 表示指向生成新的参数集的指针。 + * @param paramSet 表示生成新的参数集。 * @return 返回执行的状态代码。 * @since 9 * @version 1.0 @@ -103,11 +104,11 @@ int32_t OH_Huks_CopyParamSet(const struct OH_Huks_ParamSet *fromParamSet, uint32_t fromParamSetSize, struct OH_Huks_ParamSet **paramSet); /** - * @brief 从参数集中获取参数。 + * @brief 根据TAG从参数集paramSet中获取对应的参数。 * - * @param paramSet 表示指向参数集的指针。 - * @param tag 表示要获取的参数对应的特征值。 - * @param param 表示指向获取到的参数的指针。 + * @param paramSet 表示参数集,非空,需要满足参数要求。 + * @param tag 表示需要获取的参数的TAG,从enum OH_Huks_Tag中获取 + * @param param 表示获取到的参数,无需释放。 * @return 返回执行的状态代码。 * @since 9 * @version 1.0 @@ -118,7 +119,7 @@ int32_t OH_Huks_GetParam(const struct OH_Huks_ParamSet *paramSet, uint32_t tag, /** * @brief 刷新参数集。 * - * @param paramSet 表示指向参数集的指针。 + * @param paramSet 表示待刷新的参数集。 * @param isCopy 表示是否要刷新参数集内存中的struct HksBlob型的参数数据。 * @return 返回执行的状态代码。 * @since 9 @@ -129,7 +130,7 @@ int32_t OH_Huks_FreshParamSet(struct OH_Huks_ParamSet *paramSet, bool isCopy); /** * @brief 检查参数集中的参数是否有效、是否有重复。 * - * @param paramSet 表示指向参数集的指针。 + * @param paramSet 表示待检查的参数集。 * @return 返回执行的状态代码。 * @since 9 * @version 1.0 @@ -139,7 +140,7 @@ int32_t OH_Huks_isParamSetTagValid(const struct OH_Huks_ParamSet *paramSet); /** * @brief 检查参数集是否有效。 * - * @param paramSet 表示指向参数集的指针。 + * @param paramSet 表示待检查的参数集。 * @param size 表示参数集占用的内存大小。 * @return 返回执行的状态代码。 * @since 9 @@ -150,8 +151,8 @@ int32_t OH_Huks_isParamSetValid(const struct OH_Huks_ParamSet *paramSet, uint32_ /** * @brief 比较两个参数是否相同 * - * @param baseParam 表示指向被比较的参数的指针。 - * @param param 表示指向比较的参数的指针。 + * @param baseParam 表示被比较的参数。 + * @param param 表示比较的参数。 * @return 返回执行的状态代码。 * @since 9 * @version 1.0 -- Gitee