SHA1 / SHA256 and HMAC-SHA1 / HMAC-SHA256 Hash library
SHA1 / SHA256 and HMAC-SHA1 / HMACSHA256 Hash library
sha1.h
1 #ifndef Sha1_h
2 #define Sha1_h
3 
4 #include "sha1_config.h"
5 
6 #if defined(SHA1_LINUX)
7 class Sha1Class
8 #else
9 class Sha1Class : 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(SHA1_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 rol32(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(SHA1_LINUX)
129  timeval tv;
130  #endif
131 
132 };
133 extern Sha1Class Sha1;
134 
135 #endif
136 
void pad()
Definition: sha1.cpp:78
uint32_t rol32(uint32_t number, uint8_t bits)
Definition: sha1.cpp:22
uint8_t keyBuffer[BLOCK_LENGTH]
Definition: sha1.h:126
_buffer buffer
Definition: sha1.h:122
uint8_t * resultHmac(void)
Definition: sha1.cpp:138
uint32_t w[HASH_LENGTH/4]
Definition: sha1.h:19
uint32_t w[BLOCK_LENGTH/4]
Definition: sha1.h:15
virtual size_t write(uint8_t)
Definition: sha1.cpp:72
uint8_t innerHash[HASH_LENGTH]
Definition: sha1.h:127
Definition: sha1.h:7
uint8_t b[BLOCK_LENGTH]
Definition: sha1.h:14
Definition: sha1.h:13
size_t print(const char *str)
Definition: sha1.cpp:161
uint8_t b[HASH_LENGTH]
Definition: sha1.h:18
timeval tv
Definition: sha1.h:129
uint8_t * result(void)
Definition: sha1.cpp:97
_state state
Definition: sha1.h:124
uint32_t byteCount
Definition: sha1.h:125
double millis()
Definition: sha1.cpp:165
size_t write_L(const char *str)
Definition: sha1.cpp:150
void init(void)
Definition: sha1.cpp:16
void initHmac(const uint8_t *secret, int secretLength)
Definition: sha1.cpp:119
void hashBlock()
Definition: sha1.cpp:26
Definition: sha1.h:17
uint8_t bufferOffset
Definition: sha1.h:123
void addUncounted(uint8_t data)
Definition: sha1.cpp:63