esp8266ndn
NDN Arduino library for ESP8266 and more
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sha256-bearssl.hpp
Go to the documentation of this file.
1 #ifndef ESP8266NDN_PORT_SHA256_BEARSSL_HPP
2 #define ESP8266NDN_PORT_SHA256_BEARSSL_HPP
3 
4 #include <bearssl/bearssl_hash.h>
5 #include <bearssl/bearssl_hmac.h>
6 
7 namespace esp8266ndn {
8 namespace ndnph_port {
9 
11 class Sha256 {
12 public:
13  Sha256() {
14  ::br_sha256_init(&m_ctx);
15  }
16 
17  void update(const uint8_t* chunk, size_t size) {
18  ::br_sha256_update(&m_ctx, chunk, size);
19  }
20 
21  bool final(uint8_t* digest) {
22  ::br_sha256_out(&m_ctx, digest);
23  return true;
24  }
25 
26 private:
27  ::br_sha256_context m_ctx;
28 };
29 
31 class HmacSha256 {
32 public:
33  explicit HmacSha256(const uint8_t* key, size_t keyLen) {
34  ::br_hmac_key_init(&m_key, &br_sha256_vtable, key, keyLen);
35  ::br_hmac_init(&m_ctx, &m_key, 0);
36  }
37 
38  void update(const uint8_t* chunk, size_t size) {
39  ::br_hmac_update(&m_ctx, chunk, size);
40  }
41 
42  bool final(uint8_t* result) {
43  bool ok = ::br_hmac_out(&m_ctx, result) != 0;
44  ::br_hmac_init(&m_ctx, &m_key, 0);
45  return ok;
46  }
47 
48 private:
49  ::br_hmac_key_context m_key;
50  ::br_hmac_context m_ctx;
51 };
52 
53 } // namespace ndnph_port
54 } // namespace esp8266ndn
55 
56 namespace ndnph {
57 namespace port {
60 } // namespace port
61 } // namespace ndnph
62 
63 #endif // ESP8266NDN_PORT_SHA256_BEARSSL_HPP
HMAC-SHA256 algorithm, implemented with BearSSL.
Definition: sha256-bearssl.hpp:31
void update(const uint8_t *chunk, size_t size)
Definition: sha256-bearssl.hpp:38
HmacSha256(const uint8_t *key, size_t keyLen)
Definition: sha256-bearssl.hpp:33
SHA256 algorithm, implemented with BearSSL.
Definition: sha256-bearssl.hpp:11
Sha256()
Definition: sha256-bearssl.hpp:13
void update(const uint8_t *chunk, size_t size)
Definition: sha256-bearssl.hpp:17
Definition: autoconfig.hpp:24
esp8266ndn::ndnph_port::HmacSha256 HmacSha256
Definition: sha256-bearssl.hpp:59
esp8266ndn::ndnph_port::Sha256 Sha256
Definition: sha256-bearssl.hpp:58
Definition: fs.hpp:33