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 __DRV_HASH_H__ 20 #define __DRV_HASH_H__ 21 22 #include "drv_osal_lib.h" 23 24 /* SHA1, SHA224, SHA256 hash block size */ 25 #define HASH_BLOCK_SIZE_64 64 26 /* SHA384, SHA512 hash block size. */ 27 #define HASH_BLOCK_SIZE_128 128 28 29 /* hash capacity, 0-nonsupport, 1-support */ 30 typedef struct { 31 hi_u32 sha1 : 1; /* Support SHA1 */ 32 hi_u32 sha224 : 1; /* Support SHA224 */ 33 hi_u32 sha256 : 1; /* Support SHA256 */ 34 hi_u32 sha384 : 1; /* Support SHA384 */ 35 hi_u32 sha512 : 1; /* Support SHA512 */ 36 hi_u32 sm3 : 1; /* Support SM3 */ 37 } hash_capacity; 38 39 /* hash mode */ 40 typedef enum { 41 HASH_MODE_SHA1, /* SHA1 */ 42 HASH_MODE_SHA224, /* SHA2 224 */ 43 HASH_MODE_SHA256, /* SHA2 256 */ 44 HASH_MODE_SHA384, /* SHA2 384 */ 45 HASH_MODE_SHA512, /* SHA2 512 */ 46 HASH_MODE_SM3, /* SM3 */ 47 HASH_MODE_COUNT, 48 } hash_mode; 49 50 /* ****************************** API Declaration **************************** */ 51 /* 52 * \brief Initialize the hash module. 53 * \retval On success, HI_SUCCESS is returned. On error, HI_FAILURE is returned. 54 */ 55 hi_s32 drv_hash_init(void); 56 57 /* 58 * \brief Deinitialize the hash module. 59 * \retval On success, HI_SUCCESS is returned. On error, HI_FAILURE is returned. 60 */ 61 hi_s32 drv_hash_deinit(void); 62 63 /* 64 * \brief suspend the hash module. 65 * \retval NA. 66 */ 67 void drv_hash_suspend(void); 68 69 /* 70 * \brief resume the hash module. 71 * \retval NA. 72 */ 73 void drv_hash_resume(void); 74 75 /* 76 * \brief set work params. 77 * \param[in] chn_num The channel number. 78 * \param[in] mode The hash mode. 79 * \param[in] state The hash initial result, length is HASH_RESULT_MAX_SIZE_IN_WORD. 80 * \retval On success, HI_SUCCESS is returned. On error, HI_FAILURE is returned. 81 */ 82 hi_s32 drv_hash_cfg(hi_u32 chn_num, hash_mode mode, const hi_u32 *state); 83 84 /* 85 * \brief start hash calculation. 86 * \param[in] chn_num The channel number. 87 * \param[in] buf_phy The MMZ/SMMU address of in buffer. 88 * \param[in] buf_size The MMZ/SMMU size of in buffer. 89 * \retval On success, HI_SUCCESS is returned. On error, HI_FAILURE is returned. 90 */ 91 hi_s32 drv_hash_start(hi_u32 chn_num, const crypto_mem *mem, hi_u32 buf_size); 92 93 /* 94 * \brief wait running finished. 95 * \param[in] chn_num The channel number. 96 * \param[out] state The hash result. 97 * \param[in] hashLen The length of hash result. 98 * \retval On received interception, HI_TRUE is returned otherwise HI_FALSE is returned. 99 */ 100 hi_s32 drv_hash_wait_done(hi_u32 chn_num, hi_u32 *state); 101 102 /* 103 * \brief reset hash after hash finished. 104 * \param[in] chn_num The channel number. 105 * \retval NA. 106 */ 107 void drv_hash_reset(hi_u32 chn_num); 108 109 /* 110 * \brief get the hash capacity. 111 * \param[out] capacity The hash capacity. 112 * \retval NA. 113 */ 114 void drv_hash_get_capacity(hash_capacity *capacity); 115 #endif 116