Arduino Cryptography Library
SHA1.h
1 /*
2  * Copyright (C) 2015 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef CRYPTO_SHA1_h
24 #define CRYPTO_SHA1_h
25 
26 #include "Hash.h"
27 
28 class SHA1 : public Hash
29 {
30 public:
31  SHA1();
32  virtual ~SHA1();
33 
34  size_t hashSize() const;
35  size_t blockSize() const;
36 
37  void reset();
38  void update(const void *data, size_t len);
39  void finalize(void *hash, size_t len);
40 
41  void clear();
42 
43  void resetHMAC(const void *key, size_t keyLen);
44  void finalizeHMAC(const void *key, size_t keyLen, void *hash, size_t hashLen);
45 
46  static const size_t HASH_SIZE = 20;
47  static const size_t BLOCK_SIZE = 64;
48 
49 private:
50  struct {
51  uint32_t h[5];
52  uint32_t w[16];
53  uint64_t length;
54  uint8_t chunkSize;
55  } state;
56 
57  void processChunk();
58 };
59 
60 #endif
Abstract base class for cryptographic hash algorithms.
Definition: Hash.h:30
SHA-1 hash algorithm.
Definition: SHA1.h:29
static const size_t HASH_SIZE
Constant for the size of the hash output of SHA1.
Definition: SHA1.h:46
static const size_t BLOCK_SIZE
Constant for the block size of SHA1.
Definition: SHA1.h:47
void clear()
Clears the hash state, removing all sensitive data, and then resets the hash ready for a new hashing ...
Definition: SHA1.cpp:138
void finalize(void *hash, size_t len)
Finalizes the hashing process and returns the hash.
Definition: SHA1.cpp:107
size_t hashSize() const
Size of the hash result from finalize().
Definition: SHA1.cpp:64
void finalizeHMAC(const void *key, size_t keyLen, void *hash, size_t hashLen)
Finalizes the HMAC hashing process and returns the hash.
Definition: SHA1.cpp:151
virtual ~SHA1()
Destroys this SHA-1 hash object after clearing sensitive information.
Definition: SHA1.cpp:59
size_t blockSize() const
Size of the internal block used by the hash algorithm.
Definition: SHA1.cpp:69
void reset()
Resets the hash ready for a new hashing process.
Definition: SHA1.cpp:74
void resetHMAC(const void *key, size_t keyLen)
Resets the hash ready for a new HMAC hashing process.
Definition: SHA1.cpp:144
SHA1()
Constructs a SHA-1 hash object.
Definition: SHA1.cpp:51
void update(const void *data, size_t len)
Updates the hash with more data.
Definition: SHA1.cpp:85