3 * The Rijndael block cipher
5 * (c) 2000 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Notes on the Rijndael block cipher --------------------------------*
30 * Invented by Joan Daemen and Vincent Rijmen, Rijndael is a fast, elegant
31 * and relatively simple 128-bit block cipher. It was chosen by NIST to be
32 * the new Advanced Encryption Standard (AES) algorithm.
34 * Rijnadel appears to have a low security margin. I recommend waiting
35 * before using Rijndael for any sensitive applications.
38 #ifndef CATACOMB_RIJNDAEL_H
39 #define CATACOMB_RIJNDAEL_H
45 /*----- Header files ------------------------------------------------------*/
49 #include <mLib/bits.h>
51 /*----- Magical numbers ---------------------------------------------------*/
53 #define RIJNDAEL_BLKSZ 16
54 #define RIJNDAEL_KEYSZ 32
55 #define RIJNDAEL_CLASS (N, B, 128)
57 extern const octet rijndael_keysz[];
59 /*----- Data structures ---------------------------------------------------*/
61 #define RIJNDAEL_MAXROUNDS 16
62 #define RIJNDAEL_KWORDS ((RIJNDAEL_MAXROUNDS + 1) * 8)
64 typedef struct rijndael_ctx {
66 uint32 w[RIJNDAEL_KWORDS];
67 uint32 wi[RIJNDAEL_KWORDS];
70 /*----- Functions provided ------------------------------------------------*/
72 /* --- @rijndael_setup@ --- *
74 * Arguments: @rijndael_ctx *k@ = pointer to context to initialize
75 * @unsigned nb@ = number of words in the block
76 * @const void *buf@ = pointer to buffer of key material
77 * @size_t sz@ = size of the key material
81 * Use: Low-level key-scheduling. Don't call this directly.
84 extern void rijndael_setup(rijndael_ctx */*k*/, unsigned /*nb*/,
85 const void */*buf*/, size_t /*sz*/);
87 /* --- @rijndael_init@ --- *
89 * Arguments: @rijndael_ctx *k@ = pointer to context to initialize
90 * @const void *buf@ = pointer to buffer of key material
91 * @size_t sz@ = size of the key material
95 * Use: Initializes a Rijndael context with a particular key. This
96 * implementation of Rijndael doesn't impose any particular
97 * limits on the key size except that it must be multiple of 4
98 * bytes long. 256 bits seems sensible, though.
101 extern void rijndael_init(rijndael_ctx */*k*/,
102 const void */*buf*/, size_t /*sz*/);
104 /* --- @rijndael_eblk@, @rijndael_dblk@ --- *
106 * Arguments: @const rijndael_ctx *k@ = pointer to Rijndael context
107 * @const uint32 s[4]@ = pointer to source block
108 * @uint32 d[4]@ = pointer to destination block
112 * Use: Low-level block encryption and decryption.
115 extern void rijndael_eblk(const rijndael_ctx */*k*/,
116 const uint32 */*s*/, uint32 */*dst*/);
117 extern void rijndael_dblk(const rijndael_ctx */*k*/,
118 const uint32 */*s*/, uint32 */*dst*/);
120 /*----- That's all, folks -------------------------------------------------*/