147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom/* crypto/bf/bf_locl.h */
247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * All rights reserved.
447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *
547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * This package is an SSL implementation written
647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * by Eric Young (eay@cryptsoft.com).
747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * The implementation was written so as to conform with Netscapes SSL.
847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *
947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * This library is free for commercial and non-commercial use as long as
1047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * the following conditions are aheared to.  The following conditions
1147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * apply to all code found in this distribution, be it the RC4, RSA,
1247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * included with this distribution is covered by the same copyright terms
1447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *
1647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * Copyright remains Eric Young's, and as such any Copyright notices in
1747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * the code are not to be removed.
1847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * If this package is used in a product, Eric Young should be given attribution
1947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * as the author of the parts of the library used.
2047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * This can be in the form of a textual message at program startup or
2147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * in documentation (online or textual) provided with the package.
2247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *
2347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * Redistribution and use in source and binary forms, with or without
2447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * modification, are permitted provided that the following conditions
2547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * are met:
2647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * 1. Redistributions of source code must retain the copyright
2747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    notice, this list of conditions and the following disclaimer.
2847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * 2. Redistributions in binary form must reproduce the above copyright
2947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    notice, this list of conditions and the following disclaimer in the
3047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    documentation and/or other materials provided with the distribution.
3147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * 3. All advertising materials mentioning features or use of this software
3247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    must display the following acknowledgement:
3347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    "This product includes cryptographic software written by
3447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *     Eric Young (eay@cryptsoft.com)"
3547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    The word 'cryptographic' can be left out if the rouines from the library
3647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    being used are not cryptographic related :-).
3747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * 4. If you include any Windows specific code (or a derivative thereof) from
3847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    the apps directory (application code) you must include an acknowledgement:
3947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
4047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *
4147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * SUCH DAMAGE.
5247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *
5347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * The licence and distribution terms for any publically available version or
5447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * derivative of this code cannot be changed.  i.e. this code cannot simply be
5547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * copied and put under another distribution licence
5647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * [including the GNU Public Licence.]
5747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom */
5847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
5947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#ifndef HEADER_BF_LOCL_H
6047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define HEADER_BF_LOCL_H
6147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#include <openssl/opensslconf.h> /* BF_PTR, BF_PTR2 */
6247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
6347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#undef c2l
6447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define c2l(c,l)	(l =((unsigned long)(*((c)++)))    , \
6547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			 l|=((unsigned long)(*((c)++)))<< 8L, \
6647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			 l|=((unsigned long)(*((c)++)))<<16L, \
6747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			 l|=((unsigned long)(*((c)++)))<<24L)
6847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
6947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom/* NOTE - c is not incremented as per c2l */
7047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#undef c2ln
7147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define c2ln(c,l1,l2,n)	{ \
7247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			c+=n; \
7347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			l1=l2=0; \
7447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			switch (n) { \
7547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
7647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
7747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
7847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 5: l2|=((unsigned long)(*(--(c))));     \
7947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
8047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
8147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
8247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 1: l1|=((unsigned long)(*(--(c))));     \
8347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom				} \
8447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			}
8547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
8647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#undef l2c
8747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define l2c(l,c)	(*((c)++)=(unsigned char)(((l)     )&0xff), \
8847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
8947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
9047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
9147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
9247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom/* NOTE - c is not incremented as per l2c */
9347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#undef l2cn
9447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define l2cn(l1,l2,c,n)	{ \
9547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			c+=n; \
9647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			switch (n) { \
9747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
9847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
9947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
10047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 5: *(--(c))=(unsigned char)(((l2)     )&0xff); \
10147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
10247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
10347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
10447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 1: *(--(c))=(unsigned char)(((l1)     )&0xff); \
10547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom				} \
10647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			}
10747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
10847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom/* NOTE - c is not incremented as per n2l */
10947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define n2ln(c,l1,l2,n)	{ \
11047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			c+=n; \
11147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			l1=l2=0; \
11247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			switch (n) { \
11347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 8: l2 =((unsigned long)(*(--(c))))    ; \
11447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
11547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 6: l2|=((unsigned long)(*(--(c))))<<16; \
11647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 5: l2|=((unsigned long)(*(--(c))))<<24; \
11747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 4: l1 =((unsigned long)(*(--(c))))    ; \
11847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
11947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 2: l1|=((unsigned long)(*(--(c))))<<16; \
12047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 1: l1|=((unsigned long)(*(--(c))))<<24; \
12147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom				} \
12247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			}
12347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
12447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom/* NOTE - c is not incremented as per l2n */
12547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define l2nn(l1,l2,c,n)	{ \
12647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			c+=n; \
12747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			switch (n) { \
12847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 8: *(--(c))=(unsigned char)(((l2)    )&0xff); \
12947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
13047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
13147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
13247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 4: *(--(c))=(unsigned char)(((l1)    )&0xff); \
13347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
13447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
13547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
13647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom				} \
13747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom			}
13847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
13947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#undef n2l
14047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define n2l(c,l)        (l =((unsigned long)(*((c)++)))<<24L, \
14147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom                         l|=((unsigned long)(*((c)++)))<<16L, \
14247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom                         l|=((unsigned long)(*((c)++)))<< 8L, \
14347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom                         l|=((unsigned long)(*((c)++))))
14447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
14547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#undef l2n
14647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define l2n(l,c)        (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
14747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom                         *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
14847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom                         *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
14947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom                         *((c)++)=(unsigned char)(((l)     )&0xff))
15047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
15147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom/* This is actually a big endian algorithm, the most significant byte
15247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * is used to lookup array 0 */
15347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
15447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#if defined(BF_PTR2)
15547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
15647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom/*
15747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * This is basically a special Intel version. Point is that Intel
15847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * doesn't have many registers, but offers a reach choice of addressing
15947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * modes. So we spare some registers by directly traversing BF_KEY
16047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * structure and hiring the most decorated addressing mode. The code
16147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * generated by EGCS is *perfectly* competitive with assembler
16247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * implementation!
16347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom */
16447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define BF_ENC(LL,R,KEY,Pi) (\
16547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	LL^=KEY[Pi], \
16647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	t=  KEY[BF_ROUNDS+2 +   0 + ((R>>24)&0xFF)], \
16747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	t+= KEY[BF_ROUNDS+2 + 256 + ((R>>16)&0xFF)], \
16847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	t^= KEY[BF_ROUNDS+2 + 512 + ((R>>8 )&0xFF)], \
16947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	t+= KEY[BF_ROUNDS+2 + 768 + ((R    )&0xFF)], \
17047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	LL^=t \
17147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	)
17247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
17347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#elif defined(BF_PTR)
17447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
17547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#ifndef BF_LONG_LOG2
17647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define BF_LONG_LOG2  2       /* default to BF_LONG being 32 bits */
17747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#endif
17847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define BF_M  (0xFF<<BF_LONG_LOG2)
17947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define BF_0  (24-BF_LONG_LOG2)
18047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define BF_1  (16-BF_LONG_LOG2)
18147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define BF_2  ( 8-BF_LONG_LOG2)
18247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define BF_3  BF_LONG_LOG2 /* left shift */
18347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
18447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom/*
18547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * This is normally very good on RISC platforms where normally you
18647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * have to explicitly "multiply" array index by sizeof(BF_LONG)
18747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * in order to calculate the effective address. This implementation
18847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * excuses CPU from this extra work. Power[PC] uses should have most
18947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * fun as (R>>BF_i)&BF_M gets folded into a single instruction, namely
19047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * rlwinm. So let'em double-check if their compiler does it.
19147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom */
19247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
19347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define BF_ENC(LL,R,S,P) ( \
19447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	LL^=P, \
19547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	LL^= (((*(BF_LONG *)((unsigned char *)&(S[  0])+((R>>BF_0)&BF_M))+ \
19647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom		*(BF_LONG *)((unsigned char *)&(S[256])+((R>>BF_1)&BF_M)))^ \
19747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom		*(BF_LONG *)((unsigned char *)&(S[512])+((R>>BF_2)&BF_M)))+ \
19847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom		*(BF_LONG *)((unsigned char *)&(S[768])+((R<<BF_3)&BF_M))) \
19947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	)
20047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#else
20147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
20247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom/*
20347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * This is a *generic* version. Seem to perform best on platforms that
20447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * offer explicit support for extraction of 8-bit nibbles preferably
20547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * complemented with "multiplying" of array index by sizeof(BF_LONG).
20647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * For the moment of this writing the list comprises Alpha CPU featuring
20747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * extbl and s[48]addq instructions.
20847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom */
20947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
21047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#define BF_ENC(LL,R,S,P) ( \
21147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	LL^=P, \
21247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	LL^=(((	S[       ((int)(R>>24)&0xff)] + \
21347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom		S[0x0100+((int)(R>>16)&0xff)])^ \
21447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom		S[0x0200+((int)(R>> 8)&0xff)])+ \
21547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom		S[0x0300+((int)(R    )&0xff)])&0xffffffffL \
21647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	)
21747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#endif
21847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
21947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#endif
220