LoRaWANCH341 Library
Loading...
Searching...
No Matches
AES-CMAC.hpp
Go to the documentation of this file.
1
5#pragma once
6#include <vector>
7#include <cstddef>
8#include <cstdint>
9#include <array>
10
11
12class AESCMAC {
13public:
14/***
15 * @brief Calculate AES-CMAC for a given message and key
16 */
17static std::array<uint8_t, 16> calculate(const std::vector<uint8_t>& message,
18 const std::array<uint8_t, 16>& key);
19
20/***
21 * @brief Calculate AES-CMAC for a given message and key
22 */
23static void aes_encrypt(uint8_t* input, const uint8_t* key, uint8_t* output);
24
25/***
26 * @brief Test AES encryption on a single block
27 * @param input The input block to be encrypted
28 * @param key The encryption key
29 * @param output The encrypted output block
30 */
31 void test_encrypt_block(const std::array<uint8_t, 16> &input,
32 const std::array<uint8_t, 16> &key,
33 std::array<uint8_t, 16> &output);
34
35private:
36 static void generate_subkey(const std::array<uint8_t, 16> &key,
37 std::array<uint8_t, 16> &k1,
38 std::array<uint8_t, 16> &k2);
39 static void xor_block(uint8_t* output, const uint8_t* input, size_t len);
40 static void left_shift(uint8_t* input, uint8_t* output);
41};
AES-CMAC Implementation This class provides methods to calculate AES-CMAC and perform AES encryption.
Definition AES-CMAC.hpp:12
static std::array< uint8_t, 16 > calculate(const std::vector< uint8_t > &message, const std::array< uint8_t, 16 > &key)
Definition AES-CMAC.cpp:7
void test_encrypt_block(const std::array< uint8_t, 16 > &input, const std::array< uint8_t, 16 > &key, std::array< uint8_t, 16 > &output)
Definition AES-CMAC.cpp:129
static void xor_block(uint8_t *output, const uint8_t *input, size_t len)
Definition AES-CMAC.cpp:108
static void generate_subkey(const std::array< uint8_t, 16 > &key, std::array< uint8_t, 16 > &k1, std::array< uint8_t, 16 > &k2)
Definition AES-CMAC.cpp:56
static void left_shift(uint8_t *input, uint8_t *output)
Definition AES-CMAC.cpp:99
static void aes_encrypt(uint8_t *input, const uint8_t *key, uint8_t *output)
Definition AES-CMAC.cpp:114