sha256.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // "Borrowed" from https://github.com/B-Con/crypto-algorithms/blob/master/sha256.h
  2. /*********************************************************************
  3. * Filename: sha256.h
  4. * Author: Brad Conte (brad AT bradconte.com)
  5. * Copyright:
  6. * Disclaimer: This code is presented "as is" without any guarantees.
  7. * Details: Defines the API for the corresponding SHA1 implementation.
  8. *********************************************************************/
  9. #ifndef SHA256_H
  10. #define SHA256_H
  11. /*************************** HEADER FILES ***************************/
  12. #include <stddef.h>
  13. #include <cstdint>
  14. /****************************** MACROS ******************************/
  15. #define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
  16. /**************************** DATA TYPES ****************************/
  17. //typedef unsigned char BYTE; // 8-bit byte
  18. //typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
  19. class sha256
  20. {
  21. public:
  22. uint8_t data[64];
  23. uint32_t datalen;
  24. uint64_t bitlen;
  25. uint32_t state[8];
  26. /*********************** FUNCTION DECLARATIONS **********************/
  27. void sha256_init();
  28. void sha256_update(const uint8_t input[], size_t len);
  29. void sha256_final(uint8_t hash[]); // hash should be 32 bytes long.
  30. private:
  31. void sha256_transform(const uint8_t input[]);
  32. };
  33. #endif // SHA256_H