aes.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Freie Universität Berlin, Computer Systems & Telematics
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
32 #include <stdint.h>
33 #include "crypto/ciphers.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 typedef uint32_t u32;
40 typedef uint16_t u16;
41 typedef uint8_t u8;
42 
43 # define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ \
44  ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
45 # define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); \
46  (ct)[1] = (u8)((st) >> 16); \
47  (ct)[2] = (u8)((st) >> 8); \
48  (ct)[3] = (u8)(st); }
49 
50 #define AES_MAXNR 14
51 #define AES_BLOCK_SIZE 16
52 
57 #define AES_KEY_SIZE_128 16
58 #define AES_KEY_SIZE_192 24
59 #define AES_KEY_SIZE_256 32
65 typedef struct {
67  uint32_t context[(4 * (AES_MAXNR + 1)) + 1];
69 
85 int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize);
86 
104 int aes_encrypt(const cipher_context_t *context, const uint8_t *plain_block,
105  uint8_t *cipher_block);
106 
124 int aes_decrypt(const cipher_context_t *context, const uint8_t *cipher_block,
125  uint8_t *plain_block);
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 
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:65
the context for cipher-operations
Definition: ciphers.h:77