chiark / gitweb /
Version bump.
[catacomb] / rc2.h
1 /* -*-c-*-
2  *
3  * $Id: rc2.h,v 1.1 2000/06/17 11:54:34 mdw Exp $
4  *
5  * The RC2 block cipher
6  *
7  * (c) 2000 Straylight/Edgeware
8  */
9
10 /*----- Licensing notice --------------------------------------------------* 
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.
18  * 
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.
23  * 
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
30 /*----- Revision history --------------------------------------------------* 
31  *
32  * $Log: rc2.h,v $
33  * Revision 1.1  2000/06/17 11:54:34  mdw
34  * New cipher.
35  *
36  */
37
38 /*----- Notes on the RC2 block cipher -------------------------------------*
39  *
40  * RC2 was designed by Ron Rivest, and for a long time was a trade secret of
41  * RSA Data Security Inc.  Like RC4, it leaked out, and has now been
42  * described in RFC2268.  The RC2 key schedule is known to have some
43  * weaknesses, although I'm not aware of any major results against the cipher
44  * itself.  I'm also not aware of any legal problems with using the RC2
45  * cipher.
46  *
47  * The oddest feature in the cipher is the key schedule.  It expands the
48  * initial key material to 128 bytes, and then `brain-damages' it, according
49  * to a supplied `effective key-bits' parameter, before expanding the
50  * remaining key material back into the buffer.
51  *
52  * The key schedule allows second preimages to be computed trivially.
53  */
54
55 #ifndef CATACOMB_RC2_H
56 #define CATACOMB_RC2_H
57
58 #ifdef __cplusplus
59   extern "C" {
60 #endif
61
62 /*----- Header files ------------------------------------------------------*/
63
64 #include <stddef.h>
65
66 #include <mLib/bits.h>
67
68 /*----- Magical numbers ---------------------------------------------------*/
69
70 #define RC2_BLKSZ 8
71 #define RC2_KEYSZ 16
72 #define RC2_CLASS (N, L, 64)
73
74 extern const octet rc2_keysz[];
75
76 /*----- Data structures ---------------------------------------------------*/
77
78 typedef struct rc2_ctx {
79   uint16 k[64];
80 } rc2_ctx;
81
82 /*----- Functions provided ------------------------------------------------*/
83
84 /* --- @rc2_braindamage@ --- *
85  *
86  * Arguments:   @rc2_ctx *k@ = pointer to context to initialize
87  *              @const void *buf@ = pointer to key material
88  *              @size_t sz@ = size of key material in bytes
89  *              @unsigned eb@ = desired effective key size, in bits
90  *
91  * Returns:     ---
92  *
93  * Use:         Initializes an RC2 expanded key, and braindamages it to the
94  *              requested effective key size.  This is here for compatibility
95  *              reasons.  You should be using @rc2_init@ in normal code,
96  *              which doesn't actually apply braindamage.
97  */
98
99 extern void rc2_braindamage(rc2_ctx */*k*/, const void */*buf*/,
100                             size_t /*sz*/, unsigned /*eb*/);
101
102 /* --- @rc2_init@ --- *
103  *
104  * Arguments:   @rc2_ctx *k@ = pointer to context to initialize
105  *              @const void *buf@ = pointer to key material
106  *              @size_t sz@ = size of key material in bytes
107  *
108  * Returns:     ---
109  *
110  * Use:         Initializes an RC2 expanded key.  The effective key size is
111  *              set to be equal to the real key size, in bits.
112  */
113
114 extern void rc2_init(rc2_ctx */*k*/, const void */*buf*/, size_t /*sz*/);
115
116 /* --- @rc2_eblk@, @rc2_dblk@ --- *
117  *
118  * Arguments:   @const rc2_ctx *k@ = pointer to RC2 context
119  *              @const uint32 s[2]@ = pointer to source block
120  *              @const uint32 d[2]@ = pointer to destination block
121  *
122  * Returns:     ---
123  *
124  * Use:         Low-level block encryption and decryption.
125  */
126
127 extern void rc2_eblk(const rc2_ctx */*k*/,
128                      const uint32 */*s*/, uint32 */*dst*/);
129 extern void rc2_dblk(const rc2_ctx */*k*/,
130                      const uint32 */*s*/, uint32 */*dst*/);
131
132 /*----- That's all, folks -------------------------------------------------*/
133
134 #ifdef __cplusplus
135   }
136 #endif
137
138 #endif