From 6cace7fe8a9ba0d81eff8b2bbc493738b4778a7e Mon Sep 17 00:00:00 2001 From: zzh593245631 Date: Thu, 10 Apr 2025 17:40:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AE=97=E6=B3=95=E5=BA=93Pu?= =?UTF-8?q?blic=20C=20Api=20=E5=A4=B4=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zzh --- CryptoArchitectureKit/BUILD.gn | 10 + .../crypto_architecture_kit.h | 5 + CryptoArchitectureKit/crypto_asym_cipher.h | 205 ++++++++++ CryptoArchitectureKit/crypto_asym_key.h | 365 +++++++++++++++++- CryptoArchitectureKit/crypto_common.h | 2 + CryptoArchitectureKit/crypto_kdf.h | 173 +++++++++ CryptoArchitectureKit/crypto_key_agreement.h | 97 +++++ CryptoArchitectureKit/crypto_mac.h | 170 ++++++++ CryptoArchitectureKit/crypto_rand.h | 114 ++++++ CryptoArchitectureKit/crypto_signature.h | 21 +- CryptoArchitectureKit/libcrypto.ndk.json | 206 +++++++++- 11 files changed, 1351 insertions(+), 17 deletions(-) create mode 100644 CryptoArchitectureKit/crypto_asym_cipher.h create mode 100644 CryptoArchitectureKit/crypto_kdf.h create mode 100644 CryptoArchitectureKit/crypto_key_agreement.h create mode 100644 CryptoArchitectureKit/crypto_mac.h create mode 100644 CryptoArchitectureKit/crypto_rand.h diff --git a/CryptoArchitectureKit/BUILD.gn b/CryptoArchitectureKit/BUILD.gn index 509347a9a..d59e65555 100644 --- a/CryptoArchitectureKit/BUILD.gn +++ b/CryptoArchitectureKit/BUILD.gn @@ -18,9 +18,14 @@ ohos_ndk_headers("crypto_capi_header") { dest_dir = "$ndk_headers_out_dir/CryptoArchitectureKit" sources = [ "./crypto_architecture_kit.h", + "./crypto_asym_cipher.h", "./crypto_asym_key.h", "./crypto_common.h", "./crypto_digest.h", + "./crypto_kdf.h", + "./crypto_key_agreement.h", + "./crypto_mac.h", + "./crypto_rand.h", "./crypto_signature.h", "./crypto_sym_cipher.h", "./crypto_sym_key.h", @@ -34,9 +39,14 @@ ohos_ndk_library("libohcrypto") { system_capability = "SystemCapability.Security.CryptoFramework" system_capability_headers = [ "CryptoArchitectureKit/crypto_architecture_kit.h", + "CryptoArchitectureKit/crypto_asym_cipher.h", "CryptoArchitectureKit/crypto_asym_key.h", "CryptoArchitectureKit/crypto_common.h", "CryptoArchitectureKit/crypto_digest.h", + "CryptoArchitectureKit/crypto_kdf.h", + "CryptoArchitectureKit/crypto_key_agreement.h", + "CryptoArchitectureKit/crypto_mac.h", + "CryptoArchitectureKit/crypto_rand.h", "CryptoArchitectureKit/crypto_signature.h", "CryptoArchitectureKit/crypto_sym_cipher.h", "CryptoArchitectureKit/crypto_sym_key.h", diff --git a/CryptoArchitectureKit/crypto_architecture_kit.h b/CryptoArchitectureKit/crypto_architecture_kit.h index 4580a7506..6ed853395 100644 --- a/CryptoArchitectureKit/crypto_architecture_kit.h +++ b/CryptoArchitectureKit/crypto_architecture_kit.h @@ -38,8 +38,13 @@ #define CRYPTO_ARCHITECTURE_KIT_H #include "crypto_common.h" +#include "crypto_asym_cipher.h" #include "crypto_asym_key.h" #include "crypto_digest.h" +#include "crypto_kdf.h" +#include "crypto_key_agreement.h" +#include "crypto_mac.h" +#include "crypto_rand.h" #include "crypto_signature.h" #include "crypto_sym_cipher.h" #include "crypto_sym_key.h" diff --git a/CryptoArchitectureKit/crypto_asym_cipher.h b/CryptoArchitectureKit/crypto_asym_cipher.h new file mode 100644 index 000000000..d6ab30721 --- /dev/null +++ b/CryptoArchitectureKit/crypto_asym_cipher.h @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2025 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 CryptoAsymCipherApi + * @{ + * + * @brief Describes the asymmetric encryption and decryption algorithm interface provided to applications. + * + * @since 20 + */ + +/** + * @file crypto_asym_cipher.h + * + * @brief Defines the asymmetric cipher APIs. + * + * @library libohcrypto.so + * @kit CryptoArchitectureKit + * @syscap SystemCapability.Security.CryptoFramework + * @since 20 + */ + +#ifndef CRYPTO_ASYM_CIPHER_H +#define CRYPTO_ASYM_CIPHER_H + +#include "crypto_common.h" +#include "crypto_asym_key.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines the asymmetric cipher structure. + * + * @since 20 + */ +typedef struct OH_CryptoAsymCipher OH_CryptoAsymCipher; + +/** + * @brief Creates an asymmetric cipher context according to the given algorithm name. + * + * @param algoName Indicates the algorithm name used to generate the asymmetric cipher context. e.g. "RSA|PKCS1", + * "RSA|PKCS1_OAEP|SHA384|MGF1_SHA384", "SM2|SM3". + * @param ctx Indicates the pointer to the asymmetric cipher context. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoAsymCipher_Create(const char *algoName, OH_CryptoAsymCipher **ctx); + +/** + * @brief Initializes the asymmetric cipher context with the given crypto mode, key and parameters. + * + * @param ctx Indicates the asymmetric cipher context. + * @param mode Indicates the crypto mode is encryption or decryption. + * @param key Indicates the asymmetric key. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @see OH_CryptoAsymCipher_Final + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoAsymCipher_Init(OH_CryptoAsymCipher *ctx, Crypto_CipherMode mode, OH_CryptoKeyPair *key); + +/** + * @brief Finalizes the encryption or decryption operation. + * + * @param ctx Indicates the asymmetric cipher context. + * @param in Indicates the input data to be encrypted or decrypted. + * @param out Indicates the result of encryption or decryption. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @see OH_CryptoAsymCipher_Init + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoAsymCipher_Final(OH_CryptoAsymCipher *ctx, const Crypto_DataBlob *in, + Crypto_DataBlob *out); + +/** + * @brief Destroys the asymmetric cipher context. + * + * @param ctx Indicates the asymmetric cipher context. + */ +void OH_CryptoAsymCipher_Destroy(OH_CryptoAsymCipher *ctx); + +/** + * @brief Defines the SM2 ciphertext spec structure. + * + * @since 20 + */ +typedef struct OH_CryptoSm2CiphertextSpec OH_CryptoSm2CiphertextSpec; + +/** + * @brief Defines the SM2 ciphertext spec item type. + * + * @since 20 + */ +typedef enum { + /** Public key x, also known as C1x. */ + CRYPTO_SM2_CIPHERTEXT_C1_X = 0, + /** Public key y, also known as C1y. */ + CRYPTO_SM2_CIPHERTEXT_C1_Y = 1, + /** Hash, also known as C2. */ + CRYPTO_SM2_CIPHERTEXT_C2 = 2, + /** Ciphertext data, also known as C3. */ + CRYPTO_SM2_CIPHERTEXT_C3 = 3, +} CryptoSm2CiphertextSpec_item; + +/** + * @brief Creates a SM2 ciphertext spec. + * + * @param sm2Ciphertext Indicates the SM2 ciphertext in DER format, if sm2Ciphertext param is NULL, + * an empty SM2 ciphertext spec will be created. + * @param spec Indicates the output SM2 ciphertext spec. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoSm2CiphertextSpec_Create(Crypto_DataBlob *sm2Ciphertext, OH_CryptoSm2CiphertextSpec **spec); + +/** + * @brief Gets the specified item of the SM2 ciphertext. + * + * @param spec Indicates the SM2 ciphertext spec. + * @param item Indicates the SM2 ciphertext spec item. + * @param out Indicates the output data. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoSm2CiphertextSpec_GetItem(OH_CryptoSm2CiphertextSpec *spec, + CryptoSm2CiphertextSpec_item item, Crypto_DataBlob *out); + +/** + * @brief Sets the specified item to the SM2 ciphertext spec. + * + * @param spec Indicates the SM2 ciphertext spec. + * @param item Indicates the SM2 ciphertext spec item. + * @param in Indicates the input data. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoSm2CiphertextSpec_SetItem(OH_CryptoSm2CiphertextSpec *spec, + CryptoSm2CiphertextSpec_item item, Crypto_DataBlob *in); + +/** + * @brief Encodes the SM2 ciphertext spec to ciphertext in DER format. + * + * @param spec Indicates the SM2 ciphertext spec. + * @param out Indicates the output data. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoSm2CiphertextSpec_Encode(OH_CryptoSm2CiphertextSpec *spec, Crypto_DataBlob *out); + +/** + * @brief Destroys the SM2 ciphertext spec. + * + * @param spec Indicates the SM2 ciphertext spec. + * @since 20 + */ +void OH_CryptoSm2CiphertextSpec_Destroy(OH_CryptoSm2CiphertextSpec *spec); + +#ifdef __cplusplus +} +#endif + +#endif /* CRYPTO_ASYM_CIPHER_H */ +/** @} */ diff --git a/CryptoArchitectureKit/crypto_asym_key.h b/CryptoArchitectureKit/crypto_asym_key.h index 857e691ff..4997e5e55 100644 --- a/CryptoArchitectureKit/crypto_asym_key.h +++ b/CryptoArchitectureKit/crypto_asym_key.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -50,14 +50,14 @@ extern "C" { typedef struct OH_CryptoKeyPair OH_CryptoKeyPair; /** - * @brief Define the public Key structure. + * @brief Define the public key structure. * * @since 12 */ typedef struct OH_CryptoPubKey OH_CryptoPubKey; /** - * @brief Define the private Key structure. + * @brief Defines the private key structure. * * @since 20 */ @@ -235,7 +235,7 @@ void OH_CryptoKeyPair_Destroy(OH_CryptoKeyPair *keyCtx); OH_CryptoPubKey *OH_CryptoKeyPair_GetPubKey(OH_CryptoKeyPair *keyCtx); /** - * @brief Get the private key of the key pair. + * @brief Gets the private key of the key pair. * * @param keyCtx Indicates the keyPair context. * @return Return the private key context from the key pair. @@ -248,7 +248,7 @@ OH_CryptoPrivKey *OH_CryptoKeyPair_GetPrivKey(OH_CryptoKeyPair *keyCtx); * * @param key Indicates the public key. * @param type Indicates the pubkey type. - * @param encodingStandard Indicates the encoding standard . + * @param encodingStandard Indicates the encoding standard. * @param out Indicates the encoded result. * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS} 401 - If parameter is invalid. @@ -275,6 +275,361 @@ OH_Crypto_ErrCode OH_CryptoPubKey_Encode(OH_CryptoPubKey *key, Crypto_EncodingTy */ OH_Crypto_ErrCode OH_CryptoPubKey_GetParam(OH_CryptoPubKey *key, CryptoAsymKey_ParamType item, Crypto_DataBlob *value); +/** + * @brief Sets the password to the asymmetric key generator context. + * + * Call this method to set the password if you need to convert encrypted private key data to a key pair using + * {@link OH_CryptoAsymKeyGenerator_Convert} + * + * @param ctx Indicates the asymmetric key generator context. + * @param password Indicates the password. + * @param passwordLen Indicates the password length. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_SetPassword(OH_CryptoAsymKeyGenerator *ctx, const unsigned char *password, + uint32_t passwordLen); + +/** + * @brief Defines the private key encoding params structure. + * + * @since 20 + */ +typedef struct OH_CryptoPrivKeyEncodingParams OH_CryptoPrivKeyEncodingParams; + +/** + * @brief Defines the private key encoding param type. + * + * @since 20 + */ +typedef enum { + /** Indicates the password string. */ + CRYPTO_PRIVATE_KEY_ENCODING_PASSWORD_STR = 0, + + /** Indicates the symmetric cipher string. */ + CRYPTO_PRIVATE_KEY_ENCODING_SYMMETRIC_CIPHER_STR = 1, +} CryptoPrivKeyEncoding_ParamType; + +/** + * @brief Creates private key encoding params. + * + * @param ctx Indicates the private key encoding params. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoPrivKeyEncodingParams_Create(OH_CryptoPrivKeyEncodingParams **ctx); + +/** + * @brief Sets the private key encoding params. + * + * @param ctx Indicates the private key encoding params. + * @param type Indicates the private key encoding param type. + * @param value Indicates the private key encoding params value. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoPrivKeyEncodingParams_SetParam(OH_CryptoPrivKeyEncodingParams *ctx, + CryptoPrivKeyEncoding_ParamType type, Crypto_DataBlob *value); + +/** + * @brief Destroys the private key encoding params. + * + * @param ctx Indicates the private key encoding params. + * @since 20 + */ +void OH_CryptoPrivKeyEncodingParams_Destroy(OH_CryptoPrivKeyEncodingParams *ctx); + +/** + * @brief Encodes the private key. + * + * @param key Indicates the private key. + * @param type Indicates the private encoding type. + * @param encodingStandard Indicates the encoding standard, such as "PKCS8". + * @param params Indicates the private key encoding params, it can be NULL, and if you want encypt the private key, + * you should set this param. + * @param out Indicates the encoded result. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoPrivKey_Encode(OH_CryptoPrivKey *key, Crypto_EncodingType type, + const char *encodingStandard, OH_CryptoPrivKeyEncodingParams *params, Crypto_DataBlob *out); + +/** + * @brief Gets the specified param of the private key. + * + * @param key Indicates the private key. + * @param item Indicates the asymmetric key param type. + * @param value Indicates the output data. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoPrivKey_GetParam(OH_CryptoPrivKey *key, CryptoAsymKey_ParamType item, + Crypto_DataBlob *value); + +/** + * @brief Defines the asymmetric key spec structure. + * + * @since 20 + */ +typedef struct OH_CryptoAsymKeySpec OH_CryptoAsymKeySpec; + +/** + * @brief Defines the asymmetric key spec type. + * + * @since 20 + */ +typedef enum { + /** Common parameters spec. */ + CRYPTO_ASYM_KEY_COMMON_PARAMS_SPEC = 0, + /** Private key spec. */ + CRYPTO_ASYM_KEY_PRIVATE_KEY_SPEC = 1, + /** Public key spec. */ + CRYPTO_ASYM_KEY_PUBLIC_KEY_SPEC = 2, + /** Key pair spec. */ + CRYPTO_ASYM_KEY_KEY_PAIR_SPEC = 3, +} CryptoAsymKeySpec_Type; + +/** + * @brief Generates an EC common parameters spec. + * + * @param curveName Indicates the ECC curve name. + * @param spec Indicates the pointer to the EC common parameters spec. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoAsymKeySpec_GenEcCommonParamsSpec(const char *curveName, OH_CryptoAsymKeySpec **spec); + +/** + * @brief Generates a DH common parameters spec. + * + * @param pLen Indicates the byte length of the prime p. + * @param skLen Indicates the byte length of the private key. + * @param spec Indicates the pointer to the DH common parameters spec. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoAsymKeySpec_GenDhCommonParamsSpec(int pLen, int skLen, OH_CryptoAsymKeySpec **spec); + +/** + * @brief Creates an asymmetric key spec according to the given algorithm name and spec type. + * + * @param algoName Indicates the algorithm name for generating the spec. Example RSA. + * @param type Indicates the asymmetric key spec type. + * @param spec Indicates the pointer to the asymmetric key spec. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoAsymKeySpec_Create(const char *algoName, CryptoAsymKeySpec_Type type, + OH_CryptoAsymKeySpec **spec); + +/** + * @brief Sets the specified parameter to the asymmetric key spec. + * + * @param spec Indicates the asymmetric key spec. + * @param type Indicates the asymmetric key param type. + * @param value Indicates the input data. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoAsymKeySpec_SetParam(OH_CryptoAsymKeySpec *spec, CryptoAsymKey_ParamType type, + Crypto_DataBlob *value); + +/** + * @brief Sets the common parameters spec to the asymmetric key spec. + * + * @param spec Indicates the asymmetric key spec. + * @param commonParamsSpec Indicates the common parameters spec. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoAsymKeySpec_SetCommonParamsSpec(OH_CryptoAsymKeySpec *spec, + OH_CryptoAsymKeySpec *commonParamsSpec); + +/** + * @brief Gets the specified parameter from the asymmetric key spec. + * + * @param spec Indicates the asymmetric key spec. + * @param type Indicates the asymmetric key param type. + * @param value Indicates the output data. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoAsymKeySpec_GetParam(OH_CryptoAsymKeySpec *spec, CryptoAsymKey_ParamType type, + Crypto_DataBlob *value); + +/** + * @brief Destroys the asymmetric key spec. + * + * @param spec Indicates the asymmetric key spec. + * @since 20 + */ +void OH_CryptoAsymKeySpec_Destroy(OH_CryptoAsymKeySpec *spec); + +/** + * @brief Defines the asymmetric key generator with spec. + * + * @since 20 + */ +typedef struct OH_CryptoAsymKeyGeneratorWithSpec OH_CryptoAsymKeyGeneratorWithSpec; + +/** + * @brief Creates an asymmetric key generator with spec. + * + * @param keySpec Indicates the asymmetric key spec. + * @param generator Indicates the asymmetric key generator with spec. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoAsymKeyGeneratorWithSpec_Create(OH_CryptoAsymKeySpec *keySpec, + OH_CryptoAsymKeyGeneratorWithSpec **generator); + +/** + * @brief Generates a key pair according to the asymmetric key spec. + * + * @param generator Indicates the asymmetric key generator with spec. + * @param keyPair Indicates the pointer to the key pair. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoAsymKeyGeneratorWithSpec_GenKeyPair(OH_CryptoAsymKeyGeneratorWithSpec *generator, + OH_CryptoKeyPair **keyPair); + +/** + * @brief Destroys the asymmetric key generator with spec. + * + * @param generator Indicates the asymmetric key generator with spec. + * @since 20 + */ +void OH_CryptoAsymKeyGeneratorWithSpec_Destroy(OH_CryptoAsymKeyGeneratorWithSpec *generator); + +/** + * @brief Defines the EC point structure. + * + * @since 20 + */ +typedef struct OH_CryptoEcPoint OH_CryptoEcPoint; + +/** + * @brief Creates an EC point. + * + * @param curveName Indicates the curve name. + * @param ecKeyData Indicates the EC point data, supports "04 || x || y", "02 || x" or "03 || x" format. + * If ecKeyData param is NULL, an empty EC point spec will be created. + * @param point Indicates the pointer to the EC point. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoEcPoint_Create(const char *curveName, Crypto_DataBlob *ecKeyData, OH_CryptoEcPoint **point); + +/** + * @brief Gets the x and y coordinate of the EC point. + * + * @param point Indicates the EC point. + * @param x Indicates the x coordinate of the EC point, it can be NULL. + * @param y Indicates the y coordinate of the EC point, it can be NULL. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoEcPoint_GetCoordinate(OH_CryptoEcPoint *point, Crypto_DataBlob *x, Crypto_DataBlob *y); + +/** + * @brief Sets the x and y coordinate to the EC point. + * + * @param point Indicates the EC point. + * @param x Indicates the x coordinate of the EC point. + * @param y Indicates the y coordinate of the EC point. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoEcPoint_SetCoordinate(OH_CryptoEcPoint *point, Crypto_DataBlob *x, Crypto_DataBlob *y); + +/** + * @brief Encodes the EC point to the specified format. + * + * @param point Indicates the EC point. + * @param format Indicates the encoding format, supports "UNCOMPRESSED" and "COMPRESSED". + * @param out Indicates the encoded ec point data. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoEcPoint_Encode(OH_CryptoEcPoint *point, const char *format, Crypto_DataBlob *out); + +/** + * @brief Destroys the EC point. + * + * @param point Indicates the EC point. + * @since 20 + */ +void OH_CryptoEcPoint_Destroy(OH_CryptoEcPoint *point); + #ifdef __cplusplus } #endif diff --git a/CryptoArchitectureKit/crypto_common.h b/CryptoArchitectureKit/crypto_common.h index 8122dc51c..36a3c1b4f 100644 --- a/CryptoArchitectureKit/crypto_common.h +++ b/CryptoArchitectureKit/crypto_common.h @@ -69,6 +69,8 @@ typedef enum { CRYPTO_NOT_SUPPORTED = 801, /** Indicates the memory error. */ CRYPTO_MEMORY_ERROR = 17620001, + /** Indicates that parameter check failed. */ + CRYPTO_PARAMETER_CHECK_FAILED = 17620003, /** Indicates that crypto operation error. */ CRYPTO_OPERTION_ERROR = 17630001, } OH_Crypto_ErrCode; diff --git a/CryptoArchitectureKit/crypto_kdf.h b/CryptoArchitectureKit/crypto_kdf.h new file mode 100644 index 000000000..afa02bc37 --- /dev/null +++ b/CryptoArchitectureKit/crypto_kdf.h @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2025 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 CryptoKdfApi + * @{ + * + * @brief Describes the KDF algorithm interface provided to applications. + * + * @since 20 + */ + +/** + * @file crypto_kdf.h + * + * @brief Defines the KDF APIs. + * + * @library libohcrypto.so + * @kit CryptoArchitectureKit + * @syscap SystemCapability.Security.CryptoFramework + * @since 20 + */ + +#ifndef CRYPTO_KDF_H +#define CRYPTO_KDF_H + +#include "crypto_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines the KDF structure. + * + * @since 20 + */ +typedef struct OH_CryptoKdf OH_CryptoKdf; + +/** + * @brief Defines the KDF params structure. + * + * @since 20 + */ +typedef struct OH_CryptoKdfParams OH_CryptoKdfParams; + +/** + * @brief Defines the KDF param type. + * + * @since 20 + */ +typedef enum { + /** Indicates the key or password for KDF. */ + CRYPTO_KDF_KEY_DATABLOB = 0, + + /** Indicates the salt for KDF. */ + CRYPTO_KDF_SALT_DATABLOB = 1, + + /** Indicates the info for KDF. */ + CRYPTO_KDF_INFO_DATABLOB = 2, + + /** Indicates the iteration count for PBKDF2. */ + CRYPTO_KDF_ITER_COUNT_INT = 3, + + /** Indicates the n for SCRYPT KDF. */ + CRYPTO_KDF_SCRYPT_N_UINT64 = 4, + + /** Indicates the r for SCRYPT KDF. */ + CRYPTO_KDF_SCRYPT_R_UINT64 = 5, + + /** Indicates the p for SCRYPT KDF. */ + CRYPTO_KDF_SCRYPT_P_UINT64 = 6, + + /** Indicates the max memory for SCRYPT KDF. */ + CRYPTO_KDF_SCRYPT_MAX_MEM_UINT64 = 7, +} CryptoKdf_ParamType; + +/** + * @brief Creates KDF params. + * + * @param algoName Indicates the KDF algorithm name. e.g. "HKDF", "PBKDF2", "SCRYPT". + * @param params Indicates the KDF params. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoKdfParams_Create(const char *algoName, OH_CryptoKdfParams **params); + +/** + * @brief Sets a parameter to the KDF parameters. + * + * @param params Indicates the KDF parameters. + * @param type Indicates the KDF parameter type. + * @param value Indicates the KDF parameter value. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoKdfParams_SetParam(OH_CryptoKdfParams *params, CryptoKdf_ParamType type, + Crypto_DataBlob *value); + +/** + * @brief Destroys the KDF params. + * + * @param params Indicates the KDF parameters. + * @since 20 + */ +void OH_CryptoKdfParams_Destroy(OH_CryptoKdfParams *params); + +/** + * @brief Creates a KDF context. + * + * @param algoName Indicates the KDF algorithm name. e.g. "HKDF|SHA384|EXTRACT_AND_EXPAND", "PBKDF2|SHA384", "SCRYPT". + * @param ctx Indicates the KDF context. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoKdf_Create(const char *algoName, OH_CryptoKdf **ctx); + +/** + * @brief Derives a key. + * + * @param ctx The KDF context. + * @param params Indicates the KDF parameters. + * @param keyLen Indicates the key derivation length. + * @param key Indicates the derived key. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoKdf_Derive(OH_CryptoKdf *ctx, const OH_CryptoKdfParams *params, int keyLen, + Crypto_DataBlob *key); + +/** + * @brief Destroys the KDF context. + * + * @param ctx The KDF context. + * @since 20 + */ +void OH_CryptoKdf_Destroy(OH_CryptoKdf *ctx); + + +#ifdef __cplusplus +} +#endif + +#endif /* CRYPTO_KDF_H */ +/** @} */ diff --git a/CryptoArchitectureKit/crypto_key_agreement.h b/CryptoArchitectureKit/crypto_key_agreement.h new file mode 100644 index 000000000..2b011c409 --- /dev/null +++ b/CryptoArchitectureKit/crypto_key_agreement.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2025 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 CryptoKeyAgreementApi + * @{ + * + * @brief Describes key agreement algorithm interface provided to applications. + * + * @since 20 + */ + +/** + * @file crypto_key_agreement.h + * + * @brief Defines the key agreement APIs. + * + * @library libohcrypto.so + * @kit CryptoArchitectureKit + * @syscap SystemCapability.Security.CryptoFramework + * @since 20 + */ + +#ifndef CRYPTO_KEY_AGREEMENT_H +#define CRYPTO_KEY_AGREEMENT_H + +#include "crypto_common.h" +#include "crypto_asym_key.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines the key agreement structure. + * + * @since 20 + */ +typedef struct OH_CryptoKeyAgreement OH_CryptoKeyAgreement; + +/** + * @brief Creates a key agreement context according to the given algorithm name. + * + * @param algoName Indicates the algorithm name used to generate a key agreement context. e.g. "ECC", "X25519". + * @param ctx Indicates the key agreement context. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoKeyAgreement_Create(const char *algoName, OH_CryptoKeyAgreement **ctx); + +/** + * @brief Generates a secret value. + * + * @param ctx Indicates the key agreement context. + * @param privkey Indicates the private key. + * @param pubkey Indicates the public key. + * @param secret Indicates the secret value. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoKeyAgreement_GenerateSecret(OH_CryptoKeyAgreement *ctx, OH_CryptoPrivKey *privkey, + OH_CryptoPubKey *pubkey, Crypto_DataBlob *secret); + +/** + * @brief Destroys the key agreement context. + * + * @param ctx Indicates the key agreement context. + * @since 20 + */ +void OH_CryptoKeyAgreement_Destroy(OH_CryptoKeyAgreement *ctx); + +#ifdef __cplusplus +} +#endif + +#endif /* CRYPTO_KEY_AGREEMENT_H */ +/** @} */ diff --git a/CryptoArchitectureKit/crypto_mac.h b/CryptoArchitectureKit/crypto_mac.h new file mode 100644 index 000000000..24d3c9939 --- /dev/null +++ b/CryptoArchitectureKit/crypto_mac.h @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2025 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 CryptoMacApi + * @{ + * + * @brief Describes the MAC algorithm interface provided to applications. + * + * @since 20 + */ + +/** + * @file crypto_mac.h + * + * @brief Defines the MAC algorithm APIs. + * + * @library libohcrypto.so + * @kit CryptoArchitectureKit + * @syscap SystemCapability.Security.CryptoFramework + * @since 20 + */ + +#ifndef CRYPTO_MAC_H +#define CRYPTO_MAC_H + +#include "crypto_common.h" +#include "crypto_sym_key.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines the MAC structure. + * + * @since 20 + */ +typedef struct OH_CryptoMac OH_CryptoMac; + +/** + * @brief Defines the MAC algorithm parameter type. + * + * @since 20 + */ +typedef enum { + /** Indicates the algorithm name of the message digest function for HMAC. e.g. "SHA256".*/ + CRYPTO_MAC_DIGEST_NAME_STR = 0, + + /** Indicates the algorithm name of the symmetric cipher function for CMAC. e.g. "AES256".*/ + CRYPTO_MAC_CIPHER_NAME_STR = 1, +} CryptoMac_ParamType; + +/** + * @brief Creates a MAC context according to the given algorithm name. + * + * @param algoName Indicates the algorithm name for generating the MAC context. e.g. "HMAC", "CMAC". + * @param ctx Indicates the pointer to the MAC context. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoMac_Create(const char *algoName, OH_CryptoMac **ctx); + +/** + * @brief Sets the specified parameter to the MAC context. + * + * @param ctx Indicates the MAC context. + * @param type Indicates the MAC parameter type. + * @param value Indicates the parameter value. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoMac_SetParam(OH_CryptoMac *ctx, CryptoMac_ParamType type, const Crypto_DataBlob *value); + +/** + * @brief Initializes the MAC context with a symmetric key. + * + * @param ctx Indicates the MAC context. + * @param key Indicates the symmetric key. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @see OH_CryptoMac_Update + * @see OH_CryptoMac_Final + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoMac_Init(OH_CryptoMac *ctx, const OH_CryptoSymKey *key); + +/** + * @brief Updates the MAC context with data. + * + * @param ctx Indicates the MAC context. + * @param in Indicates the data to update. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @see OH_CryptoMac_Init + * @see OH_CryptoMac_Final + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoMac_Update(OH_CryptoMac *ctx, const Crypto_DataBlob *in); + +/** + * @brief Finalizes the MAC operation. + * + * @param ctx Indicates the MAC context. + * @param out Indicates the MAC result. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @see OH_CryptoMac_Init + * @see OH_CryptoMac_Update + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoMac_Final(OH_CryptoMac *ctx, Crypto_DataBlob *out); + +/** + * @brief Gets the length of the MAC. + * + * @param ctx Indicates the MAC context. + * @param length Indicates the MAC length. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoMac_GetLength(OH_CryptoMac *ctx, uint32_t *length); + +/** + * @brief Destroys the MAC context. + * + * @param ctx Indicates the MAC context. + * @since 20 + */ +void OH_CryptoMac_Destroy(OH_CryptoMac *ctx); + +#ifdef __cplusplus +} +#endif + +#endif /* CRYPTO_MAC_H */ +/** @} */ diff --git a/CryptoArchitectureKit/crypto_rand.h b/CryptoArchitectureKit/crypto_rand.h new file mode 100644 index 000000000..1e9a4f8e0 --- /dev/null +++ b/CryptoArchitectureKit/crypto_rand.h @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2025 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 CryptoRandApi + * @{ + * + * @brief Describes the random number generation interface provided to applications. + * + * @since 20 + */ +/** + * @file crypto_rand.h + * + * @brief Defines the random number generator APIs. + * + * @library libohcrypto.so + * @kit CryptoArchitectureKit + * @syscap SystemCapability.Security.CryptoFramework + * @since 20 + */ +#ifndef CRYPTO_RAND_H +#define CRYPTO_RAND_H + +#include "crypto_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines the random number generator structure. + * + * @since 20 + */ +typedef struct OH_CryptoRand OH_CryptoRand; + +/** + * @brief Creates a random number generator context. + * + * @param ctx Indicates the random number generator context. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoRand_Create(OH_CryptoRand **ctx); + +/** + * @brief Generates random numbers. + * + * @param ctx Indicates the random number generator context. + * @param len Indicates the byte length of the random number. + * @param out Indicates the output data. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoRand_GenerateRandom(OH_CryptoRand *ctx, int len, Crypto_DataBlob *out); + +/** + * @brief Gets the algorithm name of the random number generator context. + * + * @param ctx Indicates the pointer to the random number generator context. + * @return Return the algorithm name of the random number generator context. + * @since 20 + */ +const char *OH_CryptoRand_GetAlgoName(OH_CryptoRand *ctx); + +/** + * @brief Sets the seed to the random number generator context. + * + * @param ctx Indicates the random number generator context. + * @param seed Indicates the seed. + * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. + * @since 20 + */ +OH_Crypto_ErrCode OH_CryptoRand_SetSeed(OH_CryptoRand *ctx, Crypto_DataBlob *seed); + +/** + * @brief Destroys the random number generator context. + * + * @param ctx Indicates the random number generator context. + * @since 20 + */ +void OH_CryptoRand_Destroy(OH_CryptoRand *ctx); + +#ifdef __cplusplus +} +#endif + +#endif /* CRYPTO_RAND_H */ +/** @} */ diff --git a/CryptoArchitectureKit/crypto_signature.h b/CryptoArchitectureKit/crypto_signature.h index 47df37001..7982b278f 100644 --- a/CryptoArchitectureKit/crypto_signature.h +++ b/CryptoArchitectureKit/crypto_signature.h @@ -210,7 +210,7 @@ void OH_CryptoVerify_Destroy(OH_CryptoVerify *ctx); * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. - * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 1762003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. * @since 20 */ @@ -224,7 +224,7 @@ OH_Crypto_ErrCode OH_CryptoSign_Create(const char *algoName, OH_CryptoSign **sig * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. - * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 1762003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. * @see OH_CryptoSign_Update * @see OH_CryptoSign_Final @@ -240,7 +240,7 @@ OH_Crypto_ErrCode OH_CryptoSign_Init(OH_CryptoSign *ctx, OH_CryptoPrivKey *privK * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. - * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 1762003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. * @see OH_CryptoSign_Init * @see OH_CryptoSign_Final @@ -257,7 +257,7 @@ OH_Crypto_ErrCode OH_CryptoSign_Update(OH_CryptoSign *ctx, const Crypto_DataBlob * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. - * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 1762003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. * @see OH_CryptoSign_Init * @see OH_CryptoSign_Update @@ -283,7 +283,7 @@ const char *OH_CryptoSign_GetAlgoName(OH_CryptoSign *ctx); * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. - * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 1762003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. * @since 20 */ @@ -299,7 +299,7 @@ OH_Crypto_ErrCode OH_CryptoSign_SetParam(OH_CryptoSign *ctx, CryptoSignature_Par * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. - * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 1762003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. * @since 20 */ @@ -329,7 +329,7 @@ typedef struct OH_CryptoEccSignatureSpec OH_CryptoEccSignatureSpec; * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. - * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 1762003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. * @since 20 */ @@ -345,7 +345,7 @@ OH_Crypto_ErrCode OH_CryptoEccSignatureSpec_Create(Crypto_DataBlob *EccSignature * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. - * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 1762003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. * @since 20 */ @@ -361,7 +361,7 @@ OH_Crypto_ErrCode OH_CryptoEccSignatureSpec_GetRAndS(OH_CryptoEccSignatureSpec * * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. - * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 1762003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. * @since 20 */ @@ -376,7 +376,7 @@ OH_Crypto_ErrCode OH_CryptoEccSignatureSpec_SetRAndS(OH_CryptoEccSignatureSpec * * @return {@link OH_Crypto_ErrCode#CRYPTO_SUCCESS} 0 - If the operation is successful. * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. * {@link OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR} 17620001 - If memory operation failed. - * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 1762003 - If parameter check failed. + * {@link OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED} 17620003 - If parameter check failed. * {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto operation failed. * @since 20 */ @@ -397,4 +397,3 @@ void OH_CryptoEccSignatureSpec_Destroy(OH_CryptoEccSignatureSpec *spec); /** @} */ #endif /* CRYPTO_SIGNATURE_H */ - \ No newline at end of file diff --git a/CryptoArchitectureKit/libcrypto.ndk.json b/CryptoArchitectureKit/libcrypto.ndk.json index f3655799d..76e050848 100644 --- a/CryptoArchitectureKit/libcrypto.ndk.json +++ b/CryptoArchitectureKit/libcrypto.ndk.json @@ -169,7 +169,207 @@ }, { "first_introduced": "20", - "name": "OH_CryptoKeyPair_GetPriKey" + "name": "OH_CryptoAsymCipher_Create" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymCipher_Init" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymCipher_Final" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymCipher_Destroy" + }, + { + "first_introduced": "20", + "name": "OH_CryptoSm2CiphertextSpec_Create" + }, + { + "first_introduced": "20", + "name": "OH_CryptoSm2CiphertextSpec_GetItem" + }, + { + "first_introduced": "20", + "name": "OH_CryptoSm2CiphertextSpec_SetItem" + }, + { + "first_introduced": "20", + "name": "OH_CryptoSm2CiphertextSpec_Encode" + }, + { + "first_introduced": "20", + "name": "OH_CryptoSm2CiphertextSpec_Destroy" + }, + { + "first_introduced": "20", + "name": "OH_CryptoKeyPair_GetPrivKey" + }, + { + "first_introduced": "20", + "name": "OH_CryptoPrivKeyEncodingParams_Create" + }, + { + "first_introduced": "20", + "name": "OH_CryptoPrivKeyEncodingParams_SetParam" + }, + { + "first_introduced": "20", + "name": "OH_CryptoPrivKeyEncodingParams_Destroy" + }, + { + "first_introduced": "20", + "name": "OH_CryptoPrivKey_Encode" + }, + { + "first_introduced": "20", + "name": "OH_CryptoPrivKey_GetParam" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymKeySpec_GenEcCommonParamsSpec" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymKeySpec_GenDhCommonParamsSpec" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymKeySpec_Create" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymKeySpec_SetParam" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymKeySpec_SetCommonParamsSpec" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymKeySpec_GetParam" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymKeySpec_Destroy" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymKeyGeneratorWithSpec_Create" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymKeyGeneratorWithSpec_GenKeyPair" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymKeyGeneratorWithSpec_Destroy" + }, + { + "first_introduced": "20", + "name": "OH_CryptoEcPoint_Create" + }, + { + "first_introduced": "20", + "name": "OH_CryptoEcPoint_GetCoordinate" + }, + { + "first_introduced": "20", + "name": "OH_CryptoEcPoint_SetCoordinate" + }, + { + "first_introduced": "20", + "name": "OH_CryptoEcPoint_Encode" + }, + { + "first_introduced": "20", + "name": "OH_CryptoEcPoint_Destroy" + }, + { + "first_introduced": "20", + "name": "OH_CryptoKdfParams_Create" + }, + { + "first_introduced": "20", + "name": "OH_CryptoKdfParams_SetParam" + }, + { + "first_introduced": "20", + "name": "OH_CryptoKdfParams_Destroy" + }, + { + "first_introduced": "20", + "name": "OH_CryptoKdf_Create" + }, + { + "first_introduced": "20", + "name": "OH_CryptoKdf_Derive" + }, + { + "first_introduced": "20", + "name": "OH_CryptoKdf_Destroy" + }, + { + "first_introduced": "20", + "name": "OH_CryptoKeyAgreement_Create" + }, + { + "first_introduced": "20", + "name": "OH_CryptoKeyAgreement_GenerateSecret" + }, + { + "first_introduced": "20", + "name": "OH_CryptoKeyAgreement_Destroy" + }, + { + "first_introduced": "20", + "name": "OH_CryptoMac_Create" + }, + { + "first_introduced": "20", + "name": "OH_CryptoMac_SetParam" + }, + { + "first_introduced": "20", + "name": "OH_CryptoMac_Init" + }, + { + "first_introduced": "20", + "name": "OH_CryptoMac_Update" + }, + { + "first_introduced": "20", + "name": "OH_CryptoMac_Final" + }, + { + "first_introduced": "20", + "name": "OH_CryptoMac_GetLength" + }, + { + "first_introduced": "20", + "name": "OH_CryptoMac_Destroy" + }, + { + "first_introduced": "20", + "name": "OH_CryptoRand_Create" + }, + { + "first_introduced": "20", + "name": "OH_CryptoRand_GenerateRandom" + }, + { + "first_introduced": "20", + "name": "OH_CryptoRand_GetAlgoName" + }, + { + "first_introduced": "20", + "name": "OH_CryptoRand_SetSeed" + }, + { + "first_introduced": "20", + "name": "OH_CryptoRand_Destroy" }, { "first_introduced": "20", @@ -222,5 +422,9 @@ { "first_introduced": "20", "name": "OH_CryptoEccSignatureSpec_Destroy" + }, + { + "first_introduced": "20", + "name": "OH_CryptoAsymKeyGenerator_SetPassword" } ] -- Gitee