1 #pragma ident "%Z%%M% %I% %E% SMI" 2 /* 3 * Copyright 1993 by OpenVision Technologies, Inc. 4 * 5 * Permission to use, copy, modify, distribute, and sell this software 6 * and its documentation for any purpose is hereby granted without fee, 7 * provided that the above copyright notice appears in all copies and 8 * that both that copyright notice and this permission notice appear in 9 * supporting documentation, and that the name of OpenVision not be used 10 * in advertising or publicity pertaining to distribution of the software 11 * without specific, written prior permission. OpenVision makes no 12 * representations about the suitability of this software for any 13 * purpose. It is provided "as is" without express or implied warranty. 14 * 15 * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 17 * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR 18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 19 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 20 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 21 * PERFORMANCE OF THIS SOFTWARE. 22 */ 23 24 /* 25 * $Id: util_cksum.c,v 1.14.6.1 2000/04/22 03:01:36 raeburn Exp $ 26 */ 27 28 #include <gssapiP_krb5.h> 29 #include <memory.h> 30 31 /* Checksumming the channel bindings always uses plain MD5. */ 32 /*ARGSUSED*/ 33 krb5_error_code 34 kg_checksum_channel_bindings(context, cb, cksum, bigend) 35 krb5_context context; 36 gss_channel_bindings_t cb; 37 krb5_checksum *cksum; 38 int bigend; 39 { 40 int len; 41 char *buf, *ptr; 42 size_t sumlen; 43 krb5_data plaind; 44 krb5_error_code code; 45 46 /* initialize the the cksum and allocate the contents buffer */ 47 if (code = krb5_c_checksum_length(context, CKSUMTYPE_RSA_MD5, &sumlen)) 48 return(code); 49 50 cksum->checksum_type = CKSUMTYPE_RSA_MD5; 51 cksum->length = sumlen; 52 53 /* generate a buffer full of zeros if no cb specified */ 54 55 if (cb == GSS_C_NO_CHANNEL_BINDINGS) { 56 if ((cksum->contents = (krb5_octet *) xmalloc(cksum->length)) == NULL) { 57 return(ENOMEM); 58 } 59 memset(cksum->contents, '\0', cksum->length); 60 return(0); 61 } 62 63 /* create the buffer to checksum into */ 64 65 len = (sizeof(krb5_int32)*5+ 66 cb->initiator_address.length+ 67 cb->acceptor_address.length+ 68 cb->application_data.length); 69 70 if ((buf = (char *) xmalloc(len)) == NULL) 71 return(ENOMEM); 72 73 /* helper macros. This code currently depends on a long being 32 74 bits, and htonl dtrt. */ 75 76 ptr = buf; 77 78 TWRITE_INT(ptr, cb->initiator_addrtype, bigend); 79 TWRITE_BUF(ptr, cb->initiator_address, bigend); 80 TWRITE_INT(ptr, cb->acceptor_addrtype, bigend); 81 TWRITE_BUF(ptr, cb->acceptor_address, bigend); 82 TWRITE_BUF(ptr, cb->application_data, bigend); 83 84 /* checksum the data */ 85 86 plaind.length = len; 87 plaind.data = buf; 88 89 if (code = krb5_c_make_checksum(context, CKSUMTYPE_RSA_MD5, 0, 0, 90 &plaind, cksum)) { 91 xfree(cksum->contents); 92 xfree(buf); 93 return(code); 94 } 95 96 /* success */ 97 98 xfree(buf); 99 return(0); 100 } 101