Arduino Cryptography Library
KeccakCore.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_KECCAKCORE_H
24 #define CRYPTO_KECCAKCORE_H
25 
26 #include <inttypes.h>
27 #include <stddef.h>
28 
30 {
31 public:
32  KeccakCore();
33  ~KeccakCore();
34 
35  size_t capacity() const;
36  void setCapacity(size_t capacity);
37 
38  size_t blockSize() const { return _blockSize; }
39 
40  void reset();
41 
42  void update(const void *data, size_t size);
43  void pad(uint8_t tag);
44 
45  void extract(void *data, size_t size);
46  void encrypt(void *output, const void *input, size_t size);
47 
48  void clear();
49 
50  void setHMACKey(const void *key, size_t len, uint8_t pad, size_t hashSize);
51 
52 private:
53  struct {
54  uint64_t A[5][5];
55  uint8_t inputSize;
56  uint8_t outputSize;
57  } state;
58  uint8_t _blockSize;
59 
60  void keccakp();
61 };
62 
63 #endif
Keccak core sponge function.
Definition: KeccakCore.h:30
size_t blockSize() const
Returns the input block size for the sponge function in bytes.
Definition: KeccakCore.h:38
~KeccakCore()
Destroys this Keccak sponge function after clearing all sensitive information.
Definition: KeccakCore.cpp:66
void reset()
Resets the Keccak sponge function ready for a new session.
Definition: KeccakCore.cpp:114
KeccakCore()
Constructs a new Keccak sponge function.
Definition: KeccakCore.cpp:54
void pad(uint8_t tag)
Pads the last block of input data to blockSize().
Definition: KeccakCore.cpp:167
size_t capacity() const
Returns the capacity of the sponge function in bits.
Definition: KeccakCore.cpp:76
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
void setHMACKey(const void *key, size_t len, uint8_t pad, size_t hashSize)
Sets a HMAC key for a Keccak-based hash algorithm.
Definition: KeccakCore.cpp:293