libnx  v4.7.0
hmac.h
Go to the documentation of this file.
1 /**
2  * @file hmac.h
3  * @brief Hardware accelerated HMAC-SHA(1, 256) implementation.
4  * @copyright libnx Authors
5  */
6 #pragma once
7 #include "sha1.h"
8 #include "sha256.h"
9 
10 /// Context for HMAC-SHA1 operations.
11 typedef struct {
12  Sha1Context sha_ctx;
13  u32 key[SHA1_BLOCK_SIZE / sizeof(u32)];
14  u32 mac[SHA1_HASH_SIZE / sizeof(u32)];
15  bool finalized;
17 
18 /// Context for HMAC-SHA256 operations.
19 typedef struct {
20  Sha256Context sha_ctx;
21  u32 key[SHA256_BLOCK_SIZE / sizeof(u32)];
22  u32 mac[SHA256_HASH_SIZE / sizeof(u32)];
23  bool finalized;
25 
26 #ifndef HMAC_SHA1_KEY_MAX
27 #define HMAC_SHA1_KEY_MAX (sizeof(((HmacSha1Context *)NULL)->key))
28 #endif
29 #ifndef HMAC_SHA256_KEY_MAX
30 #define HMAC_SHA256_KEY_MAX (sizeof(((HmacSha256Context *)NULL)->key))
31 #endif
32 
33 /// Initialize a HMAC-SHA256 context.
34 void hmacSha256ContextCreate(HmacSha256Context *out, const void *key, size_t key_size);
35 /// Updates HMAC-SHA256 context with data to hash
36 void hmacSha256ContextUpdate(HmacSha256Context *ctx, const void *src, size_t size);
37 /// Gets the context's output mac, finalizes the context.
39 
40 /// Simple all-in-one HMAC-SHA256 calculator.
41 void hmacSha256CalculateMac(void *dst, const void *key, size_t key_size, const void *src, size_t size);
42 
43 /// Initialize a HMAC-SHA1 context.
44 void hmacSha1ContextCreate(HmacSha1Context *out, const void *key, size_t key_size);
45 /// Updates HMAC-SHA1 context with data to hash
46 void hmacSha1ContextUpdate(HmacSha1Context *ctx, const void *src, size_t size);
47 /// Gets the context's output mac, finalizes the context.
48 void hmacSha1ContextGetMac(HmacSha1Context *ctx, void *dst);
49 
50 /// Simple all-in-one HMAC-SHA1 calculator.
51 void hmacSha1CalculateMac(void *dst, const void *key, size_t key_size, const void *src, size_t size);
void hmacSha1ContextGetMac(HmacSha1Context *ctx, void *dst)
Gets the context's output mac, finalizes the context.
void hmacSha1ContextUpdate(HmacSha1Context *ctx, const void *src, size_t size)
Updates HMAC-SHA1 context with data to hash.
void hmacSha1ContextCreate(HmacSha1Context *out, const void *key, size_t key_size)
Initialize a HMAC-SHA1 context.
void hmacSha256ContextGetMac(HmacSha256Context *ctx, void *dst)
Gets the context's output mac, finalizes the context.
void hmacSha256ContextUpdate(HmacSha256Context *ctx, const void *src, size_t size)
Updates HMAC-SHA256 context with data to hash.
void hmacSha256CalculateMac(void *dst, const void *key, size_t key_size, const void *src, size_t size)
Simple all-in-one HMAC-SHA256 calculator.
void hmacSha1CalculateMac(void *dst, const void *key, size_t key_size, const void *src, size_t size)
Simple all-in-one HMAC-SHA1 calculator.
void hmacSha256ContextCreate(HmacSha256Context *out, const void *key, size_t key_size)
Initialize a HMAC-SHA256 context.
Hardware accelerated SHA1 implementation.
Hardware accelerated SHA256 implementation.
Context for HMAC-SHA1 operations.
Definition: hmac.h:11
Context for HMAC-SHA256 operations.
Definition: hmac.h:19
Context for SHA1 operations.
Definition: sha1.h:18
Context for SHA256 operations.
Definition: sha256.h:19
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21