xref: /freebsd/crypto/openssl/crypto/rc2/rc2_local.h (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1 /*
2  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (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
8  */
9 
10 #undef c2l
11 #define c2l(c,l)        (l =((unsigned long)(*((c)++)))    , \
12                          l|=((unsigned long)(*((c)++)))<< 8L, \
13                          l|=((unsigned long)(*((c)++)))<<16L, \
14                          l|=((unsigned long)(*((c)++)))<<24L)
15 
16 /* NOTE - c is not incremented as per c2l */
17 #undef c2ln
18 #define c2ln(c,l1,l2,n) { \
19                         c+=n; \
20                         l1=l2=0; \
21                         switch (n) { \
22                         case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
23                         /* fall thru */                               \
24                         case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
25                         /* fall thru */                               \
26                         case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
27                         /* fall thru */                               \
28                         case 5: l2|=((unsigned long)(*(--(c))));      \
29                         /* fall thru */                               \
30                         case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
31                         /* fall thru */                               \
32                         case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
33                         /* fall thru */                               \
34                         case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
35                         /* fall thru */                               \
36                         case 1: l1|=((unsigned long)(*(--(c))));      \
37                                 } \
38                         }
39 
40 #undef l2c
41 #define l2c(l,c)        (*((c)++)=(unsigned char)(((l)     )&0xff), \
42                          *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
43                          *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
44                          *((c)++)=(unsigned char)(((l)>>24L)&0xff))
45 
46 /* NOTE - c is not incremented as per l2c */
47 #undef l2cn
48 #define l2cn(l1,l2,c,n) { \
49                         c+=n; \
50                         switch (n) { \
51                         case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
52                         /* fall thru */                                     \
53                         case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
54                         /* fall thru */                                     \
55                         case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
56                         /* fall thru */                                     \
57                         case 5: *(--(c))=(unsigned char)(((l2)     )&0xff); \
58                         /* fall thru */                                     \
59                         case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
60                         /* fall thru */                                     \
61                         case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
62                         /* fall thru */                                     \
63                         case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
64                         /* fall thru */                                     \
65                         case 1: *(--(c))=(unsigned char)(((l1)     )&0xff); \
66                                 } \
67                         }
68 
69 /* NOTE - c is not incremented as per n2l */
70 #define n2ln(c,l1,l2,n) { \
71                         c+=n; \
72                         l1=l2=0; \
73                         switch (n) { \
74                         case 8: l2 =((unsigned long)(*(--(c))))    ; \
75                         /* fall thru */                              \
76                         case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
77                         /* fall thru */                              \
78                         case 6: l2|=((unsigned long)(*(--(c))))<<16; \
79                         /* fall thru */                              \
80                         case 5: l2|=((unsigned long)(*(--(c))))<<24; \
81                         /* fall thru */                              \
82                         case 4: l1 =((unsigned long)(*(--(c))))    ; \
83                         /* fall thru */                              \
84                         case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
85                         /* fall thru */                              \
86                         case 2: l1|=((unsigned long)(*(--(c))))<<16; \
87                         /* fall thru */                              \
88                         case 1: l1|=((unsigned long)(*(--(c))))<<24; \
89                                 } \
90                         }
91 
92 /* NOTE - c is not incremented as per l2n */
93 #define l2nn(l1,l2,c,n) { \
94                         c+=n; \
95                         switch (n) { \
96                         case 8: *(--(c))=(unsigned char)(((l2)    )&0xff); \
97                         /* fall thru */                                    \
98                         case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
99                         /* fall thru */                                    \
100                         case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
101                         /* fall thru */                                    \
102                         case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
103                         /* fall thru */                                    \
104                         case 4: *(--(c))=(unsigned char)(((l1)    )&0xff); \
105                         /* fall thru */                                    \
106                         case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
107                         /* fall thru */                                    \
108                         case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
109                         /* fall thru */                                    \
110                         case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
111                                 } \
112                         }
113 
114 #undef n2l
115 #define n2l(c,l)        (l =((unsigned long)(*((c)++)))<<24L, \
116                          l|=((unsigned long)(*((c)++)))<<16L, \
117                          l|=((unsigned long)(*((c)++)))<< 8L, \
118                          l|=((unsigned long)(*((c)++))))
119 
120 #undef l2n
121 #define l2n(l,c)        (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
122                          *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
123                          *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
124                          *((c)++)=(unsigned char)(((l)     )&0xff))
125 
126 #define C_RC2(n) \
127         t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff; \
128         x0=(t<<1)|(t>>15); \
129         t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff; \
130         x1=(t<<2)|(t>>14); \
131         t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff; \
132         x2=(t<<3)|(t>>13); \
133         t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff; \
134         x3=(t<<5)|(t>>11);
135