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 43extern "C" { 44#endif 45 46/** 47 * @brief Crypto data struct. 48 * 49 * @since 12 50 */ 51typedef 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 */ 63typedef 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 /** Indicates that crypto operation error. */ 73 CRYPTO_OPERTION_ERROR = 17630001, 74} OH_Crypto_ErrCode; 75 76/** 77 * @brief Define crypto cipher mode. 78 * 79 * @since 12 80 */ 81typedef enum { 82 /** Indicates encryption operation. */ 83 CRYPTO_ENCRYPT_MODE = 0, 84 /** Indicates decryption operation. */ 85 CRYPTO_DECRYPT_MODE = 1, 86} Crypto_CipherMode; 87 88/** 89 * @brief Free the data of dataBlob. 90 * 91 * @param dataBlob Indicates the data blob. 92 * @since 12 93 */ 94void OH_Crypto_FreeDataBlob(Crypto_DataBlob *dataBlob); 95 96#ifdef __cplusplus 97} 98#endif 99 100/** @} */ 101#endif /* CRYPTO_COMMON_H */