Deleted Added
full compact
bf_locl.h (55009) bf_locl.h (62587)
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
1/* crypto/bf/bf_local.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@mincom.oz.au).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *

--- 40 unchanged lines hidden (view full) ---

49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
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.]
57 *
58 * $FreeBSD: head/sys/crypto/blowfish/bf_locl.h 55009 1999-12-22 19:13:38Z shin $
59 */
60/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
61 *
62 * Always modify bf_locl.org since bf_locl.h is automatically generated from
63 * it during SSLeay configuration.
64 *
65 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
66 */
67
68#undef c2l
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
69#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
70#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
70 l|=((unsigned long)(*((c)++)))<< 8L, \
71 l|=((unsigned long)(*((c)++)))<<16L, \
72 l|=((unsigned long)(*((c)++)))<<24L)
73
74/* NOTE - c is not incremented as per c2l */
75#undef c2ln
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
76#define c2ln(c,l1,l2,n) { \
77#define c2ln(c,l1,l2,n) { \
77 c+=n; \
78 l1=l2=0; \
79 switch (n) { \
80 case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
81 case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
82 case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
83 case 5: l2|=((unsigned long)(*(--(c)))); \
84 case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
85 case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
86 case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
87 case 1: l1|=((unsigned long)(*(--(c)))); \
88 } \
89 }
90
91#undef l2c
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
92#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
93#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
93 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
94 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
95 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
96
97/* NOTE - c is not incremented as per l2c */
98#undef l2cn
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
99#define l2cn(l1,l2,c,n) { \
100#define l2cn(l1,l2,c,n) { \
100 c+=n; \
101 switch (n) { \
102 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
103 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
104 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
105 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
106 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
107 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
108 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
109 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
110 } \
111 }
112
113/* NOTE - c is not incremented as per n2l */
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 */
114#define n2ln(c,l1,l2,n) { \
115#define n2ln(c,l1,l2,n) { \
115 c+=n; \
116 l1=l2=0; \
117 switch (n) { \
118 case 8: l2 =((unsigned long)(*(--(c)))) ; \
119 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
120 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
121 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
122 case 4: l1 =((unsigned long)(*(--(c)))) ; \
123 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
124 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
125 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
126 } \
127 }
128
129/* NOTE - c is not incremented as per l2n */
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 */
130#define l2nn(l1,l2,c,n) { \
131#define l2nn(l1,l2,c,n) { \
131 c+=n; \
132 switch (n) { \
133 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
134 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
135 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
136 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
137 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
138 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
139 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
140 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
141 } \
142 }
143
144#undef n2l
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
145#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
146#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
146 l|=((unsigned long)(*((c)++)))<<16L, \
147 l|=((unsigned long)(*((c)++)))<< 8L, \
148 l|=((unsigned long)(*((c)++))))
149
150#undef l2n
147 l|=((unsigned long)(*((c)++)))<<16L, \
148 l|=((unsigned long)(*((c)++)))<< 8L, \
149 l|=((unsigned long)(*((c)++))))
150
151#undef l2n
151#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
152#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
152 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
153 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
154 *((c)++)=(unsigned char)(((l) )&0xff))
155
156/* This is actually a big endian algorithm, the most significate byte
157 * is used to lookup array 0 */
158
159/* use BF_PTR2 for intel boxes,
160 * BF_PTR for sparc and MIPS/SGI
161 * use nothing for Alpha and HP.
162 */
163#if !defined(BF_PTR) && !defined(BF_PTR2)
164#undef BF_PTR
165#endif
166
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
167#define BF_M 0x3fc
168#define BF_0 22L
169#define BF_1 14L
170#define BF_2 6L
171#define BF_3 2L /* left shift */
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 */
172
173#if defined(BF_PTR2)
174
175/* This is basically a special pentium verson */
173
174#if defined(BF_PTR2)
175
176/* This is basically a special pentium verson */
176#define BF_ENC(LL,R,S,P) \
177#define BF_ENC(LL,R,S,P) \
177 { \
178 BF_LONG t,u,v; \
179 u=R>>BF_0; \
180 v=R>>BF_1; \
181 u&=BF_M; \
182 v&=BF_M; \
183 t= *(BF_LONG *)((unsigned char *)&(S[ 0])+u); \
184 u=R>>BF_2; \

--- 6 unchanged lines hidden (view full) ---

191 t+= *(BF_LONG *)((unsigned char *)&(S[768])+v); \
192 LL^=t; \
193 }
194
195#elif defined(BF_PTR)
196
197/* This is normally very good */
198
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
199#define BF_ENC(LL,R,S,P) \
200#define BF_ENC(LL,R,S,P) \
200 LL^=P; \
201 LL^= (((*(BF_LONG *)((unsigned char *)&(S[ 0])+((R>>BF_0)&BF_M))+ \
202 *(BF_LONG *)((unsigned char *)&(S[256])+((R>>BF_1)&BF_M)))^ \
203 *(BF_LONG *)((unsigned char *)&(S[512])+((R>>BF_2)&BF_M)))+ \
204 *(BF_LONG *)((unsigned char *)&(S[768])+((R<<BF_3)&BF_M)));
205#else
206
207/* This will always work, even on 64 bit machines and strangly enough,
208 * on the Alpha it is faster than the pointer versions (both 32 and 64
209 * versions of BF_LONG) */
210
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
211#define BF_ENC(LL,R,S,P) \
212#define BF_ENC(LL,R,S,P) \
212 LL^=P; \
213 LL^=((( S[ (R>>24L) ] + \
214 S[0x0100+((R>>16L)&0xff)])^ \
215 S[0x0200+((R>> 8L)&0xff)])+ \
216 S[0x0300+((R )&0xff)])&0xffffffff;
217#endif
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