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