1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup CryptoCommonApi 18 * @{ 19 * 20 * @brief Describe openHarmony crypto common interfaces provide for applications. 21 * 22 * @since 12 23 */ 24 25 /** 26 * @file crypto_common.h 27 * 28 * @brief Defines the crypto common APIs. 29 * 30 * @library libohcrypto.so 31 * @kit CryptoArchitectureKit 32 * @syscap SystemCapability.Security.CryptoFramework 33 * @since 12 34 */ 35 36 #ifndef CRYPTO_COMMON_H 37 #define CRYPTO_COMMON_H 38 39 #include <stdint.h> 40 #include <stddef.h> 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 /** 47 * @brief Crypto data struct. 48 * 49 * @since 12 50 */ 51 typedef struct Crypto_DataBlob { 52 /** Data buffer. */ 53 uint8_t *data; 54 /** Data length. */ 55 size_t len; 56 } Crypto_DataBlob; 57 58 /** 59 * @brief Enumerates the error codes. 60 * 61 * @since 12 62 */ 63 typedef enum { 64 /** Indicates that crypto operation success. */ 65 CRYPTO_SUCCESS = 0, 66 /** Indicates that input parameters is invalid. */ 67 CRYPTO_INVALID_PARAMS = 401, 68 /** Indicates that function or algorithm is not supported. */ 69 CRYPTO_NOT_SUPPORTED = 801, 70 /** Indicates the memory error. */ 71 CRYPTO_MEMORY_ERROR = 17620001, 72 /** 73 * Indicates that parameter check failed. 74 * @since 20 75 */ 76 CRYPTO_PARAMETER_CHECK_FAILED = 17620003, 77 /** Indicates that crypto operation error. */ 78 CRYPTO_OPERTION_ERROR = 17630001, 79 } OH_Crypto_ErrCode; 80 81 /** 82 * @brief Define crypto cipher mode. 83 * 84 * @since 12 85 */ 86 typedef enum { 87 /** Indicates encryption operation. */ 88 CRYPTO_ENCRYPT_MODE = 0, 89 /** Indicates decryption operation. */ 90 CRYPTO_DECRYPT_MODE = 1, 91 } Crypto_CipherMode; 92 93 /** 94 * @brief Free the data of dataBlob. 95 * 96 * @param dataBlob Indicates the data blob. 97 * @since 12 98 */ 99 void OH_Crypto_FreeDataBlob(Crypto_DataBlob *dataBlob); 100 101 #ifdef __cplusplus 102 } 103 #endif 104 105 /** @} */ 106 #endif /* CRYPTO_COMMON_H */