Coda Distributed File System
aes.h
Go to the documentation of this file.
1/* BLURB lgpl
2 Coda File System
3 Release 6
4
5 Copyright (c) 2006 Carnegie Mellon University
6 Additional copyrights listed below
7
8This code is distributed "AS IS" without warranty of any kind under
9the terms of the GNU Library General Public Licence Version 2, as
10shown in the file LICENSE. The technical and financial contributors to
11Coda are listed in the file CREDITS.
12
13 Additional copyrights
14#*/
15
16/* Wrapper around the rijndael (v3.0) reference implementation */
17
18#ifndef _AES_H_
19#define _AES_H_
20
21#include <stdint.h>
22
23#include "rijndael-alg-fst.h"
24
25#define AES_MAXROUNDS MAXNR
26#define AES_BLOCK_SIZE 16
27
28typedef union {
31 uint64_t u64[AES_BLOCK_SIZE / sizeof(uint64_t)];
32} aes_block;
33
34typedef struct {
38#define aes_encrypt_ctx aes_context
39#define aes_decrypt_ctx aes_context
40
41/* Define this to the function used to setup tables during initialization */
42/* #define AES_INIT_FUNC */
43
44static inline int aes_encrypt_key(const uint8_t *key, int keylen,
45 aes_encrypt_ctx *ctx)
46{
47 ctx->rounds = rijndaelKeySetupEnc(ctx->context, key, keylen);
48 return 0;
49}
50
51static inline int aes_decrypt_key(const uint8_t *key, int keylen,
52 aes_decrypt_ctx *ctx)
53{
54 ctx->rounds = rijndaelKeySetupDec(ctx->context, key, keylen);
55 return 0;
56}
57
58static inline int aes_encrypt(const aes_block *in, aes_block *out,
59 const aes_encrypt_ctx *ctx)
60{
61 rijndaelEncrypt(ctx->context, ctx->rounds, in->u8, out->u8);
62 return 0;
63}
64
65static inline int aes_decrypt(const aes_block *in, aes_block *out,
66 const aes_decrypt_ctx *ctx)
67{
68 rijndaelDecrypt(ctx->context, ctx->rounds, in->u8, out->u8);
69 return 0;
70}
71
72#endif /* _AES_H_ */
#define aes_decrypt_ctx
Definition: aes.h:39
#define aes_encrypt_ctx
Definition: aes.h:38
#define AES_BLOCK_SIZE
Definition: aes.h:26
#define AES_MAXROUNDS
Definition: aes.h:25
int context
unsigned int uint32_t
Definition: coda.h:105
unsigned char uint8_t
Definition: coda.h:101
int rijndaelKeySetupDec(u32 rk[], const u8 cipherKey[], int keyBits)
Definition: rijndael-alg-fst.c:864
void rijndaelDecrypt(const u32 rk[], int Nr, const u8 ct[16], u8 pt[16])
Definition: rijndael-alg-fst.c:1089
int rijndaelKeySetupEnc(u32 rk[], const u8 cipherKey[], int keyBits)
Definition: rijndael-alg-fst.c:774
void rijndaelEncrypt(const u32 rk[], int Nr, const u8 pt[16], u8 ct[16])
Definition: rijndael-alg-fst.c:908
unsigned int u32
Definition: rijndael-alg-fst.h:36
unsigned char u8
Definition: rijndael-alg-fst.h:34
Definition: aes.h:34
uint32_t rounds
Definition: aes.h:36
Definition: aes.h:28
uint8_t u8[AES_BLOCK_SIZE]
Definition: aes.h:29