aes.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2013 Freie Universität Berlin, Computer Systems & Telematics
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
29 #include <stdint.h>
30 #include "crypto/ciphers.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 typedef uint32_t u32;
37 typedef uint16_t u16;
38 typedef uint8_t u8;
39 
40 # define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ \
41  ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
42 # define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); \
43  (ct)[1] = (u8)((st) >> 16); \
44  (ct)[2] = (u8)((st) >> 8); \
45  (ct)[3] = (u8)(st); }
46 
47 #define AES_MAXNR 14
48 #define AES_BLOCK_SIZE 16
49 
54 #define AES_KEY_SIZE_128 16
55 #define AES_KEY_SIZE_192 24
56 #define AES_KEY_SIZE_256 32
62 typedef struct {
64  uint32_t context[(4 * (AES_MAXNR + 1)) + 1];
66 
82 int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize);
83 
101 int aes_encrypt(const cipher_context_t *context, const uint8_t *plain_block,
102  uint8_t *cipher_block);
103 
121 int aes_decrypt(const cipher_context_t *context, const uint8_t *cipher_block,
122  uint8_t *plain_block);
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 
int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize)
initializes the AES Cipher-algorithm with the passed parameters
int aes_decrypt(const cipher_context_t *context, const uint8_t *cipher_block, uint8_t *plain_block)
decrypts one cipher-block and saves the plain-block in plainBlock.
int aes_encrypt(const cipher_context_t *context, const uint8_t *plain_block, uint8_t *cipher_block)
encrypts one plainBlock-block and saves the result in cipherblock.
Headers for the packet encryption class.
the cipher_context_t-struct adapted for AES
Definition: aes.h:62
the context for cipher-operations
Definition: ciphers.h:74