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 
22 #ifndef CRYPTO_AES_H
23 #define CRYPTO_AES_H
24 
25 #include <stdio.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <stdlib.h>
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 #define AES_KEY_SIZE 16
50 
55 struct aes_key_st {
57  uint32_t rd_key[4 * (AES_MAXNR + 1)];
58  int rounds;
60 };
61 
62 typedef struct aes_key_st AES_KEY;
63 
67 typedef struct {
69  uint32_t context[(4 * (AES_MAXNR + 1)) + 1];
71 
87 int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize);
88 
106 int aes_encrypt(const cipher_context_t *context, const uint8_t *plain_block,
107  uint8_t *cipher_block);
108 
126 int aes_decrypt(const cipher_context_t *context, const uint8_t *cipher_block,
127  uint8_t *plain_block);
128 
129 #ifdef __cplusplus
130 }
131 #endif
132 
134 #endif /* CRYPTO_AES_H */
aes_decrypt
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.
ciphers.h
Headers for the packet encryption class. They are used to encrypt single packets.
cipher_context_t
the context for cipher-operations
Definition: ciphers.h:67
aes_init
int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize)
initializes the AES Cipher-algorithm with the passed parameters
aes_encrypt
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.
aes_key_st
AES key.
Definition: aes.h:55
aes_context_t
the cipher_context_t-struct adapted for AES
Definition: aes.h:67