MeterLogger
Functions
hmac-sha256.c File Reference
#include <esp8266.h>
#include <string.h>
#include "crypto/crypto.h"
#include "crypto/hmac-sha256.h"
Include dependency graph for hmac-sha256.c:

Go to the source code of this file.

Functions

ICACHE_FLASH_ATTR void hmac_sha256_init (hmac_sha256_ctx_t *hctx, uint8_t *key, uint32_t keylen)
 
ICACHE_FLASH_ATTR void hmac_sha256_update (hmac_sha256_ctx_t *hctx, uint8_t *msg, uint32_t msglen)
 
ICACHE_FLASH_ATTR void hmac_sha256_final (hmac_sha256_ctx_t *hctx, uint8_t *hmac)
 
ICACHE_FLASH_ATTR void hmac_sha256 (uint8_t *key, uint32_t keylen, uint8_t *msg, uint32_t msglen, uint8_t *hmac)
 

Function Documentation

◆ hmac_sha256()

ICACHE_FLASH_ATTR void hmac_sha256 ( uint8_t *  key,
uint32_t  keylen,
uint8_t *  msg,
uint32_t  msglen,
uint8_t *  hmac 
)

Definition at line 66 of file hmac-sha256.c.

References hmac_sha256_final(), hmac_sha256_init(), and hmac_sha256_update().

66  {
67  hmac_sha256_ctx_t hctx;
68  hmac_sha256_init(&hctx, key, keylen);
69  hmac_sha256_update(&hctx, msg, msglen);
70  hmac_sha256_final(&hctx, hmac);
71 }
ICACHE_FLASH_ATTR void hmac_sha256_update(hmac_sha256_ctx_t *hctx, uint8_t *msg, uint32_t msglen)
Definition: hmac-sha256.c:49
ICACHE_FLASH_ATTR void hmac_sha256_final(hmac_sha256_ctx_t *hctx, uint8_t *hmac)
Definition: hmac-sha256.c:54
static const char key[]
Definition: config.h:42
ICACHE_FLASH_ATTR void hmac_sha256_init(hmac_sha256_ctx_t *hctx, uint8_t *key, uint32_t keylen)
Definition: hmac-sha256.c:30
Here is the call graph for this function:

◆ hmac_sha256_final()

ICACHE_FLASH_ATTR void hmac_sha256_final ( hmac_sha256_ctx_t hctx,
uint8_t *  hmac 
)

Definition at line 54 of file hmac-sha256.c.

References hmac_sha256_ctx_t::ctx, ICACHE_FLASH_ATTR, memset, hmac_sha256_ctx_t::o_key_pad, SHA256_BLOCK_LENGTH, SHA256_DIGEST_LENGTH, sha256_final(), sha256_init(), and sha256_update().

Referenced by decrypt_aes_hmac_combined(), encrypt_aes_hmac_combined(), and hmac_sha256().

54  {
55  uint8_t hash[SHA256_DIGEST_LENGTH];
56  sha256_final(&(hctx->ctx), hash);
57  sha256_init(&(hctx->ctx));
59  sha256_update(&(hctx->ctx), hash, SHA256_DIGEST_LENGTH);
60  sha256_final(&(hctx->ctx), hmac);
61  memset(hash, 0, sizeof(hash));
62  memset(hctx, 0, sizeof(hmac_sha256_ctx_t));
63 }
#define memset(x, a, b)
Definition: platform.h:21
#define SHA256_BLOCK_LENGTH
Definition: sha256.h:38
ICACHE_FLASH_ATTR void sha256_final(sha256_ctx_t *context, uint8_t digest[SHA256_DIGEST_LENGTH])
Definition: sha256.c:334
uint8_t o_key_pad[SHA256_BLOCK_LENGTH]
Definition: hmac-sha256.h:33
ICACHE_FLASH_ATTR void sha256_init(sha256_ctx_t *context)
Definition: sha256.c:196
sha256_ctx_t ctx
Definition: hmac-sha256.h:34
#define SHA256_DIGEST_LENGTH
Definition: sha256.h:39
ICACHE_FLASH_ATTR void sha256_update(sha256_ctx_t *context, uint8_t *data, size_t len)
Definition: sha256.c:288
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hmac_sha256_init()

ICACHE_FLASH_ATTR void hmac_sha256_init ( hmac_sha256_ctx_t hctx,
uint8_t *  key,
uint32_t  keylen 
)

Copyright (c) 2013-2014 Tomas Dzetkulic Copyright (c) 2013-2014 Pavol Rusnak

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition at line 30 of file hmac-sha256.c.

References hmac_sha256_ctx_t::ctx, ICACHE_FLASH_ATTR, memcpy, memset, hmac_sha256_ctx_t::o_key_pad, SHA256_BLOCK_LENGTH, sha256_init(), sha256_raw(), and sha256_update().

Referenced by decrypt_aes_hmac_combined(), encrypt_aes_hmac_combined(), and hmac_sha256().

30  {
31  int i;
32  uint8_t i_key_pad[SHA256_BLOCK_LENGTH];
33  memset(i_key_pad, 0, SHA256_BLOCK_LENGTH);
34  if (keylen > SHA256_BLOCK_LENGTH) {
35  sha256_raw(key, keylen, i_key_pad);
36  } else {
37  memcpy(i_key_pad, key, keylen);
38  }
39  for (i = 0; i < SHA256_BLOCK_LENGTH; i++) {
40  hctx->o_key_pad[i] = i_key_pad[i] ^ 0x5c;
41  i_key_pad[i] ^= 0x36;
42  }
43  sha256_init(&(hctx->ctx));
44  sha256_update(&(hctx->ctx), i_key_pad, SHA256_BLOCK_LENGTH);
45  memset(i_key_pad, 0, sizeof(i_key_pad));
46 }
#define memset(x, a, b)
Definition: platform.h:21
#define SHA256_BLOCK_LENGTH
Definition: sha256.h:38
ICACHE_FLASH_ATTR void sha256_raw(uint8_t *data, size_t len, uint8_t digest[SHA256_DIGEST_LENGTH])
Definition: sha256.c:421
uint8_t o_key_pad[SHA256_BLOCK_LENGTH]
Definition: hmac-sha256.h:33
static const char key[]
Definition: config.h:42
ICACHE_FLASH_ATTR void sha256_init(sha256_ctx_t *context)
Definition: sha256.c:196
#define memcpy(x, a, b)
Definition: platform.h:22
sha256_ctx_t ctx
Definition: hmac-sha256.h:34
ICACHE_FLASH_ATTR void sha256_update(sha256_ctx_t *context, uint8_t *data, size_t len)
Definition: sha256.c:288
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hmac_sha256_update()

ICACHE_FLASH_ATTR void hmac_sha256_update ( hmac_sha256_ctx_t hctx,
uint8_t *  msg,
uint32_t  msglen 
)

Definition at line 49 of file hmac-sha256.c.

References hmac_sha256_ctx_t::ctx, ICACHE_FLASH_ATTR, and sha256_update().

Referenced by decrypt_aes_hmac_combined(), encrypt_aes_hmac_combined(), and hmac_sha256().

49  {
50  sha256_update(&(hctx->ctx), msg, msglen);
51 }
sha256_ctx_t ctx
Definition: hmac-sha256.h:34
ICACHE_FLASH_ATTR void sha256_update(sha256_ctx_t *context, uint8_t *data, size_t len)
Definition: sha256.c:288
Here is the call graph for this function:
Here is the caller graph for this function: