SHA1 / SHA256 and HMAC-SHA1 / HMAC-SHA256 Hash library
SHA1 / SHA256 and HMAC-SHA1 / HMACSHA256 Hash library
sha256.h
1 #ifndef Sha256_h
2 #define Sha256_h
3 
4 #include "sha256_config.h"
5 
6 #if defined(SHA256_LINUX)
8 #else
9 class Sha256Class : public Print
10 #endif
11 {
12  public:
13  union _buffer {
14  uint8_t b[BLOCK_LENGTH];
15  uint32_t w[BLOCK_LENGTH/4];
16  };
17  union _state {
18  uint8_t b[HASH_LENGTH];
19  uint32_t w[HASH_LENGTH/4];
20  };
24  void init(void);
30  void initHmac(const uint8_t* secret, int secretLength);
31 
36  uint8_t* result(void);
37 
42  uint8_t* resultHmac(void);
43  #if defined(SHA256_LINUX)
44 
49  virtual size_t write(uint8_t);
50 
59  size_t write_L(const char *str);
60 
70  size_t write_L(const uint8_t *buffer, size_t size);
71 
80  size_t print(const char* str);
81 
87  double millis();
88  #else
89 
94  virtual size_t write(uint8_t);
95  using Print::write;
96  #endif
97  private:
102  void pad();
103 
109  void addUncounted(uint8_t data);
110 
114  void hashBlock();
115 
121  uint32_t ror32(uint32_t number, uint8_t bits);
123  uint8_t bufferOffset;
125  uint32_t byteCount;
126  uint8_t keyBuffer[BLOCK_LENGTH];
127  uint8_t innerHash[HASH_LENGTH];
128  #if defined(SHA256_LINUX)
129  timeval tv;
130  #endif
131 };
132 extern Sha256Class Sha256;
133 
134 #endif
uint32_t byteCount
Definition: sha256.h:125
uint32_t w[BLOCK_LENGTH/4]
Definition: sha256.h:15
double millis()
Definition: sha256.cpp:182
_state state
Definition: sha256.h:124
_buffer buffer
Definition: sha256.h:122
size_t print(const char *str)
Definition: sha256.cpp:178
void initHmac(const uint8_t *secret, int secretLength)
Definition: sha256.cpp:137
Definition: sha256.h:13
void hashBlock()
Definition: sha256.cpp:37
uint8_t b[HASH_LENGTH]
Definition: sha256.h:18
Definition: sha256.h:17
uint8_t bufferOffset
Definition: sha256.h:123
uint32_t w[HASH_LENGTH/4]
Definition: sha256.h:19
uint8_t innerHash[HASH_LENGTH]
Definition: sha256.h:127
timeval tv
Definition: sha256.h:129
size_t write_L(const char *str)
Definition: sha256.cpp:167
uint8_t * result(void)
Definition: sha256.cpp:112
void pad()
Definition: sha256.cpp:93
void addUncounted(uint8_t data)
Definition: sha256.cpp:78
uint8_t b[BLOCK_LENGTH]
Definition: sha256.h:14
uint8_t keyBuffer[BLOCK_LENGTH]
Definition: sha256.h:126
uint32_t ror32(uint32_t number, uint8_t bits)
Definition: sha256.cpp:33
virtual size_t write(uint8_t)
Definition: sha256.cpp:87
uint8_t * resultHmac(void)
Definition: sha256.cpp:156
void init(void)
Definition: sha256.cpp:27
Definition: sha256.h:7