Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nettle / des-compat.h
blobfdeefc0c8120b842a5a008366764cc245e3848a4
1 /* des-compat.h
3 * The des block cipher, libdes/openssl-style interface.
4 */
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2001 Niels Möller
9 *
10 * The nettle library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version.
15 * The nettle library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the nettle library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 * MA 02111-1301, USA.
26 #ifndef NETTLE_DES_COMPAT_H_INCLUDED
27 #define NETTLE_DES_COMPAT_H_INCLUDED
29 /* According to Assar, des_set_key, des_set_key_odd_parity,
30 * des_is_weak_key, plus the encryption functions (des_*_encrypt and
31 * des_cbc_cksum) would be a pretty useful subset. */
33 /* NOTE: This is quite experimental, and not all functions are
34 * implemented. Contributions, in particular test cases are welcome. */
36 #include "des.h"
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
42 /* We use some name mangling, to avoid collisions with either other
43 * nettle functions or with libcrypto. */
45 #define des_ecb3_encrypt nettle_openssl_des_ecb3_encrypt
46 #define des_cbc_cksum nettle_openssl_des_cbc_cksum
47 #define des_ncbc_encrypt nettle_openssl_des_ncbc_encrypt
48 #define des_cbc_encrypt nettle_openssl_des_cbc_encrypt
49 #define des_ecb_encrypt nettle_openssl_des_ecb_encrypt
50 #define des_ede3_cbc_encrypt nettle_openssl_des_ede3_cbc_encrypt
51 #define des_set_odd_parity nettle_openssl_des_set_odd_parity
52 #define des_check_key nettle_openssl_des_check_key
53 #define des_key_sched nettle_openssl_des_key_sched
54 #define des_is_weak_key nettle_openssl_des_is_weak_key
56 /* An extra alias */
57 #undef des_set_key
58 #define des_set_key nettle_openssl_des_key_sched
60 enum { DES_DECRYPT = 0, DES_ENCRYPT = 1 };
62 /* Types */
63 typedef uint32_t DES_LONG;
65 /* Note: Typedef:ed arrays should be avoided, but they're used here
66 * for compatibility. */
67 typedef struct des_ctx des_key_schedule[1];
69 typedef uint8_t des_cblock[DES_BLOCK_SIZE];
70 /* Note: The proper definition,
72 typedef const uint8_t const_des_cblock[DES_BLOCK_SIZE];
74 would have worked, *if* all the prototypes had used arguments like
75 foo(const_des_cblock src, des_cblock dst), letting argument arrays
76 "decay" into pointers of type uint8_t * and const uint8_t *.
78 But since openssl's prototypes use *pointers* const_des_cblock *src,
79 des_cblock *dst, this ends up in type conflicts, and the workaround
80 is to not use const at all.
82 #define const_des_cblock des_cblock
84 /* Aliases */
85 #define des_ecb2_encrypt(i,o,k1,k2,e) \
86 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
88 #define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
89 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
91 /* Global flag */
92 extern int des_check_key;
94 /* Prototypes */
96 /* Typing is a little confusing. Since both des_cblock and
97 des_key_schedule are typedef:ed arrays, it automatically decay to
98 a pointers.
100 But the functions are declared taking pointers to des_cblock, i.e.
101 pointers to arrays. And on the other hand, they take plain
102 des_key_schedule arguments, which is equivalent to pointers to
103 struct des_ctx. */
104 void
105 des_ecb3_encrypt(const_des_cblock *src, des_cblock *dst,
106 des_key_schedule k1,
107 des_key_schedule k2,
108 des_key_schedule k3, int enc);
110 /* des_cbc_cksum in libdes returns a 32 bit integer, representing the
111 * latter half of the output block, using little endian byte order. */
112 uint32_t
113 des_cbc_cksum(const uint8_t *src, des_cblock *dst,
114 long length, des_key_schedule ctx,
115 const_des_cblock *iv);
117 /* NOTE: Doesn't update iv. */
118 void
119 des_cbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
120 des_key_schedule ctx, const_des_cblock *iv,
121 int enc);
123 /* Similar, but updates iv. */
124 void
125 des_ncbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
126 des_key_schedule ctx, des_cblock *iv,
127 int enc);
129 void
130 des_ecb_encrypt(const_des_cblock *src, des_cblock *dst,
131 des_key_schedule ctx, int enc);
133 void
134 des_ede3_cbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
135 des_key_schedule k1,
136 des_key_schedule k2,
137 des_key_schedule k3,
138 des_cblock *iv,
139 int enc);
142 des_set_odd_parity(des_cblock *key);
145 des_key_sched(const_des_cblock *key, des_key_schedule ctx);
148 des_is_weak_key(const_des_cblock *key);
150 #ifdef __cplusplus
152 #endif
154 #endif /* NETTLE_DES_COMPAT_H_INCLUDED */