|
|
1.1.1.3 ! root 1: /* Deprecated/legacy */ ! 2: 1.1 root 3: /* crypto/bf/bf_locl.org */ 4: /* Copyright (C) 1995-1997 Eric Young ([email protected]) 5: * All rights reserved. 6: * 7: * This package is an SSL implementation written 8: * by Eric Young ([email protected]). 9: * The implementation was written so as to conform with Netscapes SSL. 10: * 11: * This library is free for commercial and non-commercial use as long as 12: * the following conditions are aheared to. The following conditions 13: * apply to all code found in this distribution, be it the RC4, RSA, 14: * lhash, DES, etc., code; not just the SSL code. The SSL documentation 15: * included with this distribution is covered by the same copyright terms 16: * except that the holder is Tim Hudson ([email protected]). 17: * 18: * Copyright remains Eric Young's, and as such any Copyright notices in 19: * the code are not to be removed. 20: * If this package is used in a product, Eric Young should be given attribution 21: * as the author of the parts of the library used. 22: * This can be in the form of a textual message at program startup or 23: * in documentation (online or textual) provided with the package. 24: * 25: * Redistribution and use in source and binary forms, with or without 26: * modification, are permitted provided that the following conditions 27: * are met: 28: * 1. Redistributions of source code must retain the copyright 29: * notice, this list of conditions and the following disclaimer. 30: * 2. Redistributions in binary form must reproduce the above copyright 31: * notice, this list of conditions and the following disclaimer in the 32: * documentation and/or other materials provided with the distribution. 33: * 3. All advertising materials mentioning features or use of this software 34: * must display the following acknowledgement: 35: * "This product includes cryptographic software written by 36: * Eric Young ([email protected])" 37: * The word 'cryptographic' can be left out if the rouines from the library 38: * being used are not cryptographic related :-). 39: * 4. If you include any Windows specific code (or a derivative thereof) from 40: * the apps directory (application code) you must include an acknowledgement: 41: * "This product includes software written by Tim Hudson ([email protected])" 42: * 43: * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 44: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 45: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 46: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 47: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 48: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 49: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 50: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 51: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 52: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 53: * SUCH DAMAGE. 54: * 55: * The licence and distribution terms for any publically available version or 56: * derivative of this code cannot be changed. i.e. this code cannot simply be 57: * copied and put under another distribution licence 58: * [including the GNU Public Licence.] 59: */ 60: 61: /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 62: * 63: * Always modify bf_locl.org since bf_locl.h is automatically generated from 64: * it during SSLeay configuration. 65: * 66: * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 67: */ 68: 69: /* Special defines which change the way the code is built depending on the 70: CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find 71: even newer MIPS CPU's, but at the moment one size fits all for 72: optimization options. Older Sparc's work better with only UNROLL, but 73: there's no way to tell at compile time what it is you're running on */ 74: 75: #if defined( sun ) /* Newer Sparc's */ 76: # define BF_PTR 77: #elif defined( __ultrix ) /* Older MIPS */ 78: # define BF_PTR 79: #elif defined( __osf1__ ) /* Alpha */ 80: /* None */ 81: #elif defined ( _AIX ) /* RS6000 */ 82: /* Unknown */ 83: #elif defined( __hpux ) /* HP-PA */ 84: /* None */ 85: #elif defined( __aux ) /* 68K */ 86: /* Unknown */ 87: #elif defined( __dgux ) /* 88K (but P6 in latest boxes) */ 88: /* Unknown */ 89: #elif defined( __sgi ) /* Newer MIPS */ 90: # define BF_PTR 91: #elif defined( i386 ) /* x86 boxes, should be gcc */ 92: # define BF_PTR2 93: #elif defined( _MSC_VER ) /* x86 boxes, Visual C */ 94: # define BF_PTR2 95: #endif /* Systems-specific speed defines */ 96: 97: #undef c2l 1.1.1.2 root 98: #define c2l(c,l) (l =((unsigned __int32)(*((c)++))) , \ 99: l|=((unsigned __int32)(*((c)++)))<< 8L, \ 100: l|=((unsigned __int32)(*((c)++)))<<16L, \ 101: l|=((unsigned __int32)(*((c)++)))<<24L) 1.1 root 102: 103: /* NOTE - c is not incremented as per c2l */ 104: #undef c2ln 105: #define c2ln(c,l1,l2,n) { \ 106: c+=n; \ 107: l1=l2=0; \ 108: switch (n) { \ 1.1.1.2 root 109: case 8: l2 =((unsigned __int32)(*(--(c))))<<24L; \ 110: case 7: l2|=((unsigned __int32)(*(--(c))))<<16L; \ 111: case 6: l2|=((unsigned __int32)(*(--(c))))<< 8L; \ 112: case 5: l2|=((unsigned __int32)(*(--(c)))); \ 113: case 4: l1 =((unsigned __int32)(*(--(c))))<<24L; \ 114: case 3: l1|=((unsigned __int32)(*(--(c))))<<16L; \ 115: case 2: l1|=((unsigned __int32)(*(--(c))))<< 8L; \ 116: case 1: l1|=((unsigned __int32)(*(--(c)))); \ 1.1 root 117: } \ 118: } 119: 120: #undef l2c 121: #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ 122: *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ 123: *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ 124: *((c)++)=(unsigned char)(((l)>>24L)&0xff)) 125: 126: /* NOTE - c is not incremented as per l2c */ 127: #undef l2cn 128: #define l2cn(l1,l2,c,n) { \ 129: c+=n; \ 130: switch (n) { \ 131: case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ 132: case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \ 133: case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \ 134: case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ 135: case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \ 136: case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \ 137: case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \ 138: case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ 139: } \ 140: } 141: 142: /* NOTE - c is not incremented as per n2l */ 143: #define n2ln(c,l1,l2,n) { \ 144: c+=n; \ 145: l1=l2=0; \ 146: switch (n) { \ 1.1.1.2 root 147: case 8: l2 =((unsigned __int32)(*(--(c)))) ; \ 148: case 7: l2|=((unsigned __int32)(*(--(c))))<< 8; \ 149: case 6: l2|=((unsigned __int32)(*(--(c))))<<16; \ 150: case 5: l2|=((unsigned __int32)(*(--(c))))<<24; \ 151: case 4: l1 =((unsigned __int32)(*(--(c)))) ; \ 152: case 3: l1|=((unsigned __int32)(*(--(c))))<< 8; \ 153: case 2: l1|=((unsigned __int32)(*(--(c))))<<16; \ 154: case 1: l1|=((unsigned __int32)(*(--(c))))<<24; \ 1.1 root 155: } \ 156: } 157: 158: /* NOTE - c is not incremented as per l2n */ 159: #define l2nn(l1,l2,c,n) { \ 160: c+=n; \ 161: switch (n) { \ 162: case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ 163: case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ 164: case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ 165: case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ 166: case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ 167: case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ 168: case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ 169: case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ 170: } \ 171: } 172: 173: #undef n2l 1.1.1.2 root 174: #define n2l(c,l) (l =((unsigned __int32)(*((c)++)))<<24L, \ 175: l|=((unsigned __int32)(*((c)++)))<<16L, \ 176: l|=((unsigned __int32)(*((c)++)))<< 8L, \ 177: l|=((unsigned __int32)(*((c)++)))) 1.1 root 178: 179: #undef l2n 180: #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ 181: *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ 182: *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ 183: *((c)++)=(unsigned char)(((l) )&0xff)) 184: 185: /* This is actually a big endian algorithm, the most significate byte 186: * is used to lookup array 0 */ 187: 188: /* use BF_PTR2 for intel boxes, 189: * BF_PTR for sparc and MIPS/SGI 190: * use nothing for Alpha and HP. 191: */ 192: #if !defined(BF_PTR) && !defined(BF_PTR2) 193: #define BF_PTR2 194: #endif 195: 196: #define BF_M 0x3fc 197: #define BF_0 22L 198: #define BF_1 14L 199: #define BF_2 6L 200: #define BF_3 2L /* left shift */ 201: 202: #if defined(BF_PTR2) 203: 204: /* This is basically a special pentium verson */ 205: #define BF_ENC(LL,R,S,P) \ 206: { \ 207: BF_LONG t,u,v; \ 208: u=R>>BF_0; \ 209: v=R>>BF_1; \ 210: u&=BF_M; \ 211: v&=BF_M; \ 212: t= *(BF_LONG *)((unsigned char *)&(S[ 0])+u); \ 213: u=R>>BF_2; \ 214: t+= *(BF_LONG *)((unsigned char *)&(S[256])+v); \ 215: v=R<<BF_3; \ 216: u&=BF_M; \ 217: v&=BF_M; \ 218: t^= *(BF_LONG *)((unsigned char *)&(S[512])+u); \ 219: LL^=P; \ 220: t+= *(BF_LONG *)((unsigned char *)&(S[768])+v); \ 221: LL^=t; \ 222: } 223: 224: #elif defined(BF_PTR) 225: 226: /* This is normally very good */ 227: 228: #define BF_ENC(LL,R,S,P) \ 229: LL^=P; \ 230: LL^= (((*(BF_LONG *)((unsigned char *)&(S[ 0])+((R>>BF_0)&BF_M))+ \ 231: *(BF_LONG *)((unsigned char *)&(S[256])+((R>>BF_1)&BF_M)))^ \ 232: *(BF_LONG *)((unsigned char *)&(S[512])+((R>>BF_2)&BF_M)))+ \ 233: *(BF_LONG *)((unsigned char *)&(S[768])+((R<<BF_3)&BF_M))); 234: #else 235: 236: /* This will always work, even on 64 bit machines and strangly enough, 237: * on the Alpha it is faster than the pointer versions (both 32 and 64 238: * versions of BF_LONG) */ 239: 240: #define BF_ENC(LL,R,S,P) \ 241: LL^=P; \ 242: LL^=((( S[ (int)(R>>24L) ] + \ 243: S[0x0100+((int)(R>>16L)&0xff)])^ \ 244: S[0x0200+((int)(R>> 8L)&0xff)])+ \ 245: S[0x0300+((int)(R )&0xff)])&0xffffffffL; 246: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.