Arduino Cryptography Library
SHAKE.h
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 #ifndef CRYPTO_SHAKE_h
24 #define CRYPTO_SHAKE_h
25 
26 #include "XOF.h"
27 #include "KeccakCore.h"
28 
29 class SHAKE : public XOF
30 {
31 public:
32  virtual ~SHAKE();
33 
34  size_t blockSize() const;
35 
36  void reset();
37  void update(const void *data, size_t len);
38 
39  void extend(uint8_t *data, size_t len);
40  void encrypt(uint8_t *output, const uint8_t *input, size_t len);
41 
42  void clear();
43 
44 protected:
45  SHAKE(size_t capacity);
46 
47 private:
48  KeccakCore core;
49  bool finalized;
50 };
51 
52 class SHAKE128 : public SHAKE
53 {
54 public:
55  SHAKE128() : SHAKE(256) {}
56  virtual ~SHAKE128();
57 };
58 
59 class SHAKE256 : public SHAKE
60 {
61 public:
62  SHAKE256() : SHAKE(512) {}
63  virtual ~SHAKE256();
64 };
65 
66 #endif
Keccak core sponge function.
Definition: KeccakCore.h:30
SHAKE Extendable-Output Function (XOF) with 128-bit security.
Definition: SHAKE.h:53
virtual ~SHAKE128()
Destroys this SHAKE128 object after clearing all sensitive information.
Definition: SHAKE.cpp:113
SHAKE128()
Constructs a SHAKE object with 128-bit security.
Definition: SHAKE.h:55
SHAKE Extendable-Output Function (XOF) with 256-bit security.
Definition: SHAKE.h:60
virtual ~SHAKE256()
Destroys this SHAKE256 object after clearing all sensitive information.
Definition: SHAKE.cpp:135
SHAKE256()
Constructs a SHAKE object with 256-bit security.
Definition: SHAKE.h:62
Abstract base class for the SHAKE Extendable-Output Functions (XOFs).
Definition: SHAKE.h:30
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
Abstract base class for Extendable-Output Functions (XOFs).
Definition: XOF.h:30