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