mirror of
https://gitee.com/openharmony/interface_sdk_c
synced 2024-11-23 06:39:54 +00:00
增加算法库Public C Api 头文件
Signed-off-by: lcc <lichaochen@huawei.com>
This commit is contained in:
parent
6c369e6bd5
commit
ea6d5613f4
42
CryptoArchitectureKit/BUILD.gn
Normal file
42
CryptoArchitectureKit/BUILD.gn
Normal file
@ -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.ndk.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",
|
||||
]
|
||||
}
|
51
CryptoArchitectureKit/crypto_architecture_kit.h
Normal file
51
CryptoArchitectureKit/crypto_architecture_kit.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @kit CryptoArchitectureKit
|
||||
* @syscap SystemCapability.Security.CryptoFramework
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_ARCHITECTURE_KIT_H
|
||||
#define CRYPTO_ARCHITECTURE_KIT_H
|
||||
|
||||
#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*/
|
267
CryptoArchitectureKit/crypto_asym_key.h
Normal file
267
CryptoArchitectureKit/crypto_asym_key.h
Normal file
@ -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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup CryptoAsymKeyApi
|
||||
* @{
|
||||
*
|
||||
* @brief Describe the features provided by the openHarmony asymmetric key related interface for applications.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file crypto_asym_key.h
|
||||
*
|
||||
* @brief Defines the AsymKey APIs.
|
||||
*
|
||||
* @library libohcrypto.so
|
||||
* @kit CryptoArchitectureKit
|
||||
* @syscap SystemCapability.Security.CryptoFramework
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_ASYM_KEY_H
|
||||
#define CRYPTO_ASYM_KEY_H
|
||||
|
||||
#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 the 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 the encoding type.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
typedef enum {
|
||||
/** PEM format */
|
||||
CRYPTO_PEM = 0,
|
||||
/** DER format */
|
||||
CRYPTO_DER = 1,
|
||||
} Crypto_EncodingType;
|
||||
|
||||
/**
|
||||
* @brief Define the 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_Convert(OH_CryptoAsymKeyGenerator *ctx, Crypto_EncodingType 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode OH_CryptoPubKey_Encode(OH_CryptoPubKey *key, Crypto_EncodingType 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode OH_CryptoPubKey_GetParam(OH_CryptoPubKey *key, CryptoAsymKey_ParamType item, Crypto_DataBlob *value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif /* CRYPTO_ASYM_KEY_H */
|
101
CryptoArchitectureKit/crypto_common.h
Normal file
101
CryptoArchitectureKit/crypto_common.h
Normal file
@ -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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup CryptoCommonApi
|
||||
* @{
|
||||
*
|
||||
* @brief Describe openHarmony crypto common interfaces provide for applications.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file crypto_common.h
|
||||
*
|
||||
* @brief Defines the crypto common APIs.
|
||||
*
|
||||
* @library libohcrypto.so
|
||||
* @kit CryptoArchitectureKit
|
||||
* @syscap SystemCapability.Security.CryptoFramework
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_COMMON_H
|
||||
#define CRYPTO_COMMON_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Crypto data struct.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
typedef struct Crypto_DataBlob {
|
||||
/** Data buffer. */
|
||||
uint8_t *data;
|
||||
/** Data length. */
|
||||
size_t len;
|
||||
} Crypto_DataBlob;
|
||||
|
||||
/**
|
||||
* @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_MEMORY_ERROR = 17620001,
|
||||
/** Indicates that crypto operation error. */
|
||||
CRYPTO_OPERTION_ERROR = 17630001,
|
||||
} OH_Crypto_ErrCode;
|
||||
|
||||
/**
|
||||
* @brief Define crypto cipher mode.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
typedef enum {
|
||||
/** Indicates encryption operation. */
|
||||
CRYPTO_ENCRYPT_MODE = 0,
|
||||
/** Indicates decryption operation. */
|
||||
CRYPTO_DECRYPT_MODE = 1,
|
||||
} Crypto_CipherMode;
|
||||
|
||||
/**
|
||||
* @brief Free the data of dataBlob.
|
||||
*
|
||||
* @param dataBlob Indicates the data blob.
|
||||
* @since 12
|
||||
*/
|
||||
void OH_Crypto_FreeDataBlob(Crypto_DataBlob *dataBlob);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif /* CRYPTO_COMMON_H */
|
136
CryptoArchitectureKit/crypto_digest.h
Normal file
136
CryptoArchitectureKit/crypto_digest.h
Normal file
@ -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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup CryptoDigestApi
|
||||
* @{
|
||||
*
|
||||
* @brief Describe openHarmony digest interfaces provide for applications.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file crypto_digest.h
|
||||
*
|
||||
* @brief Defines the digest APIs.
|
||||
*
|
||||
* @library libohcrypto.so
|
||||
* @kit CryptoArchitectureKit
|
||||
* @syscap SystemCapability.Security.CryptoFramework
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_DIGEST_H
|
||||
#define CRYPTO_DIGEST_H
|
||||
|
||||
#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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @see OH_CryptoDigest_Final
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @see OH_CryptoDigest_Update
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
void OH_DigestCrypto_Destroy(OH_CryptoDigest *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif /* CRYPTO_DIGEST_H */
|
203
CryptoArchitectureKit/crypto_signature.h
Normal file
203
CryptoArchitectureKit/crypto_signature.h
Normal file
@ -0,0 +1,203 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup CryptoSignatureApi
|
||||
* @{
|
||||
*
|
||||
* @brief Describe openHarmony signature verification interfaces provide for applications.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file crypto_signature.h
|
||||
*
|
||||
* @brief Defines the Signature APIs.
|
||||
*
|
||||
* @library libohcrypto.so
|
||||
* @kit CryptoArchitectureKit
|
||||
* @syscap SystemCapability.Security.CryptoFramework
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_SIGNATURE_H
|
||||
#define CRYPTO_SIGNATURE_H
|
||||
|
||||
#include "crypto_common.h"
|
||||
#include "crypto_asym_key.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @see OH_CryptoVerify_Update
|
||||
* @see OH_CryptoVerify_Final
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @see OH_CryptoVerify_Init
|
||||
* @see OH_CryptoVerify_Final
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode OH_CryptoVerify_Update(OH_CryptoVerify *ctx, Crypto_DataBlob *in);
|
||||
|
||||
/**
|
||||
* @brief Used to verify the message.
|
||||
*
|
||||
* @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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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 /* CRYPTO_SIGNATURE_H */
|
203
CryptoArchitectureKit/crypto_sym_cipher.h
Normal file
203
CryptoArchitectureKit/crypto_sym_cipher.h
Normal file
@ -0,0 +1,203 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup CryptoSymCipherApi
|
||||
* @{
|
||||
*
|
||||
* @brief Describe the functions provided by the openHarmony symmetric key encryption
|
||||
* and decryption interface for applications.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file crypto_sym_cipher.h
|
||||
*
|
||||
* @brief Defines the symmetric key cipher APIs.
|
||||
*
|
||||
* @library libohcrypto.so
|
||||
* @kit CryptoArchitectureKit
|
||||
* @syscap SystemCapability.Security.CryptoFramework
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_SYM_CIPHER_H
|
||||
#define CRYPTO_SYM_CIPHER_H
|
||||
|
||||
#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_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_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_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_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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.
|
||||
*
|
||||
* @param algoName Indicates the algorithm name used to generate the symmetric key cipher context.
|
||||
* Example AES128|GCM|PKCS7.
|
||||
* @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_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_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_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_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @see OH_CryptoSymCipher_Update
|
||||
* @see OH_CryptoSymCipher_Final
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_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_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @see OH_CryptoSymCipher_Init
|
||||
* @see OH_CryptoSymCipher_Final
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_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_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @see OH_CryptoSymCipher_Init
|
||||
* @see OH_CryptoSymCipher_Update
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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 /* CRYPTO_SYM_CIPHER_H */
|
156
CryptoArchitectureKit/crypto_sym_key.h
Normal file
156
CryptoArchitectureKit/crypto_sym_key.h
Normal file
@ -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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup CryptoSymKeyApi
|
||||
* @{
|
||||
*
|
||||
* @brief Describe openHarmony symmetric key related features interfaces provide for applications.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file crypto_sym_key.h
|
||||
*
|
||||
* @brief Defines the symmetric key APIs.
|
||||
*
|
||||
* @library libohcrypto.so
|
||||
* @kit CryptoArchitectureKit
|
||||
* @syscap SystemCapability.Security.CryptoFramework
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_SYM_KEY_H
|
||||
#define CRYPTO_SYM_KEY_H
|
||||
|
||||
#include "crypto_common.h"
|
||||
|
||||
#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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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_MEMORY_ERROR} 17620001 - If memory operation failed.
|
||||
* {@link OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR} 17630001 - If crypto opertion failed.
|
||||
* @since 12
|
||||
*/
|
||||
OH_Crypto_ErrCode 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 /* CRYPTO_SYM_KEY_H */
|
170
CryptoArchitectureKit/libcrypto.ndk.json
Normal file
170
CryptoArchitectureKit/libcrypto.ndk.json
Normal file
@ -0,0 +1,170 @@
|
||||
[
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_CryptoAsymKeyGenerator_Create"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_CryptoAsymKeyGenerator_Generate"
|
||||
},
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user