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 
41 /* This controls loop-unrolling in aes_core.c */
42 #undef FULL_UNROLL
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 #define AES_KEY_SIZE 16
53 
58 struct aes_key_st {
60  uint32_t rd_key[4 * (AES_MAXNR + 1)];
61  int rounds;
63 };
64 
65 typedef struct aes_key_st AES_KEY;
66 
70 typedef struct {
72  uint32_t context[(4 * (AES_MAXNR + 1)) + 1];
74 
87 int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize);
88 
104 int aes_encrypt(const cipher_context_t *context, const uint8_t *plain_block,
105  uint8_t *cipher_block);
106 
123 int aes_decrypt(const cipher_context_t *context, const uint8_t *cipher_block,
124  uint8_t *plain_block);
125 
126 #ifdef __cplusplus
127 }
128 #endif
129 
131 #endif /* CRYPTO_AES_H */
the context for cipher-operations
Definition: ciphers.h:74
the cipher_context_t-struct adapted for AES
Definition: aes.h:70
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.
Definition: aes.h:58
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.
stdio.h wrapper for MSP430
Headers for the packet encryption class.
stdlib.h wrapper for MSP430
int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize)
initializes the AES Cipher-algorithm with the passed parameters