Arduino Cryptography Library
SHAKE.cpp
1 /*
2  * Copyright (C) 2016 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 "SHAKE.h"
24 
40 SHAKE::SHAKE(size_t capacity)
41  : finalized(false)
42 {
43  core.setCapacity(capacity);
44 }
45 
50 {
51 }
52 
53 size_t SHAKE::blockSize() const
54 {
55  return core.blockSize();
56 }
57 
59 {
60  core.reset();
61  finalized = false;
62 }
63 
64 void SHAKE::update(const void *data, size_t len)
65 {
66  if (finalized)
67  reset();
68  core.update(data, len);
69 }
70 
71 void SHAKE::extend(uint8_t *data, size_t len)
72 {
73  if (!finalized) {
74  core.pad(0x1F);
75  finalized = true;
76  }
77  core.extract(data, len);
78 }
79 
80 void SHAKE::encrypt(uint8_t *output, const uint8_t *input, size_t len)
81 {
82  if (!finalized) {
83  core.pad(0x1F);
84  finalized = true;
85  }
86  core.encrypt(output, input, len);
87 }
88 
90 {
91  core.clear();
92  finalized = false;
93 }
94 
114 {
115 }
116 
136 {
137 }
size_t blockSize() const
Returns the input block size for the sponge function in bytes.
Definition: KeccakCore.h:38
void reset()
Resets the Keccak sponge function ready for a new session.
Definition: KeccakCore.cpp:114
void pad(uint8_t tag)
Pads the last block of input data to blockSize().
Definition: KeccakCore.cpp:167
void update(const void *data, size_t size)
Updates the Keccak sponge function with more input data.
Definition: KeccakCore.cpp:133
void extract(void *data, size_t size)
Extracts data from the Keccak sponge function.
Definition: KeccakCore.cpp:194
void setCapacity(size_t capacity)
Sets the capacity of the Keccak sponge function in bits.
Definition: KeccakCore.cpp:94
void encrypt(void *output, const void *input, size_t size)
Extracts data from the Keccak sponge function and uses it to encrypt a buffer.
Definition: KeccakCore.cpp:240
void clear()
Clears all sensitive data from this object.
Definition: KeccakCore.cpp:275
virtual ~SHAKE128()
Destroys this SHAKE128 object after clearing all sensitive information.
Definition: SHAKE.cpp:113
virtual ~SHAKE256()
Destroys this SHAKE256 object after clearing all sensitive information.
Definition: SHAKE.cpp:135
size_t blockSize() const
Size of the internal block used by the XOF algorithm, in bytes.
Definition: SHAKE.cpp:53
virtual ~SHAKE()
Destroys this SHAKE object after clearing all sensitive information.
Definition: SHAKE.cpp:49
void encrypt(uint8_t *output, const uint8_t *input, size_t len)
Encrypts an input buffer with extendable output from this XOF.
Definition: SHAKE.cpp:80
SHAKE(size_t capacity)
Constructs a SHAKE object.
Definition: SHAKE.cpp:40
void update(const void *data, size_t len)
Updates the XOF with more data.
Definition: SHAKE.cpp:64
void clear()
Clears the hash state, removing all sensitive data, and then resets the XOF ready for a new session.
Definition: SHAKE.cpp:89
void extend(uint8_t *data, size_t len)
Generates extendable output from this XOF.
Definition: SHAKE.cpp:71
void reset()
Resets the XOF ready for a new session.
Definition: SHAKE.cpp:58