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