xref: /illumos-gate/usr/src/uts/common/gssapi/mechs/krb5/include/des_int.h (revision 55fea89dcaa64928bed4327112404dcb3e07b79f)
1 /*
2  * Copyright 2008 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, 2002 by the Massachusetts Institute of
10  * Technology.  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 
66 #include "k5-int.h"
67 /*
68  * Begin "mit-des.h"
69  */
70 #ifndef KRB5_MIT_DES__
71 #define KRB5_MIT_DES__
72 
73 #if 0 /* SUNW14resync */
74 #define KRB5INT_CRYPTO_DES_INT  /* skip krb4-specific DES stuff */
75 #include "kerberosIV/des.h"     /* for des_key_schedule, etc. */
76 #undef KRB5INT_CRYPTO_DES_INT   /* don't screw other inclusions of des.h */
77 #endif
78 
79 /*
80  * SUNW14resync
81  * Solaris Kerberos does not do krb4 so we don't have its des.h file
82  * but we need a few symbols from it so we include them here.
83  */
84 /* begin: from mit kerberosIV/des.h */
85 #if UINT_MAX >= 0xFFFFFFFFUL
86 #define DES_INT32 int
87 #define DES_UINT32 unsigned int
88 #else
89 #define DES_INT32 long
90 #define DES_UINT32 unsigned long
91 #endif
92 /* end: from mit kerberosIV/des.h */
93 
94 typedef unsigned char des_cblock[8];    /* crypto-block size */
95 typedef struct des_ks_struct {  DES_INT32 _[2]; } des_key_schedule[16];
96 
97 
98 typedef des_cblock mit_des_cblock;
99 typedef des_key_schedule mit_des_key_schedule;
100 
101 /* Triple-DES structures */
102 typedef mit_des_cblock		mit_des3_cblock[3];
103 typedef mit_des_key_schedule	mit_des3_key_schedule[3];
104 
105 #define MIT_DES_ENCRYPT	1
106 #define MIT_DES_DECRYPT	0
107 
108 #define K5ROUNDUP(x, align)     (-(-(x) & -(align)))
109 
110 /* the first byte of the key is already in the keyblock */
111 
112 #define MIT_DES_BLOCK_LENGTH 		(8*sizeof(krb5_octet))
113 #define	MIT_DES_CBC_CRC_PAD_MINIMUM	CRC32_CKSUM_LENGTH
114 /* This used to be 8*sizeof(krb5_octet) */
115 #define MIT_DES_KEYSIZE		 	8
116 
117 #define MIT_DES_CBC_CKSUM_LENGTH	(4*sizeof(krb5_octet))
118 
119 /*
120  * Check if k5-int.h has been included before us.  If so, then check to see
121  * that our view of the DES key size is the same as k5-int.h's.
122  */
123 #ifdef	KRB5_MIT_DES_KEYSIZE
124 #if	MIT_DES_KEYSIZE != KRB5_MIT_DES_KEYSIZE
125 error(MIT_DES_KEYSIZE does not equal KRB5_MIT_DES_KEYSIZE)
126 #endif	/* MIT_DES_KEYSIZE != KRB5_MIT_DES_KEYSIZE */
127 #endif	/* KRB5_MIT_DES_KEYSIZE */
128 #endif /* KRB5_MIT_DES__ */
129 /*
130  * End "mit-des.h"
131  */
132 
133 #ifndef _KERNEL
134 /* afsstring2key.c */
135 extern krb5_error_code mit_afs_string_to_key
136 (krb5_context context,
137 		krb5_keyblock *keyblock,
138 		const krb5_data  *data,
139 		const krb5_data  *salt);
140 #endif
141 
142 /* f_cksum.c */
143 extern unsigned long mit_des_cbc_cksum
144 ( krb5_context context,
145 	const krb5_octet  *, krb5_octet  *, unsigned long ,
146 	krb5_keyblock *, const krb5_octet  *);
147 
148 /* f_cbc.c */
149 extern int mit_des_cbc_encrypt
150 (krb5_context context,
151 	const mit_des_cblock  *in,
152 	mit_des_cblock  *out, long length,
153 	krb5_keyblock *key,
154 	mit_des_cblock ivec,
155 	int encrypt);
156 
157 #define mit_des_zeroblock krb5int_c_mit_des_zeroblock
158 extern const mit_des_cblock mit_des_zeroblock;
159 
160 /* fin_rndkey.c */
161 extern krb5_error_code mit_des_finish_random_key
162     ( const krb5_encrypt_block *,
163 		krb5_pointer *);
164 
165 /* finish_key.c */
166 extern krb5_error_code mit_des_finish_key
167     ( krb5_encrypt_block *);
168 
169 /* key_parity.c */
170 extern void mit_des_fixup_key_parity (mit_des_cblock );
171 extern int mit_des_check_key_parity (mit_des_cblock );
172 
173 /* process_ky.c */
174 extern krb5_error_code mit_des_process_key
175     ( krb5_encrypt_block *,  const krb5_keyblock *);
176 
177 /* string2key.c */
178 extern krb5_error_code mit_des_string_to_key
179     ( const krb5_encrypt_block *,
180 	       krb5_keyblock *, const krb5_data *, const krb5_data *);
181 
182 /* weak_key.c */
183 extern int mit_des_is_weak_key (mit_des_cblock );
184 
185 /* cmb_keys.c */
186 krb5_error_code mit_des_combine_subkeys
187     (const krb5_keyblock *, const krb5_keyblock *,
188 	       krb5_keyblock **);
189 
190 /* f_pcbc.c */
191 int mit_des_pcbc_encrypt ();
192 
193 /* f_sched.c */
194 int mit_des_make_key_sched(mit_des_cblock, mit_des_key_schedule);
195 
196 
197 /* misc.c */
198 extern void swap_bits (char *);
199 extern unsigned long long_swap_bits (unsigned long );
200 extern unsigned long swap_six_bits_to_ansi (unsigned long );
201 extern unsigned long swap_four_bits_to_ansi (unsigned long );
202 extern unsigned long swap_bit_pos_1 (unsigned long );
203 extern unsigned long swap_bit_pos_0 (unsigned long );
204 extern unsigned long swap_bit_pos_0_to_ansi (unsigned long );
205 extern unsigned long rev_swap_bit_pos_0 (unsigned long );
206 extern unsigned long swap_byte_bits (unsigned long );
207 extern unsigned long swap_long_bytes_bit_number (unsigned long );
208 #ifdef FILE
209 /* XXX depends on FILE being a #define! */
210 extern void test_set (FILE *, const char *, int, const char *, int);
211 #endif
212 
213 /* d3_cbc.c */
214 extern int mit_des3_cbc_encrypt
215 	(krb5_context context,
216 	 const mit_des_cblock  *in,
217 	 mit_des_cblock  *out,
218 	 unsigned long length,
219 	 krb5_keyblock *key,
220 	 const mit_des_cblock ivec,
221 	 int enc);
222 
223 /* d3_procky.c */
224 extern krb5_error_code mit_des3_process_key
225 	(krb5_encrypt_block * eblock,
226 		   const krb5_keyblock * keyblock);
227 
228 /* d3_str2ky.c */
229 extern krb5_error_code mit_des3_string_to_key
230 	(const krb5_encrypt_block * eblock,
231 		   krb5_keyblock * keyblock,
232 		   const krb5_data * data,
233 		   const krb5_data * salt);
234 
235 /* u_nfold.c */
236 extern krb5_error_code mit_des_n_fold
237 	(const krb5_octet * input,
238 		   const size_t in_len,
239 		   krb5_octet * output,
240 		   const size_t out_len);
241 
242 extern krb5_error_code mit_des_set_random_sequence_number
243 	(const krb5_data * sequence,
244 		   krb5_pointer random_state);
245 
246 #endif	/*DES_INTERNAL_DEFS*/
247