chiark / gitweb /
ec-bin (ec_binproj): Make curve setup faster.
[catacomb] / rijndael-base.h
1 /* -*-c-*-
2  *
3  * $Id: rijndael-base.h,v 1.2 2004/04/08 01:36:15 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 #ifndef CATACOMB_RIJNDAEL_BASE_H
31 #define CATACOMB_RIJNDAEL_BASE_H
32
33 #ifdef __cplusplus
34   extern "C" {
35 #endif
36
37 /*----- Header files ------------------------------------------------------*/
38
39 #include <mLib/bits.h>
40
41 /*----- Constant tables ---------------------------------------------------*/
42
43 extern const octet rijndael_s[256];
44 extern const octet rijndael_si[256];
45 extern const uint32 rijndael_t[4][256];
46 extern const uint32 rijndael_ti[4][256];
47 extern const uint32 rijndael_u[4][256];
48 extern const octet rijndael_rcon[];
49
50 #define S rijndael_s
51 #define SI rijndael_si
52 #define T rijndael_t
53 #define TI rijndael_ti
54 #define U rijndael_u
55 #define RCON rijndael_rcon
56
57 /*----- Handy macros ------------------------------------------------------*/
58
59 #define SUB(s, a, b, c, d)                                              \
60   (s[U8((a) >> 24)] << 24 | s[U8((b) >> 16)] << 16 |                    \
61    s[U8((c) >>  8)] <<  8 | s[U8((d) >>  0)] <<  0)
62
63 #define MIX(t, a, b, c, d)                                              \
64    (t[0][U8((a) >> 24)] ^ t[1][U8((b) >> 16)] ^                         \
65     t[2][U8((c) >>  8)] ^ t[3][U8((d) >>  0)])
66
67 /*----- That's all, folks -------------------------------------------------*/
68
69 #ifdef __cplusplus
70   }
71 #endif
72
73 #endif