3a65506d |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: rijndael.h,v 1.1 2000/06/17 11:56:07 mdw Exp $ |
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 $ |
33 | * Revision 1.1 2000/06/17 11:56:07 mdw |
34 | * New cipher. |
35 | * |
36 | */ |
37 | |
38 | /*----- Notes on the Rijndael block cipher --------------------------------* |
39 | * |
40 | * Invented by Joan Daemen and Vincent Rijmen, Rijndael is a fast and |
41 | * relatively simple 128-bit block cipher proposed by the designers as an AES |
42 | * candidate. At the time of writing, the AES winner hasn't been decided. |
43 | * Rijnadel is fast, but has a low security margin. I recommend waiting |
44 | * before using Rijndael for any sensitive applications. |
45 | */ |
46 | |
47 | #ifndef CATACOMB_RIJNDAEL_H |
48 | #define CATACOMB_RIJNDAEL_H |
49 | |
50 | #ifdef __cplusplus |
51 | extern "C" { |
52 | #endif |
53 | |
54 | /*----- Header files ------------------------------------------------------*/ |
55 | |
56 | #include <stddef.h> |
57 | |
58 | #include <mLib/bits.h> |
59 | |
60 | /*----- Magical numbers ---------------------------------------------------*/ |
61 | |
62 | #define RIJNDAEL_BLKSZ 16 |
63 | #define RIJNDAEL_KEYSZ 32 |
64 | #define RIJNDAEL_CLASS (N, L, 128) |
65 | |
66 | extern const octet rijndael_keysz[]; |
67 | |
68 | /*----- Data structures ---------------------------------------------------*/ |
69 | |
70 | #define RIJNDAEL_MAXROUNDS 32 |
71 | #define RIJNDAEL_KWORDS ((RIJNDAEL_MAXROUNDS + 1) * (RIJNDAEL_BLKSZ / 4)) |
72 | |
73 | typedef struct rijndael_ctx { |
74 | unsigned nr; |
75 | uint32 w[RIJNDAEL_KWORDS]; |
76 | uint32 wi[RIJNDAEL_KWORDS]; |
77 | } rijndael_ctx; |
78 | |
79 | /*----- Functions provided ------------------------------------------------*/ |
80 | |
81 | /* --- @rijndael_init@ --- * |
82 | * |
83 | * Arguments: @rijndael_ctx *k@ = pointer to context to initialize |
84 | * @const void *buf@ = pointer to buffer of key material |
85 | * @size_t sz@ = size of the key material |
86 | * |
87 | * Returns: --- |
88 | * |
89 | * Use: Initializes a Rijndael context with a particular key. This |
90 | * implementation of Rijndael doesn't impose any particular |
91 | * limits on the key size except that it must be multiple of 4 |
92 | * bytes long. 256 bits seems sensible, though. |
93 | */ |
94 | |
95 | extern void rijndael_init(rijndael_ctx */*k*/, |
96 | const void */*buf*/, size_t /*sz*/); |
97 | |
98 | /* --- @rijndael_eblk@, @rijndael_dblk@ --- * |
99 | * |
100 | * Arguments: @const rijndael_ctx *k@ = pointer to Rijndael context |
101 | * @const uint32 s[4]@ = pointer to source block |
102 | * @uint32 d[4]@ = pointer to destination block |
103 | * |
104 | * Returns: --- |
105 | * |
106 | * Use: Low-level block encryption and decryption. |
107 | */ |
108 | |
109 | extern void rijndael_eblk(const rijndael_ctx */*k*/, |
110 | const uint32 */*s*/, uint32 */*dst*/); |
111 | extern void rijndael_dblk(const rijndael_ctx */*k*/, |
112 | const uint32 */*s*/, uint32 */*dst*/); |
113 | |
114 | /*----- That's all, folks -------------------------------------------------*/ |
115 | |
116 | #ifdef __cplusplus |
117 | } |
118 | #endif |
119 | |
120 | #endif |