1 /* 2 * This file is part of the openHiTLS project. 3 * 4 * openHiTLS is licensed under the Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * See the Mulan PSL v2 for more details. 14 */ 15 16 #ifndef EAL_CIPHER_LOCAL_H 17 #define EAL_CIPHER_LOCAL_H 18 19 #include "hitls_build.h" 20 #if defined(HITLS_CRYPTO_EAL) && defined(HITLS_CRYPTO_CIPHER) 21 22 #include "crypt_algid.h" 23 #include "crypt_eal_cipher.h" 24 #include "crypt_local_types.h" 25 #ifdef HITLS_CRYPTO_GCM 26 #include "crypt_modes_gcm.h" 27 #endif 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif // __cplusplus 32 33 /** 34 * @ingroup crypt_cipherstates 35 * Symmetry encryption/decryption status */ 36 typedef enum { 37 EAL_CIPHER_STATE_NEW, 38 EAL_CIPHER_STATE_INIT, 39 EAL_CIPHER_STATE_UPDATE, 40 EAL_CIPHER_STATE_FINAL 41 } EAL_CipherStates; 42 43 /** 44 * @ingroup alg map 45 * Symmetric encryption/decryption mode and ID of the encryption algorithm. 46 */ 47 typedef struct { 48 uint32_t id; 49 CRYPT_MODE_AlgId modeId; 50 } EAL_SymAlgMap; 51 52 /** 53 * @ingroup EAL 54 * 55 * CRYPT_CipherInfo: User search algorithm information. Currently, only blockSize is available. 56 */ 57 typedef struct { 58 CRYPT_CIPHER_AlgId id; 59 uint8_t blockSize; 60 uint32_t keyLen; 61 uint32_t ivLen; 62 } CRYPT_CipherInfo; 63 64 /** 65 * @ingroup crypt_eal_cipherctx 66 * Asymmetric algorithm data type */ 67 struct CryptEalCipherCtx { 68 #ifdef HITLS_CRYPTO_PROVIDER 69 bool isProvider; 70 #endif 71 CRYPT_CIPHER_AlgId id; 72 EAL_CipherStates states; /**< record status */ 73 void *ctx; /**< handle of the mode */ 74 EAL_CipherUnitaryMethod *method; /**< method corresponding to the encryption/decryption mode */ 75 }; 76 77 const EAL_SymMethod *EAL_GetSymMethod(int32_t algId); 78 79 /** 80 * @brief Obtain the EAL_CipherMethod based on the algorithm ID. 81 * 82 * @param id [IN] Symmetric encryption/decryption algorithm ID. 83 * @param modeMethod [IN/OUT] EAL_CipherMethod Pointer 84 * @return If it's successful, the system returns CRYPT_SUCCESS and assigns the value to the method in m. 85 * If it's failed, returns CRYPT_EAL_ERR_ALGID: ID of the unsupported algorithm. 86 */ 87 int32_t EAL_FindCipher(CRYPT_CIPHER_AlgId id, const EAL_CipherMethod **modeMethod); 88 89 /** 90 * @brief Obtain keyLen/ivLen/blockSize based on the algorithm ID. 91 * 92 * @param id [IN] Symmetric algorithm ID. 93 * @param id [OUT] Assign the obtained keyLen/ivLen/blockSize to the variable corresponding to info. 94 * 95 * @return Success: CRYPT_SUCCESS 96 * Failure: CRYPT_ERR_ALGID 97 */ 98 int32_t EAL_GetCipherInfo(CRYPT_CIPHER_AlgId id, CRYPT_CipherInfo *info); 99 100 /** 101 * @brief Obtain mode method based on the algorithm ID 102 * 103 * @param id [IN] Symmetric encryption/decryption algorithm ID. 104 * @return If the operation is successful, the combination of ciphers is returned. 105 * If the operation fails, NULL is returned. 106 */ 107 const EAL_CipherMethod *EAL_FindModeMethod(CRYPT_MODE_AlgId id); 108 109 110 #ifdef __cplusplus 111 } 112 #endif // __cplusplus 113 114 #endif // HITLS_CRYPTO_CIPHER 115 116 #endif // EAL_CIPHER_LOCAL_H 117