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