HAL_SHA256.h 3.3 KB

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