hashsum.1: Write some notes about compatibility with GNU Coreutils.
[u/mdw/catacomb] / twofish.h
CommitLineData
8dd8c294 1/* -*-c-*-
2 *
b817bfc6 3 * $Id: twofish.h,v 1.5 2004/04/08 01:36:15 mdw Exp $
8dd8c294 4 *
5 * The Twofish block cipher
6 *
7 * (c) 2000 Straylight/Edgeware
8 */
9
45c0fd36 10/*----- Licensing notice --------------------------------------------------*
8dd8c294 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 *
8dd8c294 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 *
8dd8c294 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
8dd8c294 30/*----- Notes on the Twofish block cipher ---------------------------------*
31 *
32 * Twofish was designed by Bruce Schneier, John Kelsey, Doug Whiting, David
33 * Wagner, Chris Hall and Niels Ferguson. The algorithm is unpatented and
fbac94e6 34 * free for anyone to use. It was one of the five AES finalist algorithms.
8dd8c294 35 *
36 * Twofish is a complex cipher offering various space and time tradeoffs.
37 * This implementation has a heavy key schedule and fast bulk encryption.
38 */
39
40#ifndef CATACOMB_TWOFISH_H
41#define CATACOMB_TWOFISH_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 TWOFISH_BLKSZ 16
56#define TWOFISH_KEYSZ 32
57#define TWOFISH_CLASS (N, L, 128)
58
59extern const octet twofish_keysz[];
60
61/*----- Data structures ---------------------------------------------------*/
62
63typedef struct twofish_ctx {
64 uint32 k[40];
65 uint32 g[4][256];
66} twofish_ctx;
67
574d8527 68typedef struct twofish_fk {
69 uint32 t0[8], t23[8], t4[2];
70 octet t1[32];
71} twofish_fk;
72
8dd8c294 73/*----- Functions provided ------------------------------------------------*/
74
574d8527 75/* --- @twofish_initfk@ --- *
76 *
77 * Arguments: @twofish_ctx *k@ = pointer to key block to fill in
78 * @const void *buf@ = pointer to buffer of key material
79 * @size_t sz@ = size of key material
80 * @const twofish_fk *fk@ = family-key information
81 *
82 * Returns: ---
83 *
84 * Use: Does the underlying Twofish key initialization with family
85 * key. Pass in a family-key structure initialized to
86 * all-bits-zero for a standard key schedule.
87 */
88
89extern void twofish_initfk(twofish_ctx */*k*/, const void */*buf*/,
90 size_t /*sz*/, const twofish_fk */*fk*/);
91
8dd8c294 92/* --- @twofish_init@ --- *
93 *
94 * Arguments: @twofish_ctx *k@ = pointer to key block to fill in
95 * @const void *buf@ = pointer to buffer of key material
96 * @size_t sz@ = size of key material
97 *
98 * Returns: ---
99 *
100 * Use: Initializes a Twofish key buffer. Twofish accepts keys of up
101 * to 256 bits in length.
102 */
103
104extern void twofish_init(twofish_ctx */*k*/,
105 const void */*buf*/, size_t /*sz*/);
106
574d8527 107/* --- @twofish_fkinit@ --- *
108 *
109 * Arguments: @twofish_fk *fk@ = pointer to family key block
110 * @const void *buf@ = pointer to buffer of key material
111 * @size_t sz@ = size of key material
112 *
113 * Returns: ---
114 *
115 * Use: Initializes a family-key buffer. This implementation allows
116 * family keys of any size acceptable to the Twofish algorithm.
117 */
118
119extern void twofish_fkinit(twofish_fk */*fk*/,
120 const void */*buf*/, size_t /*sz*/);
121
8dd8c294 122/* --- @twofish_eblk@, @twofish_dblk@ --- *
123 *
124 * Arguments: @const twofish_ctx *k@ = pointer to key block
125 * @const uint32 s[4]@ = pointer to source block
126 * @uint32 d[4]@ = pointer to destination block
127 *
128 * Returns: ---
129 *
130 * Use: Low-level block encryption and decryption.
131 */
132
133extern void twofish_eblk(const twofish_ctx */*k*/,
134 const uint32 */*s*/, uint32 */*d*/);
135
136extern void twofish_dblk(const twofish_ctx */*k*/,
db9326f0 137 const uint32 */*s*/, uint32 */*d*/);
8dd8c294 138
139/*----- That's all, folks -------------------------------------------------*/
140
141#ifdef __cplusplus
142 }
143#endif
144
145#endif