|
| 1 | +# DesfireCMAC |
| 2 | + |
| 3 | +DesfireCMAC is a C++ library that provides an implementation of the CMAC (Cipher-based Message Authentication Code) algorithm using AES (Advanced Encryption Standard) encryption. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | +- [Introduction](#introduction) |
| 7 | +- [Installation](#installation) |
| 8 | +- [Usage](#usage) |
| 9 | +- [API Reference](#api-reference) |
| 10 | +- [Author](#author) |
| 11 | + |
| 12 | +## Introduction |
| 13 | + |
| 14 | +DesfireCMAC is designed to generate a CMAC for a given data input using AES encryption. It utilizes the AES algorithm to generate subkeys and perform the necessary operations to calculate the CMAC. |
| 15 | + |
| 16 | +The library provides the following functions: |
| 17 | +- `initCMAC`: Initializes the CMAC algorithm with a key and initialization vector (IV). |
| 18 | +- `getCMAC`: Calculates the CMAC for a given data input. |
| 19 | +- `leftShift`: Performs a left shift operation on a vector. |
| 20 | +- `vecPrint`: Prints a vector in hexadecimal format. |
| 21 | +- `xorVec`: Performs an XOR operation between two vectors. |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +To use DesfireCMAC in your project, follow these steps: |
| 26 | + |
| 27 | +1. Clone the DesfireCMAC repository from GitHub: `git clone https://github.com/GtechGovind/DesfireCMAC.git`. |
| 28 | +2. Include the `CMAC.h` header file in your C++ source code. |
| 29 | +3. Make sure to link against the required dependencies, such as the AES library. |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +Here's an example of how to use the DesfireCMAC library: |
| 34 | + |
| 35 | +```cpp |
| 36 | +#include "CMAC.h" |
| 37 | + |
| 38 | +int main() { |
| 39 | + // Initialize CMAC with a key and IV |
| 40 | + vector<uint8_t> key = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; |
| 41 | + vector<uint8_t> iv = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; |
| 42 | + CMAC cmac; |
| 43 | + cmac.initCMAC(key, iv); |
| 44 | + |
| 45 | + // Calculate CMAC for data |
| 46 | + vector<uint8_t> data = {0x01, 0x02, 0x03, 0x04, 0x05}; |
| 47 | + vector<uint8_t> cmacResult = cmac.getCMAC(data); |
| 48 | + |
| 49 | + // Print the CMAC |
| 50 | + CMAC::vecPrint("CMAC", cmacResult); |
| 51 | + |
| 52 | + return 0; |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +## API Reference |
| 57 | + |
| 58 | +### CMAC Class |
| 59 | + |
| 60 | +#### `void initCMAC(const vector<uint8_t>& _key, const vector<uint8_t>& _iv)` |
| 61 | + |
| 62 | +Initializes the CMAC algorithm with a key and IV. |
| 63 | + |
| 64 | +- `_key`: The key for CMAC initialization. |
| 65 | +- `_iv`: The initialization vector for CMAC initialization. |
| 66 | + |
| 67 | +#### `vector<uint8_t> getCMAC(const vector<uint8_t>& _data)` |
| 68 | + |
| 69 | +Calculates the CMAC for a given data input. |
| 70 | + |
| 71 | +- `_data`: The input data for which the CMAC is to be calculated. |
| 72 | +- Returns: The calculated CMAC as a vector of bytes. |
| 73 | + |
| 74 | +#### `static void leftShift(const vector<uint8_t>& inputBuffer, vector<uint8_t>& outputBuffer)` |
| 75 | + |
| 76 | +Performs a left shift operation on a vector. |
| 77 | + |
| 78 | +- `inputBuffer`: The input vector to be left-shifted. |
| 79 | +- `outputBuffer`: The output vector to store the left-shifted result. |
| 80 | + |
| 81 | +#### `static void vecPrint(const string& message, const vector<unsigned char>& data)` |
| 82 | + |
| 83 | +Prints a vector in hexadecimal format. |
| 84 | + |
| 85 | +- `message`: The message to be printed before the vector. |
| 86 | +- `data`: The |
| 87 | + |
| 88 | + vector to be printed. |
| 89 | + |
| 90 | +#### `static void xorVec(const vector<uint8_t>& vector1, const vector<uint8_t>& vector2, vector<uint8_t>& result)` |
| 91 | + |
| 92 | +Performs an XOR operation between two vectors and stores the result in a third vector. |
| 93 | + |
| 94 | +- `vector1`: The first vector for XOR operation. |
| 95 | +- `vector2`: The second vector for XOR operation. |
| 96 | +- `result`: The resultant vector to store the XOR result. |
| 97 | + |
| 98 | +## Author |
| 99 | + |
| 100 | +DesfireCMAC is developed by Govind Yadav. |
0 commit comments