diff --git a/CryptoArchitectureKit/BUILD.gn b/CryptoArchitectureKit/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..07f0288abc191d7f4cae603149daae256e483c87 --- /dev/null +++ b/CryptoArchitectureKit/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (C) 2024 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. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") + +ohos_ndk_headers("crypto_capi_header") { + dest_dir = "$ndk_headers_out_dir/CryptoArchitectureKit" + sources = [ + "./crypto_asym_key.h", + "./crypto_common.h", + "./crypto_digest.h", + "./crypto_signature.h", + "./crypto_sym_cipher.h", + "./crypto_sym_key.h", + ] +} + +ohos_ndk_library("libohcrypto") { + output_name = "ohcrypto" + output_extension = "so" + ndk_description_file = "./libcrypto_capi.json" + system_capability = "SystemCapability.Security.CryptoFramework" + system_capability_headers = [ + "CryptoArchitectureKit/crypto_asym_key.h", + "CryptoArchitectureKit/crypto_common.h", + "CryptoArchitectureKit/crypto_digest.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 new file mode 100644 index 0000000000000000000000000000000000000000..c5502a3eeaedbc91d49ee46a1b120683cb72f0d9 --- /dev/null +++ b/CryptoArchitectureKit/crypto_architecture_kit.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2024 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. + */ + +#ifndef CRYPTO_ARCHITECTURE_KIT_H +#define CRYPTO_ARCHITECTURE_KIT_H + +/** + * @addtogroup CryptoArchitectureKit + * @{ + * + * @brief Provides an entry to the crypto header files for you to reference. + * + * @syscap SystemCapability.Security.CryptoFramework + * @since 12 + */ + +/** + * @file crypto_architecture_kit.h + * + * @brief Provides an entry to the crypto header files for you to reference. + * + * @library libohcrypto.so + * @syscap SystemCapability.Security.CryptoFramework + * @since 12 + */ + +#include "crypto_asym_key.h" +#include "crypto_common.h" +#include "crypto_digest.h" +#include "crypto_signature.h" +#include "crypto_sym_cipher.h" +#include "crypto_sym_key.h" + + +/** @} */ + + +#endif /* CRYPTO_ARCHITECTURE_KIT_H*/ \ No newline at end of file diff --git a/CryptoArchitectureKit/crypto_asym_key.h b/CryptoArchitectureKit/crypto_asym_key.h new file mode 100644 index 0000000000000000000000000000000000000000..9877e4fb73a5e63e5f9e9a110160b24b96bbf039 --- /dev/null +++ b/CryptoArchitectureKit/crypto_asym_key.h @@ -0,0 +1,267 @@ +/* + * Copyright (C) 2024 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. + */ + +#ifndef ASYM_KEY_H +#define ASYM_KEY_H + +/** + * @addtogroup CryptoAsymKeyApi + * @{ + * + * @brief Describe the features provided by the openHarmony asymmetric key related interface for applications. + * + * @since 12 + */ + +/** + * @file asym_key.h + * + * @brief Defines the AsymKey APIs. + * + * @library libohcrypto.z.so + * @kit Crypto Architecture Kit + * @syscap SystemCapability.Security.CryptoFramework + * @since 12 + */ + +#include "crypto_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define the key pair structure. + * + * @since 12 + */ +typedef struct OH_CryptoKeyPair OH_CryptoKeyPair; + +/** + * @brief Define the public Key structure. + * + * @since 12 + */ +typedef struct OH_CryptoPubKey OH_CryptoPubKey; + +/** + * @brief Define asymmetric key parameter types. + * + * @since 12 + */ +typedef enum { + /** Indicates the DSA prime p. */ + CRYPTO_DSA_P_DATABLOB = 101, + /** Indicates the DSA sub-prime q. */ + CRYPTO_DSA_Q_DATABLOB = 102, + /** Indicates the DSA base g. */ + CRYPTO_DSA_G_DATABLOB = 103, + /** Indicates the DSA private key. */ + CRYPTO_DSA_SK_DATABLOB = 104, + /** Indicates the DSA public key. */ + CRYPTO_DSA_PK_DATABLOB = 105, + + /** Indicates the prime p of an elliptic curve (EC) prime finite field. */ + CRYPTO_ECC_FP_P_DATABLOB = 201, + /** Indicates the first coefficient a of this elliptic curve. */ + CRYPTO_ECC_A_DATABLOB = 202, + /** Indicates the second coefficient b of this elliptic curve. */ + CRYPTO_ECC_B_DATABLOB = 203, + /** Indicates the affine x-coordinate of base point g. */ + CRYPTO_ECC_G_X_DATABLOB = 204, + /** Indicates the affine y-coordinate of base point g. */ + CRYPTO_ECC_G_Y_DATABLOB = 205, + /** Indicates the order of the base point g. */ + CRYPTO_ECC_N_DATABLOB = 206, + /** Indicates the cofactor of the elliptic curve. */ + CRYPTO_ECC_H_INT = 207, + /** Indicates the private value of the ECC private key. */ + CRYPTO_ECC_SK_DATABLOB = 208, + /** Indicates the affine x-coordinate of a point, which is the public point of an ECC public key. */ + CRYPTO_ECC_PK_X_DATABLOB = 209, + /** Indicates the affine y-coordinate of a point, which is the public point of an ECC public key. */ + CRYPTO_ECC_PK_Y_DATABLOB = 210, + /** Indicates an elliptic curve finite field type. */ + CRYPTO_ECC_FIELD_TYPE_STR = 211, + /** Indicates the field size in bits. */ + CRYPTO_ECC_FIELD_SIZE_INT = 212, + /** Indicates the curve name according to SECG (Standards for Efficient Cryptography Group). */ + CRYPTO_ECC_CURVE_NAME_STR = 213, + + /** Indicates the modulus n of RSA algorithm. */ + CRYPTO_RSA_N_DATABLOB = 301, + /** Indicates the private exponent d of RSA algorithm. */ + CRYPTO_RSA_D_DATABLOB = 302, + /** Indicates the public exponent e of RSA algorithm. */ + CRYPTO_RSA_E_DATABLOB = 303, + + /** Indicates the prime p of DH algorithm. */ + CRYPTO_DH_P_DATABLOB = 401, + /** Indicates the generator g of DH algorithm. */ + CRYPTO_DH_G_DATABLOB = 402, + /** Indicates the number of bits of the private key length used in the DH algorithm. */ + CRYPTO_DH_L_INT = 403, + /** Indicates the private value of the DH private key. */ + CRYPTO_DH_SK_DATABLOB = 404, + /** Indicates the public value of the DH public key. */ + CRYPTO_DH_PK_DATABLOB = 405, + + /** Indicates the private value of the ED25519 private key. */ + CRYPTO_ED25519_SK_DATABLOB = 501, + /** Indicates the public value of the ED25519 public key. */ + CRYPTO_ED25519_PK_DATABLOB = 502, + /** Indicates the private value of the X25519 private key. */ + CRYPTO_X25519_SK_DATABLOB = 601, + /** Indicates the public value of the X25519 public key. */ + CRYPTO_X25519_PK_DATABLOB = 602, +} CryptoAsymKey_ParamType; + +/** + * @brief Define encoding format. + * + * @since 12 + */ +typedef enum { + /** PEM format */ + CRYPTO_PEM = 0, + /** DER format */ + CRYPTO_DER = 1, +} Crypto_Encoding_type; + +/** + * @brief Define asymmetric key generator structure. + * + * @since 12 + */ +typedef struct OH_CryptoAsymKeyGenerator OH_CryptoAsymKeyGenerator; + +/** + * @brief Create an asymmetric key generator according to the given algorithm name. + * + * @param algoName Indicates the algorithm name for generating the generator. Example RSA1024|PRIMES_2. + * @param ctx Indicates the pointer to asymmetric key generator context. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoAsymKeyGenerator_Create(const char *algoName, OH_CryptoAsymKeyGenerator **ctx); + +/** + * @brief Generate an asymmetric key(a key pair). + * + * @param ctx Indicates the asymmetric key generator context. + * @param keyCtx Indicates the pointer to the asyKey context. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoAsymKeyGenerator_Generate(OH_CryptoAsymKeyGenerator *ctx, OH_CryptoKeyPair **keyCtx); + +/** + * @brief Convert the asymmetric key data to a key pair. + * + * @param ctx Indicates the asymmetric key generator context. + * @param type Indicates the encryption encoding type. + * @param pubKeyData Indicates the public key data. + * @param priKeyData Indicates the private key data. + * @param keyCtx Indicates the pointer to the keyPair instance. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoAsymKeyGenerator_Convert(OH_CryptoAsymKeyGenerator *ctx, Crypto_Encoding_type type, + Crypto_DataBlob *pubKeyData, Crypto_DataBlob *priKeyData, OH_CryptoKeyPair **keyCtx); + +/** + * @brief Get the algorithm name of the asymmetric key generator. + * + * @param ctx Indicates the asymmetric key generator context. + * @return Returns the asymmetric key algorithm name. + * @since 12 + */ +const char *OH_CryptoAsymKeyGenerator_GetAlgoName(OH_CryptoAsymKeyGenerator *ctx); + +/** + * @brief Destroy the asymmetric key generator. + * + * @param ctx Indicates the asymmetric key generator context. + * @since 12 + */ +void OH_CryptoAsymKeyGenerator_Destroy(OH_CryptoAsymKeyGenerator *ctx); + +/** + * @brief Destroy the key pair. + * + * @param keyCtx Indicates the keyPair context. + * @since 12 + */ +void OH_CryptoKeyPair_Destroy(OH_CryptoKeyPair *keyCtx); + +/** + * @brief Get the public key of the key pair. + * + * @param keyCtx Indicates the keyPair context. + * @return Return the public key context from the key pair. + * @since 12 + */ +OH_CryptoPubKey *OH_CryptoKeyPair_GetPubKey(OH_CryptoKeyPair *keyCtx); + +/** + * @brief Encode the public key. + * + * @param key Indicates the public key. + * @param type Indicates the pubkey type. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoPubKey_Encode(OH_CryptoPubKey *key, Crypto_Encoding_type type, + const char *encodingStandard, Crypto_DataBlob *out); + +/** + * @brief Get the specified param of the public key. + * + * @param key Indicates the public 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_INVALID_PARAMS} 401 - If parameter is invalid. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoPubKey_GetParam(OH_CryptoPubKey *key, CryptoAsymKey_ParamType item, Crypto_DataBlob *value); + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif /* ASYM_KEY_H*/ diff --git a/CryptoArchitectureKit/crypto_common.h b/CryptoArchitectureKit/crypto_common.h new file mode 100644 index 0000000000000000000000000000000000000000..736c86119da2845118f5ec5447e14c95f643f9fc --- /dev/null +++ b/CryptoArchitectureKit/crypto_common.h @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2024 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. + */ + +#ifndef CRYPTO_COMMON_H +#define CRYPTO_COMMON_H + +/** + * @addtogroup CryptoCommonApi + * @{ + * + * @brief Describe openHarmony common interfaces provide for applications. + * + * @since 12 + */ + +/** + * @file crypto_common.h + * + * @brief Defines the crypto common APIs. + * + * @library libohcrypto.z.so + * @kit Crypto Architecture Kit + * @syscap SystemCapability.Security.CryptoFramework + * @since 12 + */ + +#include +#include + +/** + * @brief Crypto data struct. + * + * @since 12 + */ +typedef struct Crypto_DataBlob { + /** Crypto data. */ + uint8_t *data; + /** Data length. */ + size_t len; +} Crypto_DataBlob; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerates the error codes. + * + * @since 12 + */ +typedef enum { + /** Indicates that crypto operation success. */ + CRYPTO_SUCCESS = 0, + /** Indicates that input parameters is invalid. */ + CRYPTO_INVALID_PARAMS = 401, + /** Indicates that function or algorithm is not supported. */ + CRYPTO_NOT_SUPPORTED = 801, + /** Indicates the memory error. */ + CRYPTO_ERR_MALLOC = 17620001, + /** Indicates that crypto operation error. */ + CRYPTO_ERR_CRYPTO_OPERTION = 17630001, +} Crypto_Result; + +/** + * @brief Define crypto cipher mode. + * + * @since 12 + */ +typedef enum { + /** The value of encryption operation. */ + CRYPTO_ENCRYPT_MODE = 0, + /** The value of decryption operation. */ + CRYPTO_DECRYPT_MODE = 1, +} Crypto_CipherMode; + +/** + * @brief Free the data of dataBlob. + * + * @param dataBlob Indicates the crypto data. + * @since 12 + */ +void OH_Crypto_FreeDataBlob(Crypto_DataBlob *dataBlob); + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif /* CRYPTO_COMMON_H */ \ No newline at end of file diff --git a/CryptoArchitectureKit/crypto_digest.h b/CryptoArchitectureKit/crypto_digest.h new file mode 100644 index 0000000000000000000000000000000000000000..4b3cd8185e2b00c48a3e7309de237ea7572dcea3 --- /dev/null +++ b/CryptoArchitectureKit/crypto_digest.h @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2024 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. + */ + +#ifndef DIGEST_H +#define DIGEST_H + +/** + * @addtogroup CryptoDigestApi + * @{ + * + * @brief Describe openHarmony digest interfaces provide for applications. + * + * @since 12 + */ + +/** + * @file digest.h + * + * @brief Defines the digest apis. + * + * @library libohcrypto.z.so + * @kit Crypto Architecture Kit + * @syscap SystemCapability.Security.CryptoFramework + * @since 12 + */ + +#include "crypto_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define the digest structure. + * + * @since 12 + */ +typedef struct OH_CryptoDigest OH_CryptoDigest; + +/** + * @brief Create a digest context according to the given algorithm name. + * + * @param algoName Indicates the algorithm name for generating the digest context. Example SHA256. + * @param ctx Indicates the pointer to the md context. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoDigest_Create(const char *algoName, OH_CryptoDigest **ctx); + +/** + * @brief Update digest with dataBlob. + * + * @param ctx Indicates the digest context. + * @param in Indicates the dataBlob. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @see OH_CryptoDigest_Final + * @since 12 + */ +Crypto_Result OH_CryptoDigest_Update(OH_CryptoDigest *ctx, Crypto_DataBlob *in); + +/** + * @brief Final digest with dataBlob. + * + * @param ctx Indicates the digest context. + * @param out Indicates the result as dataBlob. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @see OH_CryptoDigest_Update + * @since 12 + */ +Crypto_Result OH_CryptoDigest_Final(OH_CryptoDigest *ctx, Crypto_DataBlob *out); + +/** + * @brief Get the digest length of the digest context. + * + * @param ctx Indicates the digest context. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +uint32_t OH_CryptoDigest_GetLength(OH_CryptoDigest *ctx); + +/** + * @brief Get the algorithm name of the digest context. + * + * @param ctx Indicates the digest context. + * @return Return md algorithm name. + * @since 12 + */ +const char *OH_CryptoDigest_GetAlgoName(OH_CryptoDigest *ctx); + +/** + * @brief Destroy the digest context. + * + * @param ctx Indicates the digest context. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +void OH_DigestCrypto_Destroy(OH_CryptoDigest *ctx); + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif /* DIGEST_H */ \ No newline at end of file diff --git a/CryptoArchitectureKit/crypto_signature.h b/CryptoArchitectureKit/crypto_signature.h new file mode 100644 index 0000000000000000000000000000000000000000..10e9990cd9b92ae9936ae05404de2e54f99af451 --- /dev/null +++ b/CryptoArchitectureKit/crypto_signature.h @@ -0,0 +1,200 @@ +/* + * Copyright (C) 2024 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. + */ + +#ifndef SIGNATURE_H +#define SIGNATURE_H + +/** + * @addtogroup CryptoSignatureApi + * @{ + * + * @brief Describe openHarmony signature verification interfaces provide for applications. + * + * @since 12 + */ + +/** + * @file signature.h + * + * @brief Defines the Signature APIs. + * + * @library libohcrypto.z.so + * @kit Crypto Architecture Kit + * @syscap SystemCapability.Security.CryptoFramework + * @since 12 + */ + +#include "crypto_common.h" +#include "crypto_asym_key.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define the signature param type. + * + * @since 12 + */ +typedef enum { + /** Indicates the algorithm name of the message digest function.*/ + CRYPTO_PSS_MD_NAME_STR = 100, + /** Indicates the algorithm name for the mask generation function. */ + CRYPTO_PSS_MGF_NAME_STR = 101, + /** Indicates the message digest parameter for the MGF1 mask generation function. */ + CRYPTO_PSS_MGF1_NAME_STR = 102, + /** Indicates the salt length in bits */ + CRYPTO_PSS_SALT_LEN_INT = 103, + /** Indicates the value for the trailer field */ + CRYPTO_PSS_TRAILER_FIELD_INT = 104, + /** Indicates the value for user id */ + CRYPTO_SM2_USER_ID_DATABLOB = 105, +} CryptoSignature_ParamType; + +/** + * @brief Define the verify structure. + * + * @since 12 + */ +typedef struct OH_CryptoVerify OH_CryptoVerify; + +/** + * @brief Create a verify context according to the given algorithm name. + * + * @param algoName Indicates the algorithm name for generating the verify context. Example RSA1024|PKCS1|SHA256. + * @param ctx Indicates the pointer to the verify context. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoVerify_Create(const char *algoName, OH_CryptoVerify **verify); + +/** + * @brief Init verify context with given public Key. + * + * @param ctx Indicates the verify context. + * @param pubKey indicates the public Key + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @see OH_CryptoVerify_Update + * @see OH_CryptoVerify_Final + * @since 12 + */ +Crypto_Result OH_CryptoVerify_Init(OH_CryptoVerify *ctx, OH_CryptoPubKey *pubKey); + +/** + * @brief Used to append the message that needs to be verified. + * + * @param ctx Indicates the verify context. + * @param in Indicates the data need to be verified. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @see OH_CryptoVerify_Init + * @see OH_CryptoVerify_Final + * @since 12 + */ +Crypto_Result OH_CryptoVerify_Update(OH_CryptoVerify *ctx, Crypto_DataBlob *in); + +/** + * @brief Used to verify message, include the update data. + * + * @param ctx Indicates the verify context. + * @param in Indicates the data need to be verified. + * @param signData Indicates the signature data. + * @return Return result use bool value. + * @see OH_CryptoVerify_Init + * @see OH_CryptoVerify_Update + * @since 12 + */ +bool OH_CryptoVerify_Final(OH_CryptoVerify *ctx, Crypto_DataBlob *in, Crypto_DataBlob *signData); + +/** + * @brief Used to recover signed data. + * + * @param ctx Indicates the verify context. + * @param signData Indicates the signature data. + * @param rawSignData Indicates the raw sign data. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoVerify_Recover(OH_CryptoVerify *ctx, Crypto_DataBlob *signData, Crypto_DataBlob *rawSignData); + +/** + * @brief Get the algorithm name of the verify context. + * + * @param ctx Indicates the verify context. + * @return Return verify algorithm name. + * @since 12 + */ +const char *OH_CryptoVerify_GetAlgoName(OH_CryptoVerify *ctx); + +/** + * @brief Set the specified parameter to the verify context. + * + * @param ctx Indicates the verify context. + * @param type Indicates the verify signature_paramType. + * @param value Indicates the verify 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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoVerify_SetParam(OH_CryptoVerify *ctx, CryptoSignature_ParamType type, Crypto_DataBlob *value); + +/** + * @brief Get the specified parameter from the verify context. + * + * @param ctx Indicates the verify context. + * @param type Indicates the verify signature_paramType. + * @param value Indicates the verify 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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoVerify_GetParam(OH_CryptoVerify *ctx, CryptoSignature_ParamType type, Crypto_DataBlob *value); + +/** + * @brief Destroy the verify context. + * + * @param ctx Indicates the verify context. + * @since 12 + */ +void OH_CryptoVerify_Destroy(OH_CryptoVerify *ctx); + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif /* SIGNATURE_H */ diff --git a/CryptoArchitectureKit/crypto_sym_cipher.h b/CryptoArchitectureKit/crypto_sym_cipher.h new file mode 100644 index 0000000000000000000000000000000000000000..cbc66e7af2f5fff5c1698896431fbe7b79612e77 --- /dev/null +++ b/CryptoArchitectureKit/crypto_sym_cipher.h @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2024 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. + */ + +#ifndef SYM_CIPHER_H +#define SYM_CIPHER_H + +/** + * @addtogroup CryptoSymCipherApi + * @{ + * + * @brief Describe the functions provided by the openHarmony symmetric key encryption + * and decryption interface for applications. + * + * @since 12 + */ + +/** + * @file sym_cipher.h + * + * @brief Defines the symmetric key cipher APIs. + * + * @library libohcrypto.z.so + * @kit Crypto Architecture Kit + * @syscap SystemCapability.Security.CryptoFramework + * @since 12 + */ + +#include "crypto_common.h" +#include "crypto_sym_key.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define the cipher param type. + * + * @since 12 + */ +typedef enum { + /** Indicates the parameters such as iv. */ + CRYPTO_IV_DATABLOB = 100, + /** Indicates the additional Authenticated Data in GCM mode. */ + CRYPTO_AAD_DATABLOB = 101, + /** Indicates the output tag from the encryption operation. The tag is used for integrity check. */ + CRYPTO_TAG_DATABLOB = 102, +} CryptoSymCipher_ParamsType; + +/** + * @brief Define the symmetric key cipher structure. + * + * @since 12 + */ +typedef struct OH_CryptoSymCipher OH_CryptoSymCipher; + +/** + * @brief Define the symmetric key cipher params structure. + * + * @since 12 + */ +typedef struct OH_CryptoSymCipherParams OH_CryptoSymCipherParams; + +/** + * @brief Create a symmetric key cipher params. + * + * @param params Indicates the pointer to the cipher params context. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORT} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoSymCipherParams_Create(OH_CryptoSymCipherParams **params); + +/** + * @brief Set a parameter to the cipher params context. + * + * @param params Indicates the parameters context. + * @param paramsType Set cipher parameters. + * @param value Indicates the setParam 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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORT} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoSymCipherParams_SetParam(OH_CryptoSymCipherParams *params, + CryptoSymCipher_ParamsType paramsType, Crypto_DataBlob *value); + +/** + * @brief Destroy the cipher params context. + * + * @param params Indicates the parameters context. + * @since 12 + */ +void OH_CryptoSymCipherParams_Destroy(OH_CryptoSymCipherParams *params); + +/** + * @brief Create a symmetric key cipher context according to the given algorithm name. Example AES128|GCM|PKCS7. + * + * @param algoName Indicates the algorithm name used to generate the symmetric key cipher context. + * @param ctx Indicates the pointer to the symmetric key cipher context. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORT} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoSymCipher_Create(const char *algoName, OH_CryptoSymCipher **ctx); + +/** + * @brief Init the crypto operation with the given crypto mode, key and parameters. + * + * @param ctx Indicates the symmetric key cipher context. + * @param mod Indicates the crypto mode is encryption or decryption. + * @param key Indicates the symmetric key or the asymmetric key. + * @param params Indicates the algorithm parameters such as IV. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORT} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @see OH_CryptoSymCipher_Update + * @see OH_CryptoSymCipher_Final + * @since 12 + */ +Crypto_Result OH_CryptoSymCipher_Init(OH_CryptoSymCipher *ctx, Crypto_CipherMode mod, + OH_CryptoSymKey *key, OH_CryptoSymCipherParams *params); + +/** + * @brief Update the crypto operation with the input data, and feed back the encrypted or decrypted data. + * + * @param ctx Indicates the symmetric key cipher context. + * @param in Indicates the data to be encrypted or decrypted. + * @param out Indicates the data to be update encrypted or decrypted. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORT} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @see OH_CryptoSymCipher_Init + * @see OH_CryptoSymCipher_Final + * @since 12 + */ +Crypto_Result OH_CryptoSymCipher_Update(OH_CryptoSymCipher *ctx, Crypto_DataBlob *in, Crypto_DataBlob *out); + +/** + * @brief Finish the crypto operation, encrypt or decrypt the input data, and then feed back the output data. + * + * @param ctx Indicates the symmetric key cipher context. + * @param in Indicates the data to be encrypted or decrypted. + * @param out Indicates the data to be finally encrypted or decrypted. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORT} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @see OH_CryptoSymCipher_Init + * @see OH_CryptoSymCipher_Update + * @since 12 + */ +Crypto_Result OH_CryptoSymCipher_Final(OH_CryptoSymCipher *ctx, Crypto_DataBlob *in, Crypto_DataBlob *out); + +/** + * @brief Get the algorithm name of the symmetric key cipher context. + * + * @param ctx Indicates the symmetric key context. + * @return Return symmetric key cipher algorithm name. + * @since 12 + */ +const char *OH_CryptoSymCipher_GetAlgoName(OH_CryptoSymCipher *ctx); + +/** + * @brief Destroy the symmetric key cipher context. + * + * @param ctx Indicates the symmetric key context. + * @since 12 + */ +void OH_CryptoSymCipher_Destroy(OH_CryptoSymCipher *ctx); + + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif /* SYM_CIPHER_H */ diff --git a/CryptoArchitectureKit/crypto_sym_key.h b/CryptoArchitectureKit/crypto_sym_key.h new file mode 100644 index 0000000000000000000000000000000000000000..2743805715824c7f3260728e3a463222cc0dbf4a --- /dev/null +++ b/CryptoArchitectureKit/crypto_sym_key.h @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2024 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. + */ + +#ifndef SYM_KEY_H +#define SYM_KEY_H + +#include "crypto_common.h" + +/** + * @addtogroup CryptoSymKeyApi + * @{ + * + * @brief Describe openHarmony symmetric key related features interfaces provide for applications. + * + * @since 12 + */ + +/** + * @file sym_key.h + * + * @brief Defines the symmetric key APIs. + * + * @library libohcrypto.z.so + * @kit Crypto Architecture Kit + * @syscap SystemCapability.Security.CryptoFramework + * @since 12 + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define the symmetric key structure. + * + * @since 12 + */ +typedef struct OH_CryptoSymKey OH_CryptoSymKey; + +/** + * @brief Define the symmetric key generator structure. + * + * @since 12 + */ +typedef struct OH_CryptoSymKeyGenerator OH_CryptoSymKeyGenerator; + +/** + * @brief Create a symmetric key generator according to the given algorithm name. Example AES256. + * + * @param algoName Indicates the algorithm name for generating the generator. + * @param ctx Indicates the pointer to the symmetric key generator context. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoSymKeyGenerator_Create(const char *algoName, OH_CryptoSymKeyGenerator **ctx); + +/** + * @brief Generate a symmetric key. + * + * @param ctx Indicates the Symmetric key generator context. + * @param keyCtx Indicates the pointer to the symmetric key context. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoSymKeyGenerator_Generate(OH_CryptoSymKeyGenerator *ctx, OH_CryptoSymKey **keyCtx); + +/** + * @brief Convert the symmetric key data to a key. + * + * @param ctx Indicates the symmetric key generator context. + * @param keyData Indicates the data to generate the Symkey. + * @param keyCtx Indicates the pointer to the symmetric key context. + * @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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoSymKeyGenerator_Convert(OH_CryptoSymKeyGenerator *ctx, + const Crypto_DataBlob *keyData, OH_CryptoSymKey **keyCtx); + +/** + * @brief Get the algorithm name of the symmetric key generator. + * + * @param ctx Indicates the symmetric key generator context. + * @return Return symmetric key algorithm name. + * @since 12 + */ +const char *OH_CryptoSymKeyGenerator_GetAlgoName(OH_CryptoSymKeyGenerator *ctx); + +/** + * @brief Destroy the symmetric key generator. + * + * @param ctx Indicates the symmetric key generator context. + * @since 12 + */ +void OH_CryptoSymKeyGenerator_Destroy(OH_CryptoSymKeyGenerator *ctx); + +/** + * @brief Get the symmetric key algorithm name from a symmetric key. + * + * @param keyCtx Indicates the symmetric key context. + * @return Return algorithm name. + * @since 12 + */ +const char *OH_CryptoSymKey_GetAlgoName(OH_CryptoSymKey *keyCtx); + +/** + * @brief Get the symmetric key data from a symmetric key. + * + * @param keyCtx Indicates the symmetric key context. + * @param out Indicate to obtain the 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. + * {@link OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED} 801 - If the operation is not supported. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_MALLOC} 17620001 - If malloc failed. + * {@link OH_Crypto_ErrCode#CRYPTO_ERR_CRYPTO_OPERTION} 17630001 - If crypto opertion failed. + * @since 12 + */ +Crypto_Result OH_CryptoSymKey_GetKeyData(OH_CryptoSymKey *keyCtx, Crypto_DataBlob *out); + +/** + * @brief Destroy the symmetric key. + * + * @param keyCtx Indicates the symmetric key context. + * @since 12 + */ +void OH_CryptoSymKey_Destroy(OH_CryptoSymKey *keyCtx); + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif /* SYM_KEY_H */ diff --git a/CryptoArchitectureKit/libcrypto_capi.json b/CryptoArchitectureKit/libcrypto_capi.json new file mode 100644 index 0000000000000000000000000000000000000000..778c4efa7dac606a45c8c726e2681044c7a64d78 --- /dev/null +++ b/CryptoArchitectureKit/libcrypto_capi.json @@ -0,0 +1,170 @@ +[ + { + "first_introduced": "12", + "name": "OH_CryptoAsymKeyGenerator_Create" + }, + { + "first_introduced": "12", + "name": "OH_CryptoAsymKeyGenerator_Generatey" + }, + { + "first_introduced": "12", + "name": "OH_CryptoAsymKeyGenerator_Convert" + }, + { + "first_introduced": "12", + "name": "OH_CryptoAsymKeyGenerator_GetAlgoName" + }, + { + "first_introduced": "12", + "name": "OH_CryptoAsymKeyGenerator_Destroy" + }, + { + "first_introduced": "12", + "name": "OH_CryptoKeyPair_Destroy" + }, + { + "first_introduced": "12", + "name": "OH_CryptoKeyPair_GetPubKey" + }, + { + "first_introduced": "12", + "name": "OH_CryptoPubKey_Encode" + }, + { + "first_introduced": "12", + "name": "OH_CryptoPubKey_GetParam" + }, + { + "first_introduced": "12", + "name": "OH_Crypto_FreeDataBlob" + }, + { + "first_introduced": "12", + "name": "OH_CryptoDigest_Create" + }, + { + "first_introduced": "12", + "name": "OH_CryptoDigest_Update" + }, + { + "first_introduced": "12", + "name": "OH_CryptoDigest_Final" + }, + { + "first_introduced": "12", + "name": "OH_CryptoDigest_GetLength" + }, + { + "first_introduced": "12", + "name": "OH_CryptoDigest_GetAlgoName" + }, + { + "first_introduced": "12", + "name": "OH_DigestCrypto_Destroy" + }, + { + "first_introduced": "12", + "name": "OH_CryptoVerify_Create" + }, + { + "first_introduced": "12", + "name": "OH_CryptoVerify_Init" + }, + { + "first_introduced": "12", + "name": "OH_CryptoVerify_Update" + }, + { + "first_introduced": "12", + "name": "OH_CryptoVerify_Final" + }, + { + "first_introduced": "12", + "name": "OH_CryptoVerify_Recover" + }, + { + "first_introduced": "12", + "name": "OH_CryptoVerify_GetAlgoName" + }, + { + "first_introduced": "12", + "name": "OH_CryptoVerify_SetParam" + }, + { + "first_introduced": "12", + "name": "OH_CryptoVerify_GetParam" + }, + { + "first_introduced": "12", + "name": "OH_CryptoVerify_Destroy" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymCipherParams_Create" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymCipherParams_SetParam" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymCipherParams_Destroy" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymCipher_Create" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymCipher_Init" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymCipher_Update" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymCipher_Final" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymCipher_GetAlgoName" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymCipher_Destroy" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymKeyGenerator_Create" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymKeyGenerator_Generate" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymKeyGenerator_Convert" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymKeyGenerator_GetAlgoName" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymKeyGenerator_Destroy" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymKey_GetAlgoName" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymKey_GetKeyData" + }, + { + "first_introduced": "12", + "name": "OH_CryptoSymKey_Destroy" + } +]