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