des_cblock_print(x)1 /*
2 * des.h
3 *
4 * Copyright (C) 1987, 1988, 1989 by the Massachusetts Institute of Technology.
5 *
6 * Export of this software from the United States of America is assumed
7 * to require a specific license from the United States Government.
8 * It is the responsibility of any person or organization contemplating
9 * export to obtain such a license before exporting.
10 *
11 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12 * distribute this software and its documentation for any purpose and
13 * without fee is hereby granted, provided that the above copyright
14 * notice appear in all copies and that both that copyright notice and
15 * this permission notice appear in supporting documentation, and that
16 * the name of M.I.T. not be used in advertising or publicity pertaining
17 * to distribution of the software without specific, written prior
18 * permission. M.I.T. makes no representations about the suitability of
19 * this software for any purpose. It is provided "as is" without express
20 * or implied warranty.
21 *
22 * Include file for the Data Encryption Standard library.
23 */
24
25 /* only do the whole thing once */
26 #ifndef DES_H
27 #define DES_H
28
29 #include <stdio.h>
30
31 #if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
32 #include <KerberosSupport/KerberosSupport.h>
33 #endif
34
35 #if TARGET_API_MAC_OSX
36 #include <machine/types.h>
37
38 #ifndef DES_INT32
39 #define DES_INT32 int32_t
40 #endif
41 #ifndef DES_UINT32
42 #define DES_UINT32 u_int32_t
43 #endif
44 #elif TARGET_API_MAC_OS8 || TARGET_API_MAC_CARBON
45 #include <MacTypes.h>
46
47 #ifndef DES_INT32
48 #define DES_INT32 SInt32
49 #endif
50 #ifndef DES_UINT32
51 #define DES_UINT32 UInt32
52 #endif
53 #endif
54
55 #if !defined(DES_INT32) || !defined(DES_UINT32)
56 #error "Unsupported platform. Need definitions for UInt32 and SInt32."
57 #endif
58
59 /* There are some declarations in the system-specific header files which
60 can't be done until DES_INT32 is defined. So they are in a macro,
61 which we expand here if defined. */
62
63 #ifdef DECL_THAT_NEEDS_DES_INT32
64 DECL_THAT_NEEDS_DES_INT32
65 #endif
66
67 typedef unsigned char des_cblock[8]; /* crypto-block size */
68 /* Key schedule */
69 typedef struct des_ks_struct { union { DES_INT32 pad; des_cblock _;} __; } des_key_schedule[16];
70
71 #define DES_KEY_SZ (sizeof(des_cblock))
72 #define DES_ENCRYPT 1
73 #define DES_DECRYPT 0
74
75 #ifndef NCOMPAT
76 #define C_Block des_cblock
77 #define Key_schedule des_key_schedule
78 #define ENCRYPT DES_ENCRYPT
79 #define DECRYPT DES_DECRYPT
80 #define KEY_SZ DES_KEY_SZ
81 #define mit_string_to_key des_string_to_key
82 #define string_to_key des_string_to_key
83 #define read_pw_string des_read_pw_string
84 #define random_key des_random_key
85 #define pcbc_encrypt des_pcbc_encrypt
86 #define key_sched des_key_sched
87 #define cbc_encrypt des_cbc_encrypt
88 #define cbc_cksum des_cbc_cksum
89 #define C_Block_print des_cblock_print
90 #define quad_cksum des_quad_cksum
91 typedef struct des_ks_struct bit_64;
92 #endif
93
94 #define des_cblock_print(x) des_cblock_print_file(x, stdout)
95
96 /* Function declarations */
97
98 #ifdef __cplusplus
99 extern "C" {
100 #endif /* __cplusplus */
101
102 /* Macintosh CFM-68K magic incantation */
103 #if PRAGMA_IMPORT
104 #pragma import on
105 #endif
106
107 #if PRAGMA_STRUCT_ALIGN
108 #pragma options align=mac68k
109 #elif PRAGMA_STRUCT_PACKPUSH
110 #pragma pack(push, 2)
111 #elif PRAGMA_STRUCT_PACK
112 #pragma pack(2)
113 #endif
114
115 #if TARGET_RT_MAC_CFM
116 # define DESLibraryIsPresent() ((Ptr) (des_cbc_encrypt) != (Ptr) (kUnresolvedCFragSymbolAddress))
117 #elif TARGET_CPU_68K
118 # pragma d0_pointers on
119 #endif
120
121 int des_cbc_encrypt(des_cblock *in,
122 des_cblock *out,
123 long length,
124 des_key_schedule schedule,
125 des_cblock ivec,
126 int encrypt);
127
128 void des_3cbc_encrypt(des_cblock *in,
129 des_cblock *out,
130 long length,
131 des_key_schedule ks1,
132 des_key_schedule ks2,
133 des_key_schedule ks3,
134 des_cblock ivec,
135 int encrypt);
136
137 unsigned long des_cbc_cksum(des_cblock *in,
138 des_cblock *out,
139 long length,
140 des_key_schedule schedule,
141 des_cblock *ivec);
142
143 int des_ecb_encrypt(des_cblock *in,
144 des_cblock *out,
145 des_key_schedule schedule,
146 int encrypt);
147
148 void des_3ecb_encrypt(des_cblock *in,
149 des_cblock *out,
150 des_key_schedule ks1,
151 des_key_schedule ks2,
152 des_key_schedule ks3,
153 int encrypt);
154
155 void des_fixup_key_parity(register des_cblock key);
156 int des_check_key_parity(register des_cblock key);
157
158 int des_pcbc_encrypt(des_cblock *in,
159 des_cblock *out,
160 long length,
161 des_key_schedule schedule,
162 des_cblock ivec,
163 int encrypt);
164
165 int make_key_sched(des_cblock *key, des_key_schedule schedule);
166
167 int des_key_sched(des_cblock k, des_key_schedule schedule);
168
169 int des_new_random_key(des_cblock key);
170 void des_init_random_number_generator(des_cblock key);
171 void des_set_random_generator_seed(des_cblock key);
172 void des_set_sequence_number(des_cblock new_sequence_number);
173 void des_generate_random_block(des_cblock block);
174
175 unsigned long des_quad_cksum(unsigned char *in,
176 unsigned long *out,
177 long length,
178 int out_count,
179 des_cblock *c_seed);
180
181 int des_random_key(des_cblock *key);
182
183 int des_read_password(des_cblock *k, char *prompt, int verify);
184 int des_read_pw_string(char *s, int max, char *prompt, int verify);
185
186 int des_string_to_key(char *str, des_cblock key);
187 void afs_string_to_key(char *str, char *cell, des_cblock key);
188
189 void des_cblock_print_file(des_cblock *x, FILE *fp);
190
191 int des_is_weak_key(des_cblock key);
192
193 char *des_crypt(const char *buf, const char *salt);
194 char *des_fcrypt(const char *buf, const char *salt, char *ret);
195
196 int des_set_key(des_cblock *key, des_key_schedule schedule);
197
198 #if !TARGET_RT_MAC_CFM
199 # pragma d0_pointers reset
200 #endif
201
202 /* Macintosh CFM-68K magic incantation */
203 #if PRAGMA_STRUCT_ALIGN
204 #pragma options align=reset
205 #elif PRAGMA_STRUCT_PACKPUSH
206 #pragma pack(pop)
207 #elif PRAGMA_STRUCT_PACK
208 #pragma pack()
209 #endif
210
211 #ifdef PRAGMA_IMPORT_OFF
212 #pragma import off
213 #elif PRAGMA_IMPORT
214 #pragma import reset
215 #endif
216
217 #ifdef __cplusplus
218 }
219 #endif /* __cplusplus */
220
221 #endif /* DES_H */
222