ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
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 
47  void clear();
48 
49 private:
50  struct {
51  uint64_t A[5][5];
52  uint64_t B[5][5];
53  uint8_t inputSize;
54  uint8_t outputSize;
55  } state;
56  uint8_t _blockSize;
57 
58  void keccakp();
59 };
60 
61 #endif
size_t blockSize() const
Returns the input block size for the sponge function in bytes.
Definition: KeccakCore.h:38
void setCapacity(size_t capacity)
Sets the capacity of the Keccak sponge function in bits.
Definition: KeccakCore.cpp:89
~KeccakCore()
Destroys this Keccak sponge function after clearing all sensitive information.
Definition: KeccakCore.cpp:61
void extract(void *data, size_t size)
Extracts data from the Keccak sponge function.
Definition: KeccakCore.cpp:201
void pad(uint8_t tag)
Pads the last block of input data to blockSize().
Definition: KeccakCore.cpp:174
size_t capacity() const
Returns the capacity of the sponge function in bits.
Definition: KeccakCore.cpp:71
KeccakCore()
Constructs a new Keccak sponge function.
Definition: KeccakCore.cpp:49
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 reset()
Resets the Keccak sponge function ready for a new session.
Definition: KeccakCore.cpp:109
Keccak core sponge function.
Definition: KeccakCore.h:29