3a65506d |
1 | /* -*-c-*- |
2 | * |
7cee294a |
3 | * $Id: rijndael.h,v 1.3 2001/05/07 17:31:53 mdw Exp $ |
3a65506d |
4 | * |
5 | * The Rijndael block cipher |
6 | * |
7 | * (c) 2000 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.h,v $ |
7cee294a |
33 | * Revision 1.3 2001/05/07 17:31:53 mdw |
34 | * Separate out key scheduling. |
35 | * |
fbac94e6 |
36 | * Revision 1.2 2000/10/08 15:48:58 mdw |
37 | * Update comments now that AES has been chosen. |
38 | * |
3a65506d |
39 | * Revision 1.1 2000/06/17 11:56:07 mdw |
40 | * New cipher. |
41 | * |
42 | */ |
43 | |
44 | /*----- Notes on the Rijndael block cipher --------------------------------* |
45 | * |
fbac94e6 |
46 | * Invented by Joan Daemen and Vincent Rijmen, Rijndael is a fast, elegant |
47 | * and relatively simple 128-bit block cipher. It was chosen by NIST to be |
48 | * the new Advanced Encryption Standard (AES) algorithm. |
49 | * |
50 | * Rijnadel appears to have a low security margin. I recommend waiting |
3a65506d |
51 | * before using Rijndael for any sensitive applications. |
52 | */ |
53 | |
54 | #ifndef CATACOMB_RIJNDAEL_H |
55 | #define CATACOMB_RIJNDAEL_H |
56 | |
57 | #ifdef __cplusplus |
58 | extern "C" { |
59 | #endif |
60 | |
61 | /*----- Header files ------------------------------------------------------*/ |
62 | |
63 | #include <stddef.h> |
64 | |
65 | #include <mLib/bits.h> |
66 | |
67 | /*----- Magical numbers ---------------------------------------------------*/ |
68 | |
69 | #define RIJNDAEL_BLKSZ 16 |
70 | #define RIJNDAEL_KEYSZ 32 |
71 | #define RIJNDAEL_CLASS (N, L, 128) |
72 | |
73 | extern const octet rijndael_keysz[]; |
74 | |
75 | /*----- Data structures ---------------------------------------------------*/ |
76 | |
7cee294a |
77 | #define RIJNDAEL_MAXROUNDS 16 |
78 | #define RIJNDAEL_KWORDS ((RIJNDAEL_MAXROUNDS + 1) * 8) |
3a65506d |
79 | |
80 | typedef struct rijndael_ctx { |
81 | unsigned nr; |
82 | uint32 w[RIJNDAEL_KWORDS]; |
83 | uint32 wi[RIJNDAEL_KWORDS]; |
84 | } rijndael_ctx; |
85 | |
86 | /*----- Functions provided ------------------------------------------------*/ |
87 | |
7cee294a |
88 | /* --- @rijndael_setup@ --- * |
89 | * |
90 | * Arguments: @rijndael_ctx *k@ = pointer to context to initialize |
91 | * @unsigned nb@ = number of words in the block |
92 | * @const void *buf@ = pointer to buffer of key material |
93 | * @size_t sz@ = size of the key material |
94 | * |
95 | * Returns: --- |
96 | * |
97 | * Use: Low-level key-scheduling. Don't call this directly. |
98 | */ |
99 | |
100 | extern void rijndael_setup(rijndael_ctx */*k*/, unsigned /*nb*/, |
101 | const void */*buf*/, size_t /*sz*/); |
102 | |
3a65506d |
103 | /* --- @rijndael_init@ --- * |
104 | * |
105 | * Arguments: @rijndael_ctx *k@ = pointer to context to initialize |
106 | * @const void *buf@ = pointer to buffer of key material |
107 | * @size_t sz@ = size of the key material |
108 | * |
109 | * Returns: --- |
110 | * |
111 | * Use: Initializes a Rijndael context with a particular key. This |
112 | * implementation of Rijndael doesn't impose any particular |
113 | * limits on the key size except that it must be multiple of 4 |
114 | * bytes long. 256 bits seems sensible, though. |
115 | */ |
116 | |
117 | extern void rijndael_init(rijndael_ctx */*k*/, |
118 | const void */*buf*/, size_t /*sz*/); |
119 | |
120 | /* --- @rijndael_eblk@, @rijndael_dblk@ --- * |
121 | * |
122 | * Arguments: @const rijndael_ctx *k@ = pointer to Rijndael context |
123 | * @const uint32 s[4]@ = pointer to source block |
124 | * @uint32 d[4]@ = pointer to destination block |
125 | * |
126 | * Returns: --- |
127 | * |
128 | * Use: Low-level block encryption and decryption. |
129 | */ |
130 | |
131 | extern void rijndael_eblk(const rijndael_ctx */*k*/, |
132 | const uint32 */*s*/, uint32 */*dst*/); |
133 | extern void rijndael_dblk(const rijndael_ctx */*k*/, |
134 | const uint32 */*s*/, uint32 */*dst*/); |
135 | |
136 | /*----- That's all, folks -------------------------------------------------*/ |
137 | |
138 | #ifdef __cplusplus |
139 | } |
140 | #endif |
141 | |
142 | #endif |