libnx  v4.8.0
cmac.h
Go to the documentation of this file.
1 /**
2  * @file cmac.h
3  * @brief Hardware accelerated AES-CMAC implementation.
4  * @copyright libnx Authors
5  */
6 #pragma once
7 #include "aes.h"
8 
9 /// Context for AES-128 CMAC.
10 typedef struct {
11  Aes128Context ctx;
12  u8 subkey[AES_BLOCK_SIZE];
13  u8 mac[AES_BLOCK_SIZE];
14  u8 buffer[AES_BLOCK_SIZE];
15  size_t num_buffered;
16  bool finalized;
18 
19 /// Context for AES-192 CMAC.
20 typedef struct {
21  Aes192Context ctx;
22  u8 subkey[AES_BLOCK_SIZE];
23  u8 mac[AES_BLOCK_SIZE];
24  u8 buffer[AES_BLOCK_SIZE];
25  size_t num_buffered;
26  bool finalized;
28 
29 /// Context for AES-256 CMAC.
30 typedef struct {
31  Aes256Context ctx;
32  u8 subkey[AES_BLOCK_SIZE];
33  u8 mac[AES_BLOCK_SIZE];
34  u8 buffer[AES_BLOCK_SIZE];
35  size_t num_buffered;
36  bool finalized;
38 
39 /// Initialize an AES-128-CMAC context.
40 void cmacAes128ContextCreate(Aes128CmacContext *out, const void *key);
41 /// Updates AES-128-CMAC context with data to hash
42 void cmacAes128ContextUpdate(Aes128CmacContext *ctx, const void *src, size_t size);
43 /// Gets the context's output mac, finalizes the context.
45 
46 /// Simple all-in-one AES-128-CMAC calculator.
47 void cmacAes128CalculateMac(void *dst, const void *key, const void *src, size_t size);
48 
49 /// Initialize an AES-192-CMAC context.
50 void cmacAes192ContextCreate(Aes192CmacContext *out, const void *key);
51 /// Updates AES-192-CMAC context with data to hash
52 void cmacAes192ContextUpdate(Aes192CmacContext *ctx, const void *src, size_t size);
53 /// Gets the context's output mac, finalizes the context.
55 
56 /// Simple all-in-one AES-192-CMAC calculator.
57 void cmacAes192CalculateMac(void *dst, const void *key, const void *src, size_t size);
58 
59 /// Initialize an AES-256-CMAC context.
60 void cmacAes256ContextCreate(Aes256CmacContext *out, const void *key);
61 /// Updates AES-256-CMAC context with data to hash
62 void cmacAes256ContextUpdate(Aes256CmacContext *ctx, const void *src, size_t size);
63 /// Gets the context's output mac, finalizes the context.
65 
66 /// Simple all-in-one AES-256-CMAC calculator.
67 void cmacAes256CalculateMac(void *dst, const void *key, const void *src, size_t size);
Hardware accelerated AES-ECB implementation.
void cmacAes192CalculateMac(void *dst, const void *key, const void *src, size_t size)
Simple all-in-one AES-192-CMAC calculator.
void cmacAes128CalculateMac(void *dst, const void *key, const void *src, size_t size)
Simple all-in-one AES-128-CMAC calculator.
void cmacAes256ContextCreate(Aes256CmacContext *out, const void *key)
Initialize an AES-256-CMAC context.
void cmacAes256ContextUpdate(Aes256CmacContext *ctx, const void *src, size_t size)
Updates AES-256-CMAC context with data to hash.
void cmacAes256CalculateMac(void *dst, const void *key, const void *src, size_t size)
Simple all-in-one AES-256-CMAC calculator.
void cmacAes192ContextCreate(Aes192CmacContext *out, const void *key)
Initialize an AES-192-CMAC context.
void cmacAes256ContextGetMac(Aes256CmacContext *ctx, void *dst)
Gets the context's output mac, finalizes the context.
void cmacAes128ContextCreate(Aes128CmacContext *out, const void *key)
Initialize an AES-128-CMAC context.
void cmacAes192ContextUpdate(Aes192CmacContext *ctx, const void *src, size_t size)
Updates AES-192-CMAC context with data to hash.
void cmacAes192ContextGetMac(Aes192CmacContext *ctx, void *dst)
Gets the context's output mac, finalizes the context.
void cmacAes128ContextGetMac(Aes128CmacContext *ctx, void *dst)
Gets the context's output mac, finalizes the context.
void cmacAes128ContextUpdate(Aes128CmacContext *ctx, const void *src, size_t size)
Updates AES-128-CMAC context with data to hash.
Context for AES-128 CMAC.
Definition: cmac.h:10
Context for AES-128 operations.
Definition: aes.h:41
Context for AES-192 CMAC.
Definition: cmac.h:20
Context for AES-192 operations.
Definition: aes.h:46
Context for AES-256 CMAC.
Definition: cmac.h:30
Context for AES-256 operations.
Definition: aes.h:51
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19