Arduino Cryptography Library
SHA3.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_SHA3_h
24 #define CRYPTO_SHA3_h
25 
26 #include "KeccakCore.h"
27 #include "Hash.h"
28 
29 class SHA3_256 : public Hash
30 {
31 public:
32  SHA3_256();
33  virtual ~SHA3_256();
34 
35  size_t hashSize() const;
36  size_t blockSize() const;
37 
38  void reset();
39  void update(const void *data, size_t len);
40  void finalize(void *hash, size_t len);
41 
42  void clear();
43 
44  void resetHMAC(const void *key, size_t keyLen);
45  void finalizeHMAC(const void *key, size_t keyLen, void *hash, size_t hashLen);
46 
47  static const size_t HASH_SIZE = 32;
48  static const size_t BLOCK_SIZE = 136;
49 
50 private:
51  KeccakCore core;
52 };
53 
54 class SHA3_512 : public Hash
55 {
56 public:
57  SHA3_512();
58  virtual ~SHA3_512();
59 
60  size_t hashSize() const;
61  size_t blockSize() const;
62 
63  void reset();
64  void update(const void *data, size_t len);
65  void finalize(void *hash, size_t len);
66 
67  void clear();
68 
69  void resetHMAC(const void *key, size_t keyLen);
70  void finalizeHMAC(const void *key, size_t keyLen, void *hash, size_t hashLen);
71 
72  static const size_t HASH_SIZE = 64;
73  static const size_t BLOCK_SIZE = 72;
74 
75 private:
76  KeccakCore core;
77 };
78 
79 #endif
Abstract base class for cryptographic hash algorithms.
Definition: Hash.h:30
Keccak core sponge function.
Definition: KeccakCore.h:30
SHA3-256 hash algorithm.
Definition: SHA3.h:30
void finalizeHMAC(const void *key, size_t keyLen, void *hash, size_t hashLen)
Finalizes the HMAC hashing process and returns the hash.
Definition: SHA3.cpp:98
size_t blockSize() const
Size of the internal block used by the hash algorithm.
Definition: SHA3.cpp:66
void resetHMAC(const void *key, size_t keyLen)
Resets the hash ready for a new HMAC hashing process.
Definition: SHA3.cpp:93
static const size_t HASH_SIZE
Constant for the size of the hash output of SHA3-256.
Definition: SHA3.h:47
void clear()
Clears the hash state, removing all sensitive data, and then resets the hash ready for a new hashing ...
Definition: SHA3.cpp:88
void reset()
Resets the hash ready for a new hashing process.
Definition: SHA3.cpp:71
void update(const void *data, size_t len)
Updates the hash with more data.
Definition: SHA3.cpp:76
virtual ~SHA3_256()
Destroys this hash object after clearing sensitive information.
Definition: SHA3.cpp:56
void finalize(void *hash, size_t len)
Finalizes the hashing process and returns the hash.
Definition: SHA3.cpp:81
SHA3_256()
Constructs a new SHA3-256 hash object.
Definition: SHA3.cpp:48
size_t hashSize() const
Size of the hash result from finalize().
Definition: SHA3.cpp:61
static const size_t BLOCK_SIZE
Constant for the block size of SHA3-256.
Definition: SHA3.h:48
SHA3-512 hash algorithm.
Definition: SHA3.h:55
void update(const void *data, size_t len)
Updates the hash with more data.
Definition: SHA3.cpp:158
void finalizeHMAC(const void *key, size_t keyLen, void *hash, size_t hashLen)
Finalizes the HMAC hashing process and returns the hash.
Definition: SHA3.cpp:180
virtual ~SHA3_512()
Destroys this hash object after clearing sensitive information.
Definition: SHA3.cpp:138
void reset()
Resets the hash ready for a new hashing process.
Definition: SHA3.cpp:153
SHA3_512()
Constructs a new SHA3-512 hash object.
Definition: SHA3.cpp:130
static const size_t HASH_SIZE
Constant for the size of the hash output of SHA3-512.
Definition: SHA3.h:72
void resetHMAC(const void *key, size_t keyLen)
Resets the hash ready for a new HMAC hashing process.
Definition: SHA3.cpp:175
size_t hashSize() const
Size of the hash result from finalize().
Definition: SHA3.cpp:143
void finalize(void *hash, size_t len)
Finalizes the hashing process and returns the hash.
Definition: SHA3.cpp:163
void clear()
Clears the hash state, removing all sensitive data, and then resets the hash ready for a new hashing ...
Definition: SHA3.cpp:170
size_t blockSize() const
Size of the internal block used by the hash algorithm.
Definition: SHA3.cpp:148
static const size_t BLOCK_SIZE
Constant for the block size of SHA3-512.
Definition: SHA3.h:73