1 /* 2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 19 #ifndef __CRYP_HASH_H_ 20 #define __CRYP_HASH_H_ 21 22 #include "drv_cipher_kapi.h" 23 #include "drv_hash.h" 24 25 /* Initialize crypto of hash. */ 26 hi_s32 cryp_hash_init(hi_void); 27 28 /* Deinitialize crypto of hash. */ 29 hi_void cryp_hash_deinit(hi_void); 30 31 /* 32 * \brief Create hash handle 33 * 34 * \param mode Hash mode 35 * \return ctx if successful, or NULL 36 */ 37 typedef hi_void *(*func_hash_create)(hash_mode mode); 38 39 /* 40 * \brief Clear hash context 41 * 42 * \param ctx symc handle to be destroy 43 */ 44 typedef hi_s32 (*func_hash_destroy)(hi_void *ctx); 45 46 /* 47 * \brief Hash message chunk calculation 48 * 49 * Note: the message must be write to the buffer 50 * which get from cryp_hash_get_cpu_addr, and the length of message chunk 51 * can't large than the length which get from cryp_hash_get_cpu_addr. 52 * 53 * \param ctx hash handle to be destroy 54 * \param chunk hash message to update 55 * \param length length of hash message 56 * \param src source of hash message 57 */ 58 typedef hi_s32 (*func_hash_update)(hi_void *ctx, const hi_u8 *chunk, hi_u32 chunk_len, hash_chunk_src src); 59 60 /* 61 * \brief HASH final digest 62 * 63 * \param ctx Hash handle 64 * \param hash HASH checksum result 65 * \param hashlen Length of HASH checksum result 66 */ 67 typedef hi_s32 (*func_hash_finish)(hi_void *ctx, hi_void *hash, hi_u32 hash_buf_len, hi_u32 *hashlen); 68 69 /* struct of Hash function template. */ 70 typedef struct { 71 hi_u32 valid; /* valid or not */ 72 hi_u32 mode; /* Mode of Hash */ 73 hi_u32 block_size; /* block size */ 74 hi_u32 size; /* hash output size */ 75 func_hash_create create; /* Create function */ 76 func_hash_destroy destroy; /* destroy function */ 77 func_hash_update update; /* update function */ 78 func_hash_finish finish; /* finish function */ 79 } hash_func; 80 81 /* 82 * \brief Clone the function from template of hash engine. 83 * \param[out] func The struct of function. 84 * \param[in] mode The work mode. 85 * \retval On success, HI_SUCCESS is returned. On error, HI_FAILURE is returned. 86 */ 87 hash_func *cryp_get_hash(hash_mode mode); 88 #endif 89