1169689Skan/* crypto/des/cbc_cksm.c */ 2169689Skan/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3169689Skan * All rights reserved. 4169689Skan * 5169689Skan * This package is an SSL implementation written 6169689Skan * by Eric Young (eay@cryptsoft.com). 7169689Skan * The implementation was written so as to conform with Netscapes SSL. 8169689Skan * 9169689Skan * This library is free for commercial and non-commercial use as long as 10169689Skan * the following conditions are aheared to. The following conditions 11169689Skan * apply to all code found in this distribution, be it the RC4, RSA, 12169689Skan * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13169689Skan * included with this distribution is covered by the same copyright terms 14169689Skan * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15169689Skan * 16169689Skan * Copyright remains Eric Young's, and as such any Copyright notices in 17169689Skan * the code are not to be removed. 18169689Skan * If this package is used in a product, Eric Young should be given attribution 19169689Skan * as the author of the parts of the library used. 20169689Skan * This can be in the form of a textual message at program startup or 21169689Skan * in documentation (online or textual) provided with the package. 22169689Skan * 23169689Skan * Redistribution and use in source and binary forms, with or without 24169689Skan * modification, are permitted provided that the following conditions 25169689Skan * are met: 26169689Skan * 1. Redistributions of source code must retain the copyright 27169689Skan * notice, this list of conditions and the following disclaimer. 28169689Skan * 2. Redistributions in binary form must reproduce the above copyright 29169689Skan * notice, this list of conditions and the following disclaimer in the 30169689Skan * documentation and/or other materials provided with the distribution. 31169689Skan * 3. All advertising materials mentioning features or use of this software 32169689Skan * must display the following acknowledgement: 33169689Skan * "This product includes cryptographic software written by 34169689Skan * Eric Young (eay@cryptsoft.com)" 35169689Skan * The word 'cryptographic' can be left out if the rouines from the library 36169689Skan * being used are not cryptographic related :-). 37169689Skan * 4. If you include any Windows specific code (or a derivative thereof) from 38169689Skan * the apps directory (application code) you must include an acknowledgement: 39169689Skan * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40169689Skan * 41169689Skan * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42169689Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43169689Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44169689Skan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45169689Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46169689Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47169689Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48169689Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49169689Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50169689Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51169689Skan * SUCH DAMAGE. 52169689Skan * 53169689Skan * The licence and distribution terms for any publically available version or 54169689Skan * derivative of this code cannot be changed. i.e. this code cannot simply be 55169689Skan * copied and put under another distribution licence 56169689Skan * [including the GNU Public Licence.] 57169689Skan */ 58169689Skan 59169689Skan#include "des_locl.h" 60169689Skan 61169689SkanDES_LONG DES_cbc_cksum(const unsigned char *in, DES_cblock *output, 62169689Skan long length, DES_key_schedule *schedule, 63169689Skan const_DES_cblock *ivec) 64169689Skan{ 65169689Skan register DES_LONG tout0, tout1, tin0, tin1; 66169689Skan register long l = length; 67169689Skan DES_LONG tin[2]; 68169689Skan unsigned char *out = &(*output)[0]; 69169689Skan const unsigned char *iv = &(*ivec)[0]; 70169689Skan 71169689Skan c2l(iv, tout0); 72169689Skan c2l(iv, tout1); 73169689Skan for (; l > 0; l -= 8) { 74169689Skan if (l >= 8) { 75169689Skan c2l(in, tin0); 76169689Skan c2l(in, tin1); 77169710Skan } else 78169689Skan c2ln(in, tin0, tin1, l); 79169689Skan 80169689Skan tin0 ^= tout0; 81169689Skan tin[0] = tin0; 82169710Skan tin1 ^= tout1; 83169689Skan tin[1] = tin1; 84169689Skan DES_encrypt1((DES_LONG *)tin, schedule, DES_ENCRYPT); 85169689Skan /* fix 15/10/91 eay - thanks to keithr@sco.COM */ 86169689Skan tout0 = tin[0]; 87169689Skan tout1 = tin[1]; 88169689Skan } 89169689Skan if (out != NULL) { 90169689Skan l2c(tout0, out); 91169689Skan l2c(tout1, out); 92169689Skan } 93169689Skan tout0 = tin0 = tin1 = tin[0] = tin[1] = 0; 94169689Skan /* 95169689Skan * Transform the data in tout1 so that it will match the return value 96169689Skan * that the MIT Kerberos mit_des_cbc_cksum API returns. 97169689Skan */ 98169689Skan tout1 = ((tout1 >> 24L) & 0x000000FF) 99169689Skan | ((tout1 >> 8L) & 0x0000FF00) 100169689Skan | ((tout1 << 8L) & 0x00FF0000) 101169689Skan | ((tout1 << 24L) & 0xFF000000); 102169689Skan return (tout1); 103169689Skan} 104169689Skan