b348397a |
1 | /* -*-c-*- |
2 | * |
b817bfc6 |
3 | * $Id: desx.h,v 1.2 2004/04/08 01:36:15 mdw Exp $ |
b348397a |
4 | * |
5 | * The DESX algorithm |
6 | * |
7 | * (c) 2001 Straylight/Edgeware |
8 | */ |
9 | |
45c0fd36 |
10 | /*----- Licensing notice --------------------------------------------------* |
b348397a |
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 | * |
b348397a |
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 | * |
b348397a |
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 | |
b348397a |
30 | /*----- Notes on DESX -----------------------------------------------------* |
31 | * |
32 | * DESX was designed by Ron Rivest in 1986 as a simple and cheap way to |
33 | * strengthen DES against exhaustive search. It also increases the |
34 | * difficulty of differential and linear attacks. |
35 | */ |
36 | |
37 | #ifndef CATACOMB_DESX_H |
38 | #define CATACOMB_DESX_H |
39 | |
40 | #ifdef __cplusplus |
41 | extern "C" { |
42 | #endif |
43 | |
44 | /*----- Header files ------------------------------------------------------*/ |
45 | |
46 | #include <stddef.h> |
47 | |
48 | #include <mLib/bits.h> |
49 | |
50 | #ifndef CATACOMB_DES_H |
51 | # include "des.h" |
52 | #endif |
53 | |
54 | /*----- Magical numbers ---------------------------------------------------*/ |
55 | |
56 | #define DESX_BLKSZ 8 |
57 | #define DESX_KEYSZ 23 |
58 | #define DESX_CLASS (N, B, 64) |
59 | |
60 | extern const octet desx_keysz[]; |
61 | |
62 | /*----- Data structures ---------------------------------------------------*/ |
63 | |
64 | typedef struct desx_ctx { |
65 | des_ctx k; |
66 | uint32 prea, preb; |
67 | uint32 posta, postb; |
68 | } desx_ctx; |
69 | |
70 | /*----- Functions provided ------------------------------------------------*/ |
71 | |
72 | /* --- @desx_init@ --- * |
73 | * |
74 | * Arguments: @desx_ctx *k@ = pointer to key block |
75 | * @const void *buf@ = pointer to key buffer |
76 | * @size_t sz@ = size of key material |
77 | * |
78 | * Returns: --- |
79 | * |
80 | * Use: Initializes a DESX key buffer. The key buffer contains, in |
81 | * order, an optional 8-byte pre-whitening key, a single-DES key |
82 | * (either 7 or 8 bytes), and an optional 8-byte port-whitening |
83 | * key. If no whitening keys are specified, the algorithm |
84 | * becomes the same as single-DES. |
85 | */ |
86 | |
87 | extern void desx_init(desx_ctx */*k*/, const void */*buf*/, size_t /*sz*/); |
88 | |
89 | /* --- @desx_eblk@, @desx_dblk@ --- * |
90 | * |
91 | * Arguments: @const desx_ctx *k@ = pointer to key block |
92 | * @const uint32 s[2]@ = pointer to source block |
93 | * @uint32 d[2]@ = pointer to destination block |
94 | * |
95 | * Returns: --- |
96 | * |
97 | * Use: Low-level block encryption and decryption. |
98 | */ |
99 | |
100 | extern void desx_eblk(const desx_ctx */*k*/, |
101 | const uint32 */*s*/, uint32 */*d*/); |
102 | extern void desx_dblk(const desx_ctx */*k*/, |
103 | const uint32 */*s*/, uint32 */*d*/); |
104 | |
105 | /*----- That's all, folks -------------------------------------------------*/ |
106 | |
107 | #ifdef __cplusplus |
108 | } |
109 | #endif |
110 | |
111 | #endif |