Rearrange the file tree.
[u/mdw/catacomb] / symm / cast128.h
1 /* -*-c-*-
2 *
3 * The CAST-128 block cipher
4 *
5 * (c) 2000 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
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.
16 *
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.
21 *
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
28 /*----- Notes on the CAST-128 block cipher --------------------------------*
29 *
30 * CAST, designed by Carlisle Adams and Stafford Tavares, is a method for
31 * designing block ciphers, based around the concept of `bent functions'. It
32 * is described in the paper `Constructing Symmetric Ciphers using the CAST
33 * Design Procedure' by Carlisle Adams.
34 *
35 * CAST-128, defined in RFC2144, is a particular instance of the CAST design
36 * procedure, The cipher seems strong and fairly quick. The design procedure
37 * itself is patented, although the cipher CAST-128 is free to use.
38 *
39 * Although CAST ciphers are resistant to differential and linear
40 * cryptanalysis, some instances have been broken by more advanced techniques
41 * -- the CAST procedure does not guarantee a strong cipher. However,
42 * CAST-128 has so far resisted all attacks against it, and has now been
43 * accepted by the Canadian government for protection of all `Designated'
44 * material.
45 */
46
47 #ifndef CATACOMB_CAST128_H
48 #define CATACOMB_CAST128_H
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 /*----- Header files ------------------------------------------------------*/
55
56 #include <mLib/bits.h>
57
58 /*----- Magic numbers -----------------------------------------------------*/
59
60 #define CAST128_BLKSZ 8
61 #define CAST128_KEYSZ 16
62 #define CAST128_CLASS (N, B, 64)
63
64 extern const octet cast128_keysz[];
65
66 /*----- Data structures ---------------------------------------------------*/
67
68 typedef struct cast128_ctx {
69 unsigned r;
70 uint32 km[16];
71 octet kr[16];
72 } cast128_ctx;
73
74 /*----- Functions provided ------------------------------------------------*/
75
76 /* --- @cast128_init@ --- *
77 *
78 * Arguments: @cast128_ctx *k@ = pointer to key block to fill in
79 * @const void *buf@ = pointer to buffer of key material
80 * @size_t sz@ = size of key material
81 *
82 * Returns: ---
83 *
84 * Use: Initializes a CAST-128 key buffer. CAST-128 accepts
85 * 128-bit keys or shorter.
86 */
87
88 extern void cast128_init(cast128_ctx */*k*/,
89 const void */*buf*/, size_t /*sz*/);
90
91 /* --- @cast128_eblk@, @cast128_dblk@ --- *
92 *
93 * Arguments: @const cast128_ctx *k@ = pointer to key block
94 * @const uint32 s[2]@ = pointer to source block
95 * @uint32 d[2]@ = pointer to destination block
96 *
97 * Returns: ---
98 *
99 * Use: Low-level block encryption and decryption.
100 */
101
102 extern void cast128_eblk(const cast128_ctx */*k*/,
103 const uint32 */*s*/, uint32 */*d*/);
104
105 extern void cast128_dblk(const cast128_ctx */*k*/,
106 const uint32 */*s*/, uint32 */*d*/);
107
108 /*----- That's all, folks -------------------------------------------------*/
109
110 #ifdef __cplusplus
111 }
112 #endif
113
114 #endif