1/* $FreeBSD: head/sys/crypto/blowfish/bf_locl.h 62587 2000-07-04 16:35:15Z itojun $ */ 2/* $KAME: bf_locl.h,v 1.3 2000/03/27 04:36:26 sumikawa Exp $ */ 3 |
4/* crypto/bf/bf_local.h */ 5/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au) 6 * All rights reserved. 7 * 8 * This package is an SSL implementation written 9 * by Eric Young (eay@mincom.oz.au). 10 * The implementation was written so as to conform with Netscapes SSL. 11 * --- 40 unchanged lines hidden (view full) --- 52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 54 * SUCH DAMAGE. 55 * 56 * The licence and distribution terms for any publically available version or 57 * derivative of this code cannot be changed. i.e. this code cannot simply be 58 * copied and put under another distribution licence 59 * [including the GNU Public Licence.] |
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#undef c2l |
70#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \ |
71 l|=((unsigned long)(*((c)++)))<< 8L, \ 72 l|=((unsigned long)(*((c)++)))<<16L, \ 73 l|=((unsigned long)(*((c)++)))<<24L) 74 75/* NOTE - c is not incremented as per c2l */ 76#undef c2ln |
77#define c2ln(c,l1,l2,n) { \ |
78 c+=n; \ 79 l1=l2=0; \ 80 switch (n) { \ 81 case 8: l2 =((unsigned long)(*(--(c))))<<24L; \ 82 case 7: l2|=((unsigned long)(*(--(c))))<<16L; \ 83 case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \ 84 case 5: l2|=((unsigned long)(*(--(c)))); \ 85 case 4: l1 =((unsigned long)(*(--(c))))<<24L; \ 86 case 3: l1|=((unsigned long)(*(--(c))))<<16L; \ 87 case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \ 88 case 1: l1|=((unsigned long)(*(--(c)))); \ 89 } \ 90 } 91 92#undef l2c |
93#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ |
94 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ 95 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ 96 *((c)++)=(unsigned char)(((l)>>24L)&0xff)) 97 98/* NOTE - c is not incremented as per l2c */ 99#undef l2cn |
100#define l2cn(l1,l2,c,n) { \ |
101 c+=n; \ 102 switch (n) { \ 103 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ 104 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \ 105 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \ 106 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ 107 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \ 108 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \ 109 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \ 110 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ 111 } \ 112 } 113 114/* NOTE - c is not incremented as per n2l */ |
115#define n2ln(c,l1,l2,n) { \ |
116 c+=n; \ 117 l1=l2=0; \ 118 switch (n) { \ 119 case 8: l2 =((unsigned long)(*(--(c)))) ; \ 120 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \ 121 case 6: l2|=((unsigned long)(*(--(c))))<<16; \ 122 case 5: l2|=((unsigned long)(*(--(c))))<<24; \ 123 case 4: l1 =((unsigned long)(*(--(c)))) ; \ 124 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \ 125 case 2: l1|=((unsigned long)(*(--(c))))<<16; \ 126 case 1: l1|=((unsigned long)(*(--(c))))<<24; \ 127 } \ 128 } 129 130/* NOTE - c is not incremented as per l2n */ |
131#define l2nn(l1,l2,c,n) { \ |
132 c+=n; \ 133 switch (n) { \ 134 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ 135 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ 136 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ 137 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ 138 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ 139 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ 140 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ 141 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ 142 } \ 143 } 144 145#undef n2l |
146#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \ |
147 l|=((unsigned long)(*((c)++)))<<16L, \ 148 l|=((unsigned long)(*((c)++)))<< 8L, \ 149 l|=((unsigned long)(*((c)++)))) 150 151#undef l2n |
152#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ |
153 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ 154 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ 155 *((c)++)=(unsigned char)(((l) )&0xff)) 156 157/* This is actually a big endian algorithm, the most significate byte 158 * is used to lookup array 0 */ 159 160/* use BF_PTR2 for intel boxes, 161 * BF_PTR for sparc and MIPS/SGI 162 * use nothing for Alpha and HP. 163 */ 164#if !defined(BF_PTR) && !defined(BF_PTR2) 165#undef BF_PTR 166#endif 167 |
168#define BF_M 0x3fc 169#define BF_0 22L 170#define BF_1 14L 171#define BF_2 6L 172#define BF_3 2L /* left shift */ |
173 174#if defined(BF_PTR2) 175 176/* This is basically a special pentium verson */ |
177#define BF_ENC(LL,R,S,P) \ |
178 { \ 179 BF_LONG t,u,v; \ 180 u=R>>BF_0; \ 181 v=R>>BF_1; \ 182 u&=BF_M; \ 183 v&=BF_M; \ 184 t= *(BF_LONG *)((unsigned char *)&(S[ 0])+u); \ 185 u=R>>BF_2; \ --- 6 unchanged lines hidden (view full) --- 192 t+= *(BF_LONG *)((unsigned char *)&(S[768])+v); \ 193 LL^=t; \ 194 } 195 196#elif defined(BF_PTR) 197 198/* This is normally very good */ 199 |
200#define BF_ENC(LL,R,S,P) \ |
201 LL^=P; \ 202 LL^= (((*(BF_LONG *)((unsigned char *)&(S[ 0])+((R>>BF_0)&BF_M))+ \ 203 *(BF_LONG *)((unsigned char *)&(S[256])+((R>>BF_1)&BF_M)))^ \ 204 *(BF_LONG *)((unsigned char *)&(S[512])+((R>>BF_2)&BF_M)))+ \ 205 *(BF_LONG *)((unsigned char *)&(S[768])+((R<<BF_3)&BF_M))); 206#else 207 208/* This will always work, even on 64 bit machines and strangly enough, 209 * on the Alpha it is faster than the pointer versions (both 32 and 64 210 * versions of BF_LONG) */ 211 |
212#define BF_ENC(LL,R,S,P) \ |
213 LL^=P; \ 214 LL^=((( S[ (R>>24L) ] + \ 215 S[0x0100+((R>>16L)&0xff)])^ \ 216 S[0x0200+((R>> 8L)&0xff)])+ \ 217 S[0x0300+((R )&0xff)])&0xffffffff; 218#endif |