1*ae771770SStanislav Sedov /* 2*ae771770SStanislav Sedov * Copyright (c) 1997 - 2008 Kungliga Tekniska Högskolan 3*ae771770SStanislav Sedov * (Royal Institute of Technology, Stockholm, Sweden). 4*ae771770SStanislav Sedov * All rights reserved. 5*ae771770SStanislav Sedov * 6*ae771770SStanislav Sedov * Redistribution and use in source and binary forms, with or without 7*ae771770SStanislav Sedov * modification, are permitted provided that the following conditions 8*ae771770SStanislav Sedov * are met: 9*ae771770SStanislav Sedov * 10*ae771770SStanislav Sedov * 1. Redistributions of source code must retain the above copyright 11*ae771770SStanislav Sedov * notice, this list of conditions and the following disclaimer. 12*ae771770SStanislav Sedov * 13*ae771770SStanislav Sedov * 2. Redistributions in binary form must reproduce the above copyright 14*ae771770SStanislav Sedov * notice, this list of conditions and the following disclaimer in the 15*ae771770SStanislav Sedov * documentation and/or other materials provided with the distribution. 16*ae771770SStanislav Sedov * 17*ae771770SStanislav Sedov * 3. Neither the name of the Institute nor the names of its contributors 18*ae771770SStanislav Sedov * may be used to endorse or promote products derived from this software 19*ae771770SStanislav Sedov * without specific prior written permission. 20*ae771770SStanislav Sedov * 21*ae771770SStanislav Sedov * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22*ae771770SStanislav Sedov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23*ae771770SStanislav Sedov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24*ae771770SStanislav Sedov * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25*ae771770SStanislav Sedov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26*ae771770SStanislav Sedov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27*ae771770SStanislav Sedov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28*ae771770SStanislav Sedov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29*ae771770SStanislav Sedov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30*ae771770SStanislav Sedov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31*ae771770SStanislav Sedov * SUCH DAMAGE. 32*ae771770SStanislav Sedov */ 33*ae771770SStanislav Sedov 34*ae771770SStanislav Sedov #ifndef HEIMDAL_SMALLER 35*ae771770SStanislav Sedov #define DES3_OLD_ENCTYPE 1 36*ae771770SStanislav Sedov #endif 37*ae771770SStanislav Sedov 38*ae771770SStanislav Sedov struct _krb5_key_data { 39*ae771770SStanislav Sedov krb5_keyblock *key; 40*ae771770SStanislav Sedov krb5_data *schedule; 41*ae771770SStanislav Sedov }; 42*ae771770SStanislav Sedov 43*ae771770SStanislav Sedov struct _krb5_key_usage; 44*ae771770SStanislav Sedov 45*ae771770SStanislav Sedov struct krb5_crypto_data { 46*ae771770SStanislav Sedov struct _krb5_encryption_type *et; 47*ae771770SStanislav Sedov struct _krb5_key_data key; 48*ae771770SStanislav Sedov int num_key_usage; 49*ae771770SStanislav Sedov struct _krb5_key_usage *key_usage; 50*ae771770SStanislav Sedov }; 51*ae771770SStanislav Sedov 52*ae771770SStanislav Sedov #define CRYPTO_ETYPE(C) ((C)->et->type) 53*ae771770SStanislav Sedov 54*ae771770SStanislav Sedov /* bits for `flags' below */ 55*ae771770SStanislav Sedov #define F_KEYED 1 /* checksum is keyed */ 56*ae771770SStanislav Sedov #define F_CPROOF 2 /* checksum is collision proof */ 57*ae771770SStanislav Sedov #define F_DERIVED 4 /* uses derived keys */ 58*ae771770SStanislav Sedov #define F_VARIANT 8 /* uses `variant' keys (6.4.3) */ 59*ae771770SStanislav Sedov #define F_PSEUDO 16 /* not a real protocol type */ 60*ae771770SStanislav Sedov #define F_SPECIAL 32 /* backwards */ 61*ae771770SStanislav Sedov #define F_DISABLED 64 /* enctype/checksum disabled */ 62*ae771770SStanislav Sedov #define F_WEAK 128 /* enctype is considered weak */ 63*ae771770SStanislav Sedov 64*ae771770SStanislav Sedov struct salt_type { 65*ae771770SStanislav Sedov krb5_salttype type; 66*ae771770SStanislav Sedov const char *name; 67*ae771770SStanislav Sedov krb5_error_code (*string_to_key)(krb5_context, krb5_enctype, krb5_data, 68*ae771770SStanislav Sedov krb5_salt, krb5_data, krb5_keyblock*); 69*ae771770SStanislav Sedov }; 70*ae771770SStanislav Sedov 71*ae771770SStanislav Sedov struct _krb5_key_type { 72*ae771770SStanislav Sedov krb5_enctype type; 73*ae771770SStanislav Sedov const char *name; 74*ae771770SStanislav Sedov size_t bits; 75*ae771770SStanislav Sedov size_t size; 76*ae771770SStanislav Sedov size_t schedule_size; 77*ae771770SStanislav Sedov void (*random_key)(krb5_context, krb5_keyblock*); 78*ae771770SStanislav Sedov void (*schedule)(krb5_context, struct _krb5_key_type *, struct _krb5_key_data *); 79*ae771770SStanislav Sedov struct salt_type *string_to_key; 80*ae771770SStanislav Sedov void (*random_to_key)(krb5_context, krb5_keyblock*, const void*, size_t); 81*ae771770SStanislav Sedov void (*cleanup)(krb5_context, struct _krb5_key_data *); 82*ae771770SStanislav Sedov const EVP_CIPHER *(*evp)(void); 83*ae771770SStanislav Sedov }; 84*ae771770SStanislav Sedov 85*ae771770SStanislav Sedov struct _krb5_checksum_type { 86*ae771770SStanislav Sedov krb5_cksumtype type; 87*ae771770SStanislav Sedov const char *name; 88*ae771770SStanislav Sedov size_t blocksize; 89*ae771770SStanislav Sedov size_t checksumsize; 90*ae771770SStanislav Sedov unsigned flags; 91*ae771770SStanislav Sedov krb5_error_code (*checksum)(krb5_context context, 92*ae771770SStanislav Sedov struct _krb5_key_data *key, 93*ae771770SStanislav Sedov const void *buf, size_t len, 94*ae771770SStanislav Sedov unsigned usage, 95*ae771770SStanislav Sedov Checksum *csum); 96*ae771770SStanislav Sedov krb5_error_code (*verify)(krb5_context context, 97*ae771770SStanislav Sedov struct _krb5_key_data *key, 98*ae771770SStanislav Sedov const void *buf, size_t len, 99*ae771770SStanislav Sedov unsigned usage, 100*ae771770SStanislav Sedov Checksum *csum); 101*ae771770SStanislav Sedov }; 102*ae771770SStanislav Sedov 103*ae771770SStanislav Sedov struct _krb5_encryption_type { 104*ae771770SStanislav Sedov krb5_enctype type; 105*ae771770SStanislav Sedov const char *name; 106*ae771770SStanislav Sedov size_t blocksize; 107*ae771770SStanislav Sedov size_t padsize; 108*ae771770SStanislav Sedov size_t confoundersize; 109*ae771770SStanislav Sedov struct _krb5_key_type *keytype; 110*ae771770SStanislav Sedov struct _krb5_checksum_type *checksum; 111*ae771770SStanislav Sedov struct _krb5_checksum_type *keyed_checksum; 112*ae771770SStanislav Sedov unsigned flags; 113*ae771770SStanislav Sedov krb5_error_code (*encrypt)(krb5_context context, 114*ae771770SStanislav Sedov struct _krb5_key_data *key, 115*ae771770SStanislav Sedov void *data, size_t len, 116*ae771770SStanislav Sedov krb5_boolean encryptp, 117*ae771770SStanislav Sedov int usage, 118*ae771770SStanislav Sedov void *ivec); 119*ae771770SStanislav Sedov size_t prf_length; 120*ae771770SStanislav Sedov krb5_error_code (*prf)(krb5_context, 121*ae771770SStanislav Sedov krb5_crypto, const krb5_data *, krb5_data *); 122*ae771770SStanislav Sedov }; 123*ae771770SStanislav Sedov 124*ae771770SStanislav Sedov #define ENCRYPTION_USAGE(U) (((U) << 8) | 0xAA) 125*ae771770SStanislav Sedov #define INTEGRITY_USAGE(U) (((U) << 8) | 0x55) 126*ae771770SStanislav Sedov #define CHECKSUM_USAGE(U) (((U) << 8) | 0x99) 127*ae771770SStanislav Sedov 128*ae771770SStanislav Sedov /* Checksums */ 129*ae771770SStanislav Sedov 130*ae771770SStanislav Sedov extern struct _krb5_checksum_type _krb5_checksum_none; 131*ae771770SStanislav Sedov extern struct _krb5_checksum_type _krb5_checksum_crc32; 132*ae771770SStanislav Sedov extern struct _krb5_checksum_type _krb5_checksum_rsa_md4; 133*ae771770SStanislav Sedov extern struct _krb5_checksum_type _krb5_checksum_rsa_md4_des; 134*ae771770SStanislav Sedov extern struct _krb5_checksum_type _krb5_checksum_rsa_md5_des; 135*ae771770SStanislav Sedov extern struct _krb5_checksum_type _krb5_checksum_rsa_md5_des3; 136*ae771770SStanislav Sedov extern struct _krb5_checksum_type _krb5_checksum_rsa_md5; 137*ae771770SStanislav Sedov extern struct _krb5_checksum_type _krb5_checksum_hmac_sha1_des3; 138*ae771770SStanislav Sedov extern struct _krb5_checksum_type _krb5_checksum_hmac_sha1_aes128; 139*ae771770SStanislav Sedov extern struct _krb5_checksum_type _krb5_checksum_hmac_sha1_aes256; 140*ae771770SStanislav Sedov extern struct _krb5_checksum_type _krb5_checksum_hmac_md5; 141*ae771770SStanislav Sedov extern struct _krb5_checksum_type _krb5_checksum_sha1; 142*ae771770SStanislav Sedov 143*ae771770SStanislav Sedov extern struct _krb5_checksum_type *_krb5_checksum_types[]; 144*ae771770SStanislav Sedov extern int _krb5_num_checksums; 145*ae771770SStanislav Sedov 146*ae771770SStanislav Sedov /* Salts */ 147*ae771770SStanislav Sedov 148*ae771770SStanislav Sedov extern struct salt_type _krb5_AES_salt[]; 149*ae771770SStanislav Sedov extern struct salt_type _krb5_arcfour_salt[]; 150*ae771770SStanislav Sedov extern struct salt_type _krb5_des_salt[]; 151*ae771770SStanislav Sedov extern struct salt_type _krb5_des3_salt[]; 152*ae771770SStanislav Sedov extern struct salt_type _krb5_des3_salt_derived[]; 153*ae771770SStanislav Sedov 154*ae771770SStanislav Sedov /* Encryption types */ 155*ae771770SStanislav Sedov 156*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_aes256_cts_hmac_sha1; 157*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_aes128_cts_hmac_sha1; 158*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_des3_cbc_sha1; 159*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_des3_cbc_md5; 160*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_des3_cbc_none; 161*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_arcfour_hmac_md5; 162*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_des_cbc_md5; 163*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_old_des3_cbc_sha1; 164*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_des_cbc_crc; 165*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_des_cbc_md4; 166*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_des_cbc_md5; 167*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_des_cbc_none; 168*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_des_cfb64_none; 169*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_des_pcbc_none; 170*ae771770SStanislav Sedov extern struct _krb5_encryption_type _krb5_enctype_null; 171*ae771770SStanislav Sedov 172*ae771770SStanislav Sedov extern struct _krb5_encryption_type *_krb5_etypes[]; 173*ae771770SStanislav Sedov extern int _krb5_num_etypes; 174*ae771770SStanislav Sedov 175*ae771770SStanislav Sedov /* Interface to the EVP crypto layer provided by hcrypto */ 176*ae771770SStanislav Sedov struct _krb5_evp_schedule { 177*ae771770SStanislav Sedov EVP_CIPHER_CTX ectx; 178*ae771770SStanislav Sedov EVP_CIPHER_CTX dctx; 179*ae771770SStanislav Sedov }; 180