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