1
0

HAL_SHA1.h 3.4 KB

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