]> git.piffa.net Git - arduino/blob - books/pdummies/Libraries/Sha/sha1.h
first commit
[arduino] / books / pdummies / Libraries / Sha / sha1.h
1 #ifndef Sha1_h
2 #define Sha1_h
3
4 #include <inttypes.h>
5 #include "Print.h"
6
7 #define HASH_LENGTH 20
8 #define BLOCK_LENGTH 64
9
10 union _buffer {
11   uint8_t b[BLOCK_LENGTH];
12   uint32_t w[BLOCK_LENGTH/4];
13 };
14 union _state {
15   uint8_t b[HASH_LENGTH];
16   uint32_t w[HASH_LENGTH/4];
17 };
18
19 class Sha1Class : public Print
20 {
21   public:
22     void init(void);
23     void initHmac(const uint8_t* secret, int secretLength);
24     uint8_t* result(void);
25     uint8_t* resultHmac(void);
26     virtual size_t write(uint8_t);
27     using Print::write;
28   private:
29     void pad();
30     void addUncounted(uint8_t data);
31     void hashBlock();
32     uint32_t rol32(uint32_t number, uint8_t bits);
33     _buffer buffer;
34     uint8_t bufferOffset;
35     _state state;
36     uint32_t byteCount;
37     uint8_t keyBuffer[BLOCK_LENGTH];
38     uint8_t innerHash[HASH_LENGTH];
39
40 };
41 extern Sha1Class Sha1;
42
43 #endif