math/mpreduce.h: Missing include files.
[u/mdw/catacomb] / symm / twofish.h
CommitLineData
8dd8c294 1/* -*-c-*-
2 *
8dd8c294 3 * The Twofish block cipher
4 *
5 * (c) 2000 Straylight/Edgeware
6 */
7
45c0fd36 8/*----- Licensing notice --------------------------------------------------*
8dd8c294 9 *
10 * This file is part of Catacomb.
11 *
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.
45c0fd36 16 *
8dd8c294 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.
45c0fd36 21 *
8dd8c294 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,
25 * MA 02111-1307, USA.
26 */
27
8dd8c294 28/*----- Notes on the Twofish block cipher ---------------------------------*
29 *
30 * Twofish was designed by Bruce Schneier, John Kelsey, Doug Whiting, David
31 * Wagner, Chris Hall and Niels Ferguson. The algorithm is unpatented and
fbac94e6 32 * free for anyone to use. It was one of the five AES finalist algorithms.
8dd8c294 33 *
34 * Twofish is a complex cipher offering various space and time tradeoffs.
35 * This implementation has a heavy key schedule and fast bulk encryption.
36 */
37
38#ifndef CATACOMB_TWOFISH_H
39#define CATACOMB_TWOFISH_H
40
41#ifdef __cplusplus
42 extern "C" {
43#endif
44
45/*----- Header files ------------------------------------------------------*/
46
47#include <stddef.h>
48
49#include <mLib/bits.h>
50
51/*----- Magical numbers ---------------------------------------------------*/
52
53#define TWOFISH_BLKSZ 16
54#define TWOFISH_KEYSZ 32
55#define TWOFISH_CLASS (N, L, 128)
56
57extern const octet twofish_keysz[];
58
59/*----- Data structures ---------------------------------------------------*/
60
61typedef struct twofish_ctx {
62 uint32 k[40];
63 uint32 g[4][256];
64} twofish_ctx;
65
574d8527 66typedef struct twofish_fk {
67 uint32 t0[8], t23[8], t4[2];
68 octet t1[32];
69} twofish_fk;
70
8dd8c294 71/*----- Functions provided ------------------------------------------------*/
72
574d8527 73/* --- @twofish_initfk@ --- *
74 *
75 * Arguments: @twofish_ctx *k@ = pointer to key block to fill in
76 * @const void *buf@ = pointer to buffer of key material
77 * @size_t sz@ = size of key material
78 * @const twofish_fk *fk@ = family-key information
79 *
80 * Returns: ---
81 *
82 * Use: Does the underlying Twofish key initialization with family
83 * key. Pass in a family-key structure initialized to
84 * all-bits-zero for a standard key schedule.
85 */
86
87extern void twofish_initfk(twofish_ctx */*k*/, const void */*buf*/,
88 size_t /*sz*/, const twofish_fk */*fk*/);
89
8dd8c294 90/* --- @twofish_init@ --- *
91 *
92 * Arguments: @twofish_ctx *k@ = pointer to key block to fill in
93 * @const void *buf@ = pointer to buffer of key material
94 * @size_t sz@ = size of key material
95 *
96 * Returns: ---
97 *
98 * Use: Initializes a Twofish key buffer. Twofish accepts keys of up
99 * to 256 bits in length.
100 */
101
102extern void twofish_init(twofish_ctx */*k*/,
103 const void */*buf*/, size_t /*sz*/);
104
574d8527 105/* --- @twofish_fkinit@ --- *
106 *
107 * Arguments: @twofish_fk *fk@ = pointer to family key block
108 * @const void *buf@ = pointer to buffer of key material
109 * @size_t sz@ = size of key material
110 *
111 * Returns: ---
112 *
113 * Use: Initializes a family-key buffer. This implementation allows
114 * family keys of any size acceptable to the Twofish algorithm.
115 */
116
117extern void twofish_fkinit(twofish_fk */*fk*/,
118 const void */*buf*/, size_t /*sz*/);
119
8dd8c294 120/* --- @twofish_eblk@, @twofish_dblk@ --- *
121 *
122 * Arguments: @const twofish_ctx *k@ = pointer to key block
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
131extern void twofish_eblk(const twofish_ctx */*k*/,
132 const uint32 */*s*/, uint32 */*d*/);
133
134extern void twofish_dblk(const twofish_ctx */*k*/,
db9326f0 135 const uint32 */*s*/, uint32 */*d*/);
8dd8c294 136
137/*----- That's all, folks -------------------------------------------------*/
138
139#ifdef __cplusplus
140 }
141#endif
142
143#endif