2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
12 #ifdef OPENSSL_SYS_WIN32
17 #define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
18 l|=((unsigned long)(*((c)++)))<< 8L, \
19 l|=((unsigned long)(*((c)++)))<<16L, \
20 l|=((unsigned long)(*((c)++)))<<24L)
22 /* NOTE - c is not incremented as per c2l */
24 #define c2ln(c,l1,l2,n) { \
28 case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
29 case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
30 case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
31 case 5: l2|=((unsigned long)(*(--(c)))); \
32 case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
33 case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
34 case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
35 case 1: l1|=((unsigned long)(*(--(c)))); \
40 #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
41 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
42 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
43 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
45 /* NOTE - c is not incremented as per l2c */
47 #define l2cn(l1,l2,c,n) { \
50 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
51 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
52 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
53 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
54 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
55 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
56 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
57 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
61 /* NOTE - c is not incremented as per n2l */
62 #define n2ln(c,l1,l2,n) { \
66 case 8: l2 =((unsigned long)(*(--(c)))) ; \
67 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
68 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
69 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
70 case 4: l1 =((unsigned long)(*(--(c)))) ; \
71 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
72 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
73 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
77 /* NOTE - c is not incremented as per l2n */
78 #define l2nn(l1,l2,c,n) { \
81 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
82 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
83 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
84 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
85 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
86 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
87 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
88 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
93 #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
94 l|=((unsigned long)(*((c)++)))<<16L, \
95 l|=((unsigned long)(*((c)++)))<< 8L, \
96 l|=((unsigned long)(*((c)++))))
99 #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
100 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
101 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
102 *((c)++)=(unsigned char)(((l) )&0xff))
104 #if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
105 # define ROTL(a,n) (_lrotl(a,n))
107 # define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>((32-(n))&31)))
114 #define C_3 2L /* left shift */
116 /* The rotate has an extra 16 added to it to help the x86 asm */
117 #if defined(CAST_PTR)
118 # define E_CAST(n,key,L,R,OP1,OP2,OP3) \
121 t=(key[n*2] OP1 R)&0xffffffffL; \
124 L^= (((((*(CAST_LONG *)((unsigned char *) \
125 CAST_S_table0+((t>>C_2)&C_M)) OP2 \
126 *(CAST_LONG *)((unsigned char *) \
127 CAST_S_table1+((t<<C_3)&C_M)))&0xffffffffL) OP3 \
128 *(CAST_LONG *)((unsigned char *) \
129 CAST_S_table2+((t>>C_0)&C_M)))&0xffffffffL) OP1 \
130 *(CAST_LONG *)((unsigned char *) \
131 CAST_S_table3+((t>>C_1)&C_M)))&0xffffffffL; \
133 #elif defined(CAST_PTR2)
134 # define E_CAST(n,key,L,R,OP1,OP2,OP3) \
138 w=(key[n*2] OP1 R)&0xffffffffL; \
145 t= *(CAST_LONG *)((unsigned char *)CAST_S_table0+u); \
147 t=(t OP2 *(CAST_LONG *)((unsigned char *)CAST_S_table1+v))&0xffffffffL;\
151 t=(t OP3 *(CAST_LONG *)((unsigned char *)CAST_S_table2+u)&0xffffffffL);\
152 t=(t OP1 *(CAST_LONG *)((unsigned char *)CAST_S_table3+v)&0xffffffffL);\
156 # define E_CAST(n,key,L,R,OP1,OP2,OP3) \
159 t=(key[n*2] OP1 R)&0xffffffff; \
160 t=ROTL(t,(key[n*2+1])); \
161 a=CAST_S_table0[(t>> 8)&0xff]; \
162 b=CAST_S_table1[(t )&0xff]; \
163 c=CAST_S_table2[(t>>24)&0xff]; \
164 d=CAST_S_table3[(t>>16)&0xff]; \
165 L^=(((((a OP2 b)&0xffffffffL) OP3 c)&0xffffffffL) OP1 d)&0xffffffffL; \
169 extern const CAST_LONG CAST_S_table0[256];
170 extern const CAST_LONG CAST_S_table1[256];
171 extern const CAST_LONG CAST_S_table2[256];
172 extern const CAST_LONG CAST_S_table3[256];
173 extern const CAST_LONG CAST_S_table4[256];
174 extern const CAST_LONG CAST_S_table5[256];
175 extern const CAST_LONG CAST_S_table6[256];
176 extern const CAST_LONG CAST_S_table7[256];