Arduino Cryptography Library
BLAKE2b.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_BLAKE2B_H
24 #define CRYPTO_BLAKE2B_H
25 
26 #include "Hash.h"
27 
28 class BLAKE2b : public Hash
29 {
30 public:
31  BLAKE2b();
32  virtual ~BLAKE2b();
33 
34  size_t hashSize() const;
35  size_t blockSize() const;
36 
37  void reset();
38  void reset(uint8_t outputLength);
39  void reset(const void *key, size_t keyLen, uint8_t outputLength = 64);
40 
41  void update(const void *data, size_t len);
42  void finalize(void *hash, size_t len);
43 
44  void clear();
45 
46  void resetHMAC(const void *key, size_t keyLen);
47  void finalizeHMAC(const void *key, size_t keyLen, void *hash, size_t hashLen);
48 
49  static const size_t HASH_SIZE = 64;
50  static const size_t BLOCK_SIZE = 128;
51 
52 private:
53  struct {
54  uint64_t h[8];
55  uint64_t m[16];
56  uint64_t lengthLow;
57  uint64_t lengthHigh;
58  uint8_t chunkSize;
59  } state;
60 
61  void processChunk(uint64_t f0);
62 };
63 
64 #endif
BLAKE2b hash algorithm.
Definition: BLAKE2b.h:29
void finalize(void *hash, size_t len)
Finalizes the hashing process and returns the hash.
Definition: BLAKE2b.cpp:227
BLAKE2b()
Constructs a BLAKE2b hash object.
Definition: BLAKE2b.cpp:85
static const size_t BLOCK_SIZE
Constant for the block size of BLAKE2b.
Definition: BLAKE2b.h:50
void clear()
Clears the hash state, removing all sensitive data, and then resets the hash ready for a new hashing ...
Definition: BLAKE2b.cpp:243
void finalizeHMAC(const void *key, size_t keyLen, void *hash, size_t hashLen)
Finalizes the HMAC hashing process and returns the hash.
Definition: BLAKE2b.cpp:256
size_t hashSize() const
Size of the hash result from finalize().
Definition: BLAKE2b.cpp:99
void update(const void *data, size_t len)
Updates the hash with more data.
Definition: BLAKE2b.cpp:202
size_t blockSize() const
Size of the internal block used by the hash algorithm.
Definition: BLAKE2b.cpp:104
void reset()
Resets the hash ready for a new hashing process.
Definition: BLAKE2b.cpp:119
static const size_t HASH_SIZE
Constant for the size of the hash output of BLAKE2b.
Definition: BLAKE2b.h:49
void resetHMAC(const void *key, size_t keyLen)
Resets the hash ready for a new HMAC hashing process.
Definition: BLAKE2b.cpp:249
virtual ~BLAKE2b()
Destroys this BLAKE2b hash object after clearing sensitive information.
Definition: BLAKE2b.cpp:94
Abstract base class for cryptographic hash algorithms.
Definition: Hash.h:30