ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
SHA3.cpp
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 #include "SHA3.h"
24 
38 {
39  core.setCapacity(512);
40 }
41 
46 {
47  // The destructor for the KeccakCore object will do most of the work.
48 }
49 
50 size_t SHA3_256::hashSize() const
51 {
52  return 32;
53 }
54 
55 size_t SHA3_256::blockSize() const
56 {
57  return core.blockSize();
58 }
59 
61 {
62  core.reset();
63 }
64 
65 void SHA3_256::update(const void *data, size_t len)
66 {
67  core.update(data, len);
68 }
69 
70 void SHA3_256::finalize(void *hash, size_t len)
71 {
72  // Pad the final block and then extract the hash value.
73  core.pad(0x06);
74  core.extract(hash, len);
75 }
76 
78 {
79  core.clear();
80 }
81 
95 {
96  core.setCapacity(1024);
97 }
98 
103 {
104  // The destructor for the KeccakCore object will do most of the work.
105 }
106 
107 size_t SHA3_512::hashSize() const
108 {
109  return 64;
110 }
111 
112 size_t SHA3_512::blockSize() const
113 {
114  return core.blockSize();
115 }
116 
118 {
119  core.reset();
120 }
121 
122 void SHA3_512::update(const void *data, size_t len)
123 {
124  core.update(data, len);
125 }
126 
127 void SHA3_512::finalize(void *hash, size_t len)
128 {
129  // Pad the final block and then extract the hash value.
130  core.pad(0x06);
131  core.extract(hash, len);
132 }
133 
135 {
136  core.clear();
137 }
SHA3_512()
Constructs a new SHA3-512 hash object.
Definition: SHA3.cpp:94
void reset()
Resets the hash ready for a new hashing process.
Definition: SHA3.cpp:60
size_t blockSize() const
Returns the input block size for the sponge function in bytes.
Definition: KeccakCore.h:38
virtual ~SHA3_256()
Destroys this hash object after clearing sensitive information.
Definition: SHA3.cpp:45
size_t hashSize() const
Size of the hash result from finalize().
Definition: SHA3.cpp:107
SHA3_256()
Constructs a new SHA3-256 hash object.
Definition: SHA3.cpp:37
virtual ~SHA3_512()
Destroys this hash object after clearing sensitive information.
Definition: SHA3.cpp:102
size_t hashSize() const
Size of the hash result from finalize().
Definition: SHA3.cpp:50
void finalize(void *hash, size_t len)
Finalizes the hashing process and returns the hash.
Definition: SHA3.cpp:127
void reset()
Resets the hash ready for a new hashing process.
Definition: SHA3.cpp:117
void setCapacity(size_t capacity)
Sets the capacity of the Keccak sponge function in bits.
Definition: KeccakCore.cpp:89
size_t blockSize() const
Size of the internal block used by the hash algorithm.
Definition: SHA3.cpp:55
void extract(void *data, size_t size)
Extracts data from the Keccak sponge function.
Definition: KeccakCore.cpp:201
void clear()
Clears the hash state, removing all sensitive data, and then resets the hash ready for a new hashing ...
Definition: SHA3.cpp:134
void pad(uint8_t tag)
Pads the last block of input data to blockSize().
Definition: KeccakCore.cpp:174
size_t blockSize() const
Size of the internal block used by the hash algorithm.
Definition: SHA3.cpp:112
void update(const void *data, size_t len)
Updates the hash with more data.
Definition: SHA3.cpp:122
void update(const void *data, size_t size)
Updates the Keccak sponge function with more input data.
Definition: KeccakCore.cpp:128
void clear()
Clears all sensitive data from this object.
Definition: KeccakCore.cpp:245
void finalize(void *hash, size_t len)
Finalizes the hashing process and returns the hash.
Definition: SHA3.cpp:70
void reset()
Resets the Keccak sponge function ready for a new session.
Definition: KeccakCore.cpp:109
void update(const void *data, size_t len)
Updates the hash with more data.
Definition: SHA3.cpp:65
void clear()
Clears the hash state, removing all sensitive data, and then resets the hash ready for a new hashing ...
Definition: SHA3.cpp:77