xref: /illumos-gate/usr/src/uts/common/gssapi/mechs/krb5/include/des_int.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * lib/crypto/des/des_int.h
8  *
9  * Copyright 1987, 1988, 1990 by the Massachusetts Institute of Technology.
10  * All Rights Reserved.
11  *
12  * Export of this software from the United States of America may
13  *   require a specific license from the United States Government.
14  *   It is the responsibility of any person or organization contemplating
15  *   export to obtain such a license before exporting.
16  *
17  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
18  * distribute this software and its documentation for any purpose and
19  * without fee is hereby granted, provided that the above copyright
20  * notice appear in all copies and that both that copyright notice and
21  * this permission notice appear in supporting documentation, and that
22  * the name of M.I.T. not be used in advertising or publicity pertaining
23  * to distribution of the software without specific, written prior
24  * permission.  Furthermore if you modify this software you must label
25  * your software as modified software and not distribute it in such a
26  * fashion that it might be confused with the original M.I.T. software.
27  * M.I.T. makes no representations about the suitability of
28  * this software for any purpose.  It is provided "as is" without express
29  * or implied warranty.
30  *
31  *
32  * Private include file for the Data Encryption Standard library.
33  */
34 
35 /*
36  * Copyright (C) 1998 by the FundsXpress, INC.
37  *
38  * All rights reserved.
39  *
40  * Export of this software from the United States of America may require
41  * a specific license from the United States Government.  It is the
42  * responsibility of any person or organization contemplating export to
43  * obtain such a license before exporting.
44  *
45  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
46  * distribute this software and its documentation for any purpose and
47  * without fee is hereby granted, provided that the above copyright
48  * notice appear in all copies and that both that copyright notice and
49  * this permission notice appear in supporting documentation, and that
50  * the name of FundsXpress. not be used in advertising or publicity pertaining
51  * to distribution of the software without specific, written prior
52  * permission.  FundsXpress makes no representations about the suitability of
53  * this software for any purpose.  It is provided "as is" without express
54  * or implied warranty.
55  *
56  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
57  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
58  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
59  */
60 
61 /* only do the whole thing once	 */
62 #ifndef	DES_INTERNAL_DEFS
63 #define	DES_INTERNAL_DEFS
64 
65 #pragma ident	"%Z%%M%	%I%	%E% SMI"
66 
67 #include <k5-int.h>
68 /*
69  * Begin "mit-des.h"
70  */
71 #ifndef KRB5_MIT_DES__
72 #define KRB5_MIT_DES__
73 
74 #if !defined(PROTOTYPE)
75 #if defined(__STDC__) || defined(_MSDOS)
76 #define PROTOTYPE(x) x
77 #else
78 #define PROTOTYPE(x) ()
79 #endif
80 #endif
81 
82 typedef krb5_octet mit_des_cblock[8];		/* crypto-block size */
83 
84 #ifndef DES_INT32
85 #ifdef SIZEOF_INT
86 #if SIZEOF_INT >= 4
87 #define DES_INT32 int
88 #else
89 #define DES_INT32 long
90 #endif
91 #else /* !defined(SIZEOF_INT) */
92 #include <limits.h>
93 #if (UINT_MAX >= 0xffffffff)
94 #define DES_INT32 int
95 #else
96 #define DES_INT32 long
97 #endif
98 #endif /* !defined(SIZEOF_INT) */
99 #endif /* !defined(DES_INT32) */
100 
101 /* Triple-DES structures */
102 typedef mit_des_cblock		mit_des3_cblock[3];
103 
104 #define MIT_DES_ENCRYPT	1
105 #define MIT_DES_DECRYPT	0
106 
107 #define K5ROUNDUP(x, align)     (-(-(x) & -(align)))
108 
109 /* the first byte of the key is already in the keyblock */
110 
111 #define MIT_DES_BLOCK_LENGTH 		(8*sizeof(krb5_octet))
112 #define	MIT_DES_CBC_CRC_PAD_MINIMUM	CRC32_CKSUM_LENGTH
113 /* This used to be 8*sizeof(krb5_octet) */
114 #define MIT_DES_KEYSIZE		 	8
115 
116 #define MIT_DES_CBC_CKSUM_LENGTH	(4*sizeof(krb5_octet))
117 
118 /*
119  * Check if k5-int.h has been included before us.  If so, then check to see
120  * that our view of the DES key size is the same as k5-int.h's.
121  */
122 #ifdef	KRB5_MIT_DES_KEYSIZE
123 #if	MIT_DES_KEYSIZE != KRB5_MIT_DES_KEYSIZE
124 error(MIT_DES_KEYSIZE does not equal KRB5_MIT_DES_KEYSIZE)
125 #endif	/* MIT_DES_KEYSIZE != KRB5_MIT_DES_KEYSIZE */
126 #endif	/* KRB5_MIT_DES_KEYSIZE */
127 #endif /* KRB5_MIT_DES__ */
128 /*
129  * End "mit-des.h"
130  */
131 
132 #ifndef _KERNEL
133 /* afsstring2key.c */
134 extern krb5_error_code mit_afs_string_to_key
135 	PROTOTYPE((krb5_context context,
136 		krb5_keyblock FAR *keyblock,
137 		const krb5_data FAR *data,
138 		const krb5_data FAR *salt));
139 #endif
140 
141 /* f_cksum.c */
142 extern unsigned long mit_des_cbc_cksum
143     PROTOTYPE((
144 	krb5_context context,
145 	krb5_octet FAR *, krb5_octet FAR *, long ,
146 	krb5_keyblock *, krb5_octet FAR *));
147 
148 /* f_cbc.c */
149 extern int mit_des_cbc_encrypt
150     PROTOTYPE((krb5_context context,
151 	const mit_des_cblock FAR *in,
152 	mit_des_cblock FAR *out, long length,
153 	krb5_keyblock *key,
154 	mit_des_cblock ivec,
155 	int encrypt));
156 
157 /* fin_rndkey.c */
158 extern krb5_error_code mit_des_finish_random_key
159     PROTOTYPE(( const krb5_encrypt_block FAR *,
160 		krb5_pointer FAR *));
161 
162 /* finish_key.c */
163 extern krb5_error_code mit_des_finish_key
164     PROTOTYPE(( krb5_encrypt_block FAR *));
165 
166 /* key_parity.c */
167 extern void mit_des_fixup_key_parity PROTOTYPE((mit_des_cblock ));
168 extern int mit_des_check_key_parity PROTOTYPE((mit_des_cblock ));
169 
170 /* process_ky.c */
171 extern krb5_error_code mit_des_process_key
172     PROTOTYPE(( krb5_encrypt_block FAR *,  const krb5_keyblock FAR *));
173 
174 /* string2key.c */
175 extern krb5_error_code mit_des_string_to_key
176     PROTOTYPE((const krb5_encrypt_block FAR *,
177 		krb5_keyblock FAR *,
178 		const krb5_data FAR *,
179 		const krb5_data FAR *));
180 
181 /* weak_key.c */
182 extern int mit_des_is_weak_key PROTOTYPE((mit_des_cblock ));
183 
184 /* cmb_keys.c */
185 krb5_error_code mit_des_combine_subkeys
186     PROTOTYPE((const krb5_keyblock FAR *, const krb5_keyblock FAR *,
187 	       krb5_keyblock FAR * FAR *));
188 
189 /* f_pcbc.c */
190 int mit_des_pcbc_encrypt ();
191 
192 /* misc.c */
193 extern void swap_bits PROTOTYPE((char FAR *));
194 extern unsigned long long_swap_bits PROTOTYPE((unsigned long ));
195 extern unsigned long swap_six_bits_to_ansi PROTOTYPE((unsigned long ));
196 extern unsigned long swap_four_bits_to_ansi PROTOTYPE((unsigned long ));
197 extern unsigned long swap_bit_pos_1 PROTOTYPE((unsigned long ));
198 extern unsigned long swap_bit_pos_0 PROTOTYPE((unsigned long ));
199 extern unsigned long swap_bit_pos_0_to_ansi PROTOTYPE((unsigned long ));
200 extern unsigned long rev_swap_bit_pos_0 PROTOTYPE((unsigned long ));
201 extern unsigned long swap_byte_bits PROTOTYPE((unsigned long ));
202 extern unsigned long swap_long_bytes_bit_number PROTOTYPE((unsigned long ));
203 #ifdef FILE
204 /* XXX depends on FILE being a #define! */
205 extern void test_set PROTOTYPE((FILE *, const char *, int, const char *, int));
206 #endif
207 
208 /* d3_cbc.c */
209 extern int mit_des3_cbc_encrypt
210 	PROTOTYPE((krb5_context context,
211 		const mit_des_cblock FAR *in,
212 		mit_des_cblock FAR *out,
213 		long length,
214 		krb5_keyblock *key,
215 		mit_des_cblock ivec,
216 		int encrypt));
217 
218 /* d3_procky.c */
219 extern krb5_error_code mit_des3_process_key
220 	PROTOTYPE((krb5_encrypt_block * eblock,
221 		   const krb5_keyblock * keyblock));
222 
223 /* d3_str2ky.c */
224 extern krb5_error_code mit_des3_string_to_key
225 	PROTOTYPE((const krb5_encrypt_block FAR *,
226 		   krb5_keyblock FAR *,
227 		   const krb5_data FAR *,
228 		   const krb5_data FAR *));
229 
230 
231 /* u_nfold.c */
232 extern krb5_error_code mit_des_n_fold
233 	PROTOTYPE((const krb5_octet * input,
234 		   const size_t in_len,
235 		   krb5_octet * output,
236 		   const size_t out_len));
237 
238 extern krb5_error_code mit_des_set_random_sequence_number
239 	PROTOTYPE((const krb5_data * sequence,
240 		   krb5_pointer random_state));
241 
242 #endif	/*DES_INTERNAL_DEFS*/
243