8b3d7f30 |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: rijndael-base.h,v 1.1 2001/05/07 17:31:37 mdw Exp $ |
4 | * |
5 | * Internal header for Rijndael implementation |
6 | * |
7 | * (c) 2001 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of Catacomb. |
13 | * |
14 | * Catacomb is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU Library General Public License as |
16 | * published by the Free Software Foundation; either version 2 of the |
17 | * License, or (at your option) any later version. |
18 | * |
19 | * Catacomb is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU Library General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU Library General Public |
25 | * License along with Catacomb; if not, write to the Free |
26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: rijndael-base.h,v $ |
33 | * Revision 1.1 2001/05/07 17:31:37 mdw |
34 | * Centralize Rijndael tables and key scheduling. |
35 | * |
36 | */ |
37 | |
38 | #ifndef CATACOMB_RIJNDAEL_BASE_H |
39 | #define CATACOMB_RIJNDAEL_BASE_H |
40 | |
41 | #ifdef __cplusplus |
42 | extern "C" { |
43 | #endif |
44 | |
45 | /*----- Header files ------------------------------------------------------*/ |
46 | |
47 | #include <mLib/bits.h> |
48 | |
49 | /*----- Constant tables ---------------------------------------------------*/ |
50 | |
51 | extern const octet rijndael_s[256]; |
52 | extern const octet rijndael_si[256]; |
53 | extern const uint32 rijndael_t[4][256]; |
54 | extern const uint32 rijndael_ti[4][256]; |
55 | extern const uint32 rijndael_u[4][256]; |
56 | extern const octet rijndael_rcon[]; |
57 | |
58 | #define S rijndael_s |
59 | #define SI rijndael_si |
60 | #define T rijndael_t |
61 | #define TI rijndael_ti |
62 | #define U rijndael_u |
63 | #define RCON rijndael_rcon |
64 | |
65 | /*----- Handy macros ------------------------------------------------------*/ |
66 | |
67 | #define SUB(s, a, b, c, d) \ |
68 | (s[U8((a) >> 0)] << 0 | s[U8((b) >> 8)] << 8 | \ |
69 | s[U8((c) >> 16)] << 16 | s[U8((d) >> 24)] << 24) |
70 | |
71 | #define MIX(t, a, b, c, d) \ |
72 | (t[0][U8((a) >> 0)] ^ t[1][U8((b) >> 8)] ^ \ |
73 | t[2][U8((c) >> 16)] ^ t[3][U8((d) >> 24)]) |
74 | |
75 | /*----- That's all, folks -------------------------------------------------*/ |
76 | |
77 | #ifdef __cplusplus |
78 | } |
79 | #endif |
80 | |
81 | #endif |