os/ossrv/ssl/libcrypto/src/crypto/des/ncbc_enc.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ssl/libcrypto/src/crypto/des/ncbc_enc.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,148 @@
     1.4 +/* crypto/des/ncbc_enc.c */
     1.5 +/*
     1.6 + * #included by:
     1.7 + *    cbc_enc.c  (DES_cbc_encrypt)
     1.8 + *    des_enc.c  (DES_ncbc_encrypt)
     1.9 + */
    1.10 +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
    1.11 + * All rights reserved.
    1.12 + *
    1.13 + * This package is an SSL implementation written
    1.14 + * by Eric Young (eay@cryptsoft.com).
    1.15 + * The implementation was written so as to conform with Netscapes SSL.
    1.16 + * 
    1.17 + * This library is free for commercial and non-commercial use as long as
    1.18 + * the following conditions are aheared to.  The following conditions
    1.19 + * apply to all code found in this distribution, be it the RC4, RSA,
    1.20 + * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
    1.21 + * included with this distribution is covered by the same copyright terms
    1.22 + * except that the holder is Tim Hudson (tjh@cryptsoft.com).
    1.23 + * 
    1.24 + * Copyright remains Eric Young's, and as such any Copyright notices in
    1.25 + * the code are not to be removed.
    1.26 + * If this package is used in a product, Eric Young should be given attribution
    1.27 + * as the author of the parts of the library used.
    1.28 + * This can be in the form of a textual message at program startup or
    1.29 + * in documentation (online or textual) provided with the package.
    1.30 + * 
    1.31 + * Redistribution and use in source and binary forms, with or without
    1.32 + * modification, are permitted provided that the following conditions
    1.33 + * are met:
    1.34 + * 1. Redistributions of source code must retain the copyright
    1.35 + *    notice, this list of conditions and the following disclaimer.
    1.36 + * 2. Redistributions in binary form must reproduce the above copyright
    1.37 + *    notice, this list of conditions and the following disclaimer in the
    1.38 + *    documentation and/or other materials provided with the distribution.
    1.39 + * 3. All advertising materials mentioning features or use of this software
    1.40 + *    must display the following acknowledgement:
    1.41 + *    "This product includes cryptographic software written by
    1.42 + *     Eric Young (eay@cryptsoft.com)"
    1.43 + *    The word 'cryptographic' can be left out if the rouines from the library
    1.44 + *    being used are not cryptographic related :-).
    1.45 + * 4. If you include any Windows specific code (or a derivative thereof) from 
    1.46 + *    the apps directory (application code) you must include an acknowledgement:
    1.47 + *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
    1.48 + * 
    1.49 + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
    1.50 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.51 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.52 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
    1.53 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    1.54 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    1.55 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.56 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    1.57 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    1.58 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.59 + * SUCH DAMAGE.
    1.60 + * 
    1.61 + * The licence and distribution terms for any publically available version or
    1.62 + * derivative of this code cannot be changed.  i.e. this code cannot simply be
    1.63 + * copied and put under another distribution licence
    1.64 + * [including the GNU Public Licence.]
    1.65 + */
    1.66 +
    1.67 +#include "des_locl.h"
    1.68 +
    1.69 +#ifdef CBC_ENC_C__DONT_UPDATE_IV
    1.70 +EXPORT_C void DES_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
    1.71 +		     DES_key_schedule *_schedule, DES_cblock *ivec, int enc)
    1.72 +#else
    1.73 +EXPORT_C void DES_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length,
    1.74 +		     DES_key_schedule *_schedule, DES_cblock *ivec, int enc)
    1.75 +#endif
    1.76 +	{
    1.77 +	register DES_LONG tin0,tin1;
    1.78 +	register DES_LONG tout0,tout1,xor0,xor1;
    1.79 +	register long l=length;
    1.80 +	DES_LONG tin[2];
    1.81 +	unsigned char *iv;
    1.82 +
    1.83 +	iv = &(*ivec)[0];
    1.84 +
    1.85 +	if (enc)
    1.86 +		{
    1.87 +		c2l(iv,tout0);
    1.88 +		c2l(iv,tout1);
    1.89 +		for (l-=8; l>=0; l-=8)
    1.90 +			{
    1.91 +			c2l(in,tin0);
    1.92 +			c2l(in,tin1);
    1.93 +			tin0^=tout0; tin[0]=tin0;
    1.94 +			tin1^=tout1; tin[1]=tin1;
    1.95 +			DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT);
    1.96 +			tout0=tin[0]; l2c(tout0,out);
    1.97 +			tout1=tin[1]; l2c(tout1,out);
    1.98 +			}
    1.99 +		if (l != -8)
   1.100 +			{
   1.101 +			c2ln(in,tin0,tin1,l+8);
   1.102 +			tin0^=tout0; tin[0]=tin0;
   1.103 +			tin1^=tout1; tin[1]=tin1;
   1.104 +			DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT);
   1.105 +			tout0=tin[0]; l2c(tout0,out);
   1.106 +			tout1=tin[1]; l2c(tout1,out);
   1.107 +			}
   1.108 +#ifndef CBC_ENC_C__DONT_UPDATE_IV
   1.109 +		iv = &(*ivec)[0];
   1.110 +		l2c(tout0,iv);
   1.111 +		l2c(tout1,iv);
   1.112 +#endif
   1.113 +		}
   1.114 +	else
   1.115 +		{
   1.116 +		c2l(iv,xor0);
   1.117 +		c2l(iv,xor1);
   1.118 +		for (l-=8; l>=0; l-=8)
   1.119 +			{
   1.120 +			c2l(in,tin0); tin[0]=tin0;
   1.121 +			c2l(in,tin1); tin[1]=tin1;
   1.122 +			DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT);
   1.123 +			tout0=tin[0]^xor0;
   1.124 +			tout1=tin[1]^xor1;
   1.125 +			l2c(tout0,out);
   1.126 +			l2c(tout1,out);
   1.127 +			xor0=tin0;
   1.128 +			xor1=tin1;
   1.129 +			}
   1.130 +		if (l != -8)
   1.131 +			{
   1.132 +			c2l(in,tin0); tin[0]=tin0;
   1.133 +			c2l(in,tin1); tin[1]=tin1;
   1.134 +			DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT);
   1.135 +			tout0=tin[0]^xor0;
   1.136 +			tout1=tin[1]^xor1;
   1.137 +			l2cn(tout0,tout1,out,l+8);
   1.138 +#ifndef CBC_ENC_C__DONT_UPDATE_IV
   1.139 +			xor0=tin0;
   1.140 +			xor1=tin1;
   1.141 +#endif
   1.142 +			}
   1.143 +#ifndef CBC_ENC_C__DONT_UPDATE_IV 
   1.144 +		iv = &(*ivec)[0];
   1.145 +		l2c(xor0,iv);
   1.146 +		l2c(xor1,iv);
   1.147 +#endif
   1.148 +		}
   1.149 +	tin0=tin1=tout0=tout1=xor0=xor1=0;
   1.150 +	tin[0]=tin[1]=0;
   1.151 +	}