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