Blake2s.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Blake2s.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include "HashApi/blake2s.h"
14 #include "HashEngine.h"
15 #include "HashContext.h"
16 #include "HmacContext.h"
17 
18 namespace Crypto
19 {
20 #define BLAKE2S_INIT(name_) \
21  static_assert(hash_size > 0 && hash_size <= BLAKE2S_MAXHASHSIZE, "Blake2s invalid hashsize"); \
22  \
23  void init() \
24  { \
25  CRYPTO_NAME(name_, initkey)(&ctx, hash_size, nullptr, 0); \
26  } \
27  \
28  void init(const Secret& key) \
29  { \
30  CRYPTO_NAME(name_, initkey)(&ctx, hash_size, key.data(), key.size()); \
31  }
32 
33 template <size_t hash_size>
35 
36 /*
37  * Hash Contexts
38  */
39 template <size_t hashsize>
40 using Blake2s = HashContext<Blake2sEngine<hashsize>>;
41 using Blake2s256 = Blake2s<32>;
42 using Blake2s128 = Blake2s<16>;
43 
44 /*
45  * HMAC Contexts
46  */
47 template <size_t hashsize> using HmacBlake2s = HmacContext<Blake2s<hashsize>>;
50 
51 } // namespace Crypto
#define CRYPTO_HASH_ENGINE(class_, name_, hashsize_, statesize_, blocksize_, INIT)
Macro template to construct Engine class wrapper for a given hash API.
Definition: HashEngine.h:25
HmacContext< Blake2s< hashsize > > HmacBlake2s
Definition: Blake2s.h:55
HashContext< Blake2sEngine< hashsize > > Blake2s
Definition: Blake2s.h:48
#define BLAKE2S_INIT(name_)
Definition: Blake2s.h:28
Blake2s< 16 > Blake2s128
Definition: Blake2s.h:50
#define BLAKE2S_STATESIZE
Definition: blake2s.h:21
#define BLAKE2S_BLOCKSIZE
Definition: blake2s.h:22
Blake2s< 32 > Blake2s256
Definition: Blake2s.h:49
Definition: Blake2s.h:18
HMAC class template.
Definition: HmacContext.h:32