1 /*********************************************************************** 2 * Filename : sha1.h 3 * Description : sha1 header file 4 * Author(s) : firmware team 5 * version : V1.0 6 * Modify date : 2020-07-29 7 ***********************************************************************/ 8 #ifndef __SHA1_H__ 9 #define __SHA1_H__ 10 11 #include "ACM32Fxx_HAL.h" 12 /********************************************************** 13 * structure 14 **********************************************************/ 15 //SHA1 context 16 typedef struct { 17 UINT32 state[5]; //state (ABCD) 18 UINT32 count[2]; // number of bits, modulo 2^64 (msb first) 19 uint8_t buffer[64]; // input buffer 20 } SHA1_CTX; 21 22 /************************************************************************** 23 * Function Name : HAL_SHA1_Init 24 * Description : SHA1 initialization. Begins an SHA1 operation, writing a new context. 25 * Input : None 26 * Output : - *context : the point of sha1 context 27 * Return : None 28 **************************************************************************/ 29 void HAL_SHA1_Init(SHA1_CTX *context); 30 31 /************************************************************************** 32 * Function Name : HAL_SHA1_Update 33 * Description : SHA1 block update operation. Continues an SHA1 message-digest 34 * : operation, processing another message block, and updating the 35 * : context. 36 * Input : - *context : context before transform 37 * : - *input : input message 38 * : - inputlen : the byte length of input message 39 * Output : - *context : context after transform 40 * Return : None 41 **************************************************************************/ 42 void HAL_SHA1_Update(SHA1_CTX *context,uint8_t *input,UINT32 inputLen); 43 44 /************************************************************************** 45 * Function Name : HAL_SHA1_Final 46 * Description : SHA1 finalization. Ends an MD5 message-digest operation, writing the 47 * : the message digest and zeroizing the context. 48 * Input : - *context : context before transform 49 * Output : - *digest : message digest 50 * Return : None 51 **************************************************************************/ 52 void HAL_SHA1_Final(uint8_t *digest, SHA1_CTX *context); 53 54 /************************************************************************** 55 * Function Name : HAL_SHA1_Hash 56 * Description : transform message to digest in SHA1 algorithm 57 * Input : - *pDataIn : input message to be tranformed; 58 : - DataLen : the byte length of message; 59 * Output : - *pDigest : output the digest; 60 * Return : None 61 **************************************************************************/ 62 void HAL_SHA1_Hash(uint8_t *pDataIn,UINT32 DataLen,uint8_t *pDigest); 63 64 /************************************************************************** 65 * Function Name : SHA_encode 66 * Description : Encodes input (UINT32) into output (unsigned char)[Big-Endian] 67 * Input : - *input : input data to be tranformed; 68 : - len : byte len of the input data(len is a multiple of 4); 69 * Output : - *output : output data; 70 * Return : None 71 **************************************************************************/ 72 void SHA_encode (uint8_t *output, UINT32 *input, UINT32 len); 73 void SHA_memcpy (uint8_t *output,uint8_t *input, UINT32 len); 74 void SHA_memset (uint8_t *output, int value, UINT32 len); 75 76 77 #endif 78