Coda Distributed File System
lib-src
rpc2
secure
rijndael-mikescott.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
8
This code is distributed "AS IS" without warranty of any kind under
9
the terms of the GNU Library General Public Licence Version 2, as
10
shown in the file LICENSE. The technical and financial contributors to
11
Coda are listed in the file CREDITS.
12
13
Additional copyrights
14
#*/
15
16
/* Wrapper around the rijndael (AES) implementation by Mike Scott */
17
#ifndef _AES_H_
18
#define _AES_H_
19
20
#include <stdint.h>
21
22
#define AES_MAXROUNDS MAXNR
23
#define AES_BLOCK_SIZE 16
24
25
typedef
struct
{
26
uint32_t
context
[120 *
sizeof
(
uint32_t
)];
27
uint8_t
Nk
,
Nb
,
Nr
;
28
uint32_t
rounds;
29
}
aes_context
;
30
#define aes_encrypt_ctx aes_context
31
#define aes_decrypt_ctx aes_context
32
33
/* Define this to the function used to setup tables during initialization */
34
#define AES_INIT_FUNC gentables()
35
36
/* arghh. this code uses globals... */
37
extern
int
Nb
,
Nr
,
Nk
;
38
extern
unsigned
int
fkey
[120],
rkey
[120];
39
40
static
inline
int
aes_encrypt_key(
const
uint8_t
*key,
int
keylen,
41
aes_encrypt_ctx
*ctx)
42
{
43
ctx->rounds = (keylen == 128) ? 10 : (keylen == 192) ? 12 : 14;
44
gkey
(
AES_BLOCK_SIZE
/
sizeof
(
uint32_t
), keylen / 8 /
sizeof
(
uint32_t
), key);
45
46
ctx->Nk =
Nk
;
47
ctx->Nb =
Nb
;
48
ctx->Nr =
Nr
;
49
memcpy(ctx->context,
fkey
, 120 *
sizeof
(
uint32_t
));
50
return
0;
51
}
52
53
static
inline
int
aes_decrypt_key(
const
uint8_t
*key,
int
keylen,
54
aes_decrypt_ctx
*ctx)
55
{
56
ctx->rounds = (keylen == 128) ? 10 : (keylen == 192) ? 12 : 14;
57
gkey
(
AES_BLOCK_SIZE
/
sizeof
(
uint32_t
), keylen / 8 /
sizeof
(
uint32_t
), key);
58
59
ctx->Nk =
Nk
;
60
ctx->Nb =
Nb
;
61
ctx->Nr =
Nr
;
62
memcpy(ctx->context,
rkey
, 120 *
sizeof
(
uint32_t
));
63
return
0;
64
}
65
66
static
inline
int
aes_encrypt(
const
uint8_t
in[
AES_BLOCK_SIZE
],
67
uint8_t
out[
AES_BLOCK_SIZE
],
68
const
aes_encrypt_ctx
*ctx)
69
{
70
Nk
= ctx->Nk;
71
Nb
= ctx->Nb;
72
Nr
= ctx->Nr;
73
memcpy(
fkey
, ctx->context, 120 *
sizeof
(
uint32_t
));
74
75
/* and I guess it also only supports in-place encryption/decryption */
76
if
(out != in)
77
memcpy(out, in,
AES_BLOCK_SIZE
);
78
encrypt
(out);
79
return
0;
80
}
81
82
static
inline
int
aes_decrypt(
const
uint8_t
in[
AES_BLOCK_SIZE
],
83
uint8_t
out[
AES_BLOCK_SIZE
],
84
const
aes_decrypt_ctx
*ctx)
85
{
86
Nk
= ctx->Nk;
87
Nb
= ctx->Nb;
88
Nr
= ctx->Nr;
89
memcpy(
rkey
, ctx->context, 120 *
sizeof
(
uint32_t
));
90
91
if
(out != in)
92
memcpy(out, in,
AES_BLOCK_SIZE
);
93
decrypt
(out);
94
return
0;
95
}
96
97
#endif
/* _AES_H_ */
context
int context
uint32_t
unsigned int uint32_t
Definition:
coda.h:105
uint8_t
unsigned char uint8_t
Definition:
coda.h:101
encrypt
void encrypt(char *buff)
Definition:
rijndael-mikescott.c:267
decrypt
void decrypt(char *buff)
Definition:
rijndael-mikescott.c:314
gkey
void gkey(int nb, int nk, char *key)
Definition:
rijndael-mikescott.c:195
aes_decrypt_ctx
#define aes_decrypt_ctx
Definition:
rijndael-mikescott.h:31
aes_encrypt_ctx
#define aes_encrypt_ctx
Definition:
rijndael-mikescott.h:30
fkey
unsigned int fkey[120]
Definition:
rijndael-mikescott.c:69
Nk
int Nk
Definition:
rijndael-mikescott.h:37
Nr
int Nr
Definition:
rijndael-mikescott.h:37
rkey
unsigned int rkey[120]
Definition:
rijndael-mikescott.h:38
AES_BLOCK_SIZE
#define AES_BLOCK_SIZE
Definition:
rijndael-mikescott.h:23
Nb
int Nb
Definition:
rijndael-mikescott.c:67
aes_context
Definition:
aes.h:34
aes_context::Nb
uint8_t Nb
Definition:
rijndael-mikescott.h:27
Generated by
1.9.4