crypto.h revision 1.2
1158115Sume/* $NetBSD: crypto.h,v 1.2 2017/01/28 21:31:49 christos Exp $ */ 2158115Sume 3158115Sume/* 4158115Sume * Copyright (c) 1997 - 2016 Kungliga Tekniska H��gskolan 5158115Sume * (Royal Institute of Technology, Stockholm, Sweden). 6158115Sume * All rights reserved. 7158115Sume * 8158115Sume * Redistribution and use in source and binary forms, with or without 9158115Sume * modification, are permitted provided that the following conditions 10158115Sume * are met: 11158115Sume * 12158115Sume * 1. Redistributions of source code must retain the above copyright 13158115Sume * notice, this list of conditions and the following disclaimer. 14158115Sume * 15158115Sume * 2. Redistributions in binary form must reproduce the above copyright 16158115Sume * notice, this list of conditions and the following disclaimer in the 17158115Sume * documentation and/or other materials provided with the distribution. 18158115Sume * 19158115Sume * 3. Neither the name of the Institute nor the names of its contributors 20158115Sume * may be used to endorse or promote products derived from this software 21158115Sume * without specific prior written permission. 22158115Sume * 23158115Sume * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 24158115Sume * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25158115Sume * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26158115Sume * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 27158115Sume * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28158115Sume * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29171795Sbushman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30171795Sbushman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31158115Sume * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32158115Sume * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33158115Sume * SUCH DAMAGE. 34158115Sume */ 35158115Sume 36158115Sume#ifndef HEIMDAL_SMALLER 37158115Sume#define DES3_OLD_ENCTYPE 1 38158115Sume#endif 39158115Sume 40158115Sumestruct _krb5_key_data { 41158115Sume krb5_keyblock *key; 42158115Sume krb5_data *schedule; 43158115Sume}; 44158115Sume 45158115Sumestruct _krb5_key_usage; 46158115Sume 47158115Sumestruct krb5_crypto_data { 48158115Sume struct _krb5_encryption_type *et; 49158115Sume struct _krb5_key_data key; 50158115Sume int num_key_usage; 51158115Sume struct _krb5_key_usage *key_usage; 52158115Sume}; 53158115Sume 54158115Sume#define CRYPTO_ETYPE(C) ((C)->et->type) 55158115Sume 56194087Sdes/* bits for `flags' below */ 57158115Sume#define F_KEYED 0x0001 /* checksum is keyed */ 58158115Sume#define F_CPROOF 0x0002 /* checksum is collision proof */ 59158115Sume#define F_DERIVED 0x0004 /* uses derived keys */ 60158115Sume#define F_VARIANT 0x0008 /* uses `variant' keys (6.4.3) */ 61158115Sume#define F_PSEUDO 0x0010 /* not a real protocol type */ 62158115Sume#define F_DISABLED 0x0020 /* enctype/checksum disabled */ 63158115Sume#define F_WEAK 0x0040 /* enctype is considered weak */ 64158115Sume 65158115Sume#define F_RFC3961_ENC 0x0100 /* RFC3961 simplified profile */ 66194112Sdes#define F_SPECIAL 0x0200 /* backwards */ 67194112Sdes#define F_ENC_THEN_CKSUM 0x0400 /* checksum is over encrypted data */ 68194112Sdes#define F_CRYPTO_MASK 0x0F00 69194112Sdes 70158115Sume#define F_RFC3961_KDF 0x1000 /* RFC3961 KDF */ 71158115Sume#define F_SP800_108_HMAC_KDF 0x2000 /* SP800-108 HMAC KDF */ 72#define F_KDF_MASK 0xF000 73 74struct salt_type { 75 krb5_salttype type; 76 const char *name; 77 krb5_error_code (*string_to_key)(krb5_context, krb5_enctype, krb5_data, 78 krb5_salt, krb5_data, krb5_keyblock*); 79}; 80 81struct _krb5_key_type { 82 krb5_enctype type; 83 const char *name; 84 size_t bits; 85 size_t size; 86 size_t schedule_size; 87 void (*random_key)(krb5_context, krb5_keyblock*); 88 void (*schedule)(krb5_context, struct _krb5_key_type *, struct _krb5_key_data *); 89 struct salt_type *string_to_key; 90 void (*random_to_key)(krb5_context, krb5_keyblock*, const void*, size_t); 91 void (*cleanup)(krb5_context, struct _krb5_key_data *); 92 const EVP_CIPHER *(*evp)(void); 93}; 94 95struct _krb5_checksum_type { 96 krb5_cksumtype type; 97 const char *name; 98 size_t blocksize; 99 size_t checksumsize; 100 unsigned flags; 101 krb5_error_code (*checksum)(krb5_context context, 102 struct _krb5_key_data *key, 103 const void *buf, size_t len, 104 unsigned usage, 105 Checksum *csum); 106 krb5_error_code (*verify)(krb5_context context, 107 struct _krb5_key_data *key, 108 const void *buf, size_t len, 109 unsigned usage, 110 Checksum *csum); 111}; 112 113struct _krb5_encryption_type { 114 krb5_enctype type; 115 const char *name; 116 const char *alias; 117 size_t blocksize; 118 size_t padsize; 119 size_t confoundersize; 120 struct _krb5_key_type *keytype; 121 struct _krb5_checksum_type *checksum; 122 struct _krb5_checksum_type *keyed_checksum; 123 unsigned flags; 124 krb5_error_code (*encrypt)(krb5_context context, 125 struct _krb5_key_data *key, 126 void *data, size_t len, 127 krb5_boolean encryptp, 128 int usage, 129 void *ivec); 130 size_t prf_length; 131 krb5_error_code (*prf)(krb5_context, 132 krb5_crypto, const krb5_data *, krb5_data *); 133}; 134 135#define ENCRYPTION_USAGE(U) (((U) << 8) | 0xAA) 136#define INTEGRITY_USAGE(U) (((U) << 8) | 0x55) 137#define CHECKSUM_USAGE(U) (((U) << 8) | 0x99) 138 139/* Checksums */ 140 141extern struct _krb5_checksum_type _krb5_checksum_none; 142extern struct _krb5_checksum_type _krb5_checksum_crc32; 143extern struct _krb5_checksum_type _krb5_checksum_rsa_md4; 144extern struct _krb5_checksum_type _krb5_checksum_rsa_md4_des; 145extern struct _krb5_checksum_type _krb5_checksum_rsa_md5_des; 146extern struct _krb5_checksum_type _krb5_checksum_rsa_md5_des3; 147extern struct _krb5_checksum_type _krb5_checksum_rsa_md5; 148extern struct _krb5_checksum_type _krb5_checksum_hmac_sha1_des3; 149extern struct _krb5_checksum_type _krb5_checksum_hmac_sha1_aes128; 150extern struct _krb5_checksum_type _krb5_checksum_hmac_sha1_aes256; 151extern struct _krb5_checksum_type _krb5_checksum_hmac_sha256_128_aes128; 152extern struct _krb5_checksum_type _krb5_checksum_hmac_sha384_192_aes256; 153extern struct _krb5_checksum_type _krb5_checksum_hmac_md5; 154extern struct _krb5_checksum_type _krb5_checksum_sha1; 155extern struct _krb5_checksum_type _krb5_checksum_sha2; 156 157extern struct _krb5_checksum_type *_krb5_checksum_types[]; 158extern int _krb5_num_checksums; 159 160/* Salts */ 161 162extern struct salt_type _krb5_AES_SHA1_salt[]; 163extern struct salt_type _krb5_AES_SHA2_salt[]; 164extern struct salt_type _krb5_arcfour_salt[]; 165extern struct salt_type _krb5_des_salt[]; 166extern struct salt_type _krb5_des3_salt[]; 167extern struct salt_type _krb5_des3_salt_derived[]; 168 169/* Encryption types */ 170 171extern struct _krb5_encryption_type _krb5_enctype_aes256_cts_hmac_sha1; 172extern struct _krb5_encryption_type _krb5_enctype_aes128_cts_hmac_sha1; 173extern struct _krb5_encryption_type _krb5_enctype_aes128_cts_hmac_sha256_128; 174extern struct _krb5_encryption_type _krb5_enctype_aes256_cts_hmac_sha384_192; 175extern struct _krb5_encryption_type _krb5_enctype_des3_cbc_sha1; 176extern struct _krb5_encryption_type _krb5_enctype_des3_cbc_md5; 177extern struct _krb5_encryption_type _krb5_enctype_des3_cbc_none; 178extern struct _krb5_encryption_type _krb5_enctype_arcfour_hmac_md5; 179extern struct _krb5_encryption_type _krb5_enctype_des_cbc_md5; 180extern struct _krb5_encryption_type _krb5_enctype_old_des3_cbc_sha1; 181extern struct _krb5_encryption_type _krb5_enctype_des_cbc_crc; 182extern struct _krb5_encryption_type _krb5_enctype_des_cbc_md4; 183extern struct _krb5_encryption_type _krb5_enctype_des_cbc_md5; 184extern struct _krb5_encryption_type _krb5_enctype_des_cbc_none; 185extern struct _krb5_encryption_type _krb5_enctype_des_cfb64_none; 186extern struct _krb5_encryption_type _krb5_enctype_des_pcbc_none; 187extern struct _krb5_encryption_type _krb5_enctype_null; 188 189extern struct _krb5_encryption_type *_krb5_etypes[]; 190extern int _krb5_num_etypes; 191 192/* NO_HCRYPTO_POLLUTION is defined in pkinit-ec.c. See commentary there. */ 193#ifndef NO_HCRYPTO_POLLUTION 194/* Interface to the EVP crypto layer provided by hcrypto */ 195struct _krb5_evp_schedule { 196 /* 197 * Normally we'd say EVP_CIPHER_CTX here, but! this header gets 198 * included in lib/krb5/pkinit-ec.ck 199 */ 200 EVP_CIPHER_CTX ectx; 201 EVP_CIPHER_CTX dctx; 202}; 203#endif 204