Debian Codegraph @

debian/rust-vendor/openssl-src/openssl/crypto/idea/idea_local.h

raw
1 /*
2 * Copyright 1995-2024 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 #define idea_mul(r, a, b, ul) \
11 ul = (unsigned long)a * b; \
12 if (ul != 0) { \
13 r = (ul & 0xffff) - (ul >> 16); \
14 r -= ((r) >> 16); \
15 } else { \
16 r = (-(int)a - b + 1); /* assuming a or b is 0 and in range */ \
17 }
18
19 /* NOTE - c is not incremented as per n2l */
20 #define n2ln(c, l1, l2, n) \
21 { \
22 c += n; \
23 l1 = l2 = 0; \
24 switch (n) { \
25 case 8: \
26 l2 = ((unsigned long)(*(--(c)))); \
27 /* fall through */ \
28 case 7: \
29 l2 |= ((unsigned long)(*(--(c)))) << 8; \
30 /* fall through */ \
31 case 6: \
32 l2 |= ((unsigned long)(*(--(c)))) << 16; \
33 /* fall through */ \
34 case 5: \
35 l2 |= ((unsigned long)(*(--(c)))) << 24; \
36 /* fall through */ \
37 case 4: \
38 l1 = ((unsigned long)(*(--(c)))); \
39 /* fall through */ \
40 case 3: \
41 l1 |= ((unsigned long)(*(--(c)))) << 8; \
42 /* fall through */ \
43 case 2: \
44 l1 |= ((unsigned long)(*(--(c)))) << 16; \
45 /* fall through */ \
46 case 1: \
47 l1 |= ((unsigned long)(*(--(c)))) << 24; \
48 } \
49 }
50
51 /* NOTE - c is not incremented as per l2n */
52 #define l2nn(l1, l2, c, n) \
53 { \
54 c += n; \
55 switch (n) { \
56 case 8: \
57 *(--(c)) = (unsigned char)(((l2)) & 0xff); \
58 /* fall through */ \
59 case 7: \
60 *(--(c)) = (unsigned char)(((l2) >> 8) & 0xff); \
61 /* fall through */ \
62 case 6: \
63 *(--(c)) = (unsigned char)(((l2) >> 16) & 0xff); \
64 /* fall through */ \
65 case 5: \
66 *(--(c)) = (unsigned char)(((l2) >> 24) & 0xff); \
67 /* fall through */ \
68 case 4: \
69 *(--(c)) = (unsigned char)(((l1)) & 0xff); \
70 /* fall through */ \
71 case 3: \
72 *(--(c)) = (unsigned char)(((l1) >> 8) & 0xff); \
73 /* fall through */ \
74 case 2: \
75 *(--(c)) = (unsigned char)(((l1) >> 16) & 0xff); \
76 /* fall through */ \
77 case 1: \
78 *(--(c)) = (unsigned char)(((l1) >> 24) & 0xff); \
79 } \
80 }
81
82 #undef n2l
83 #define n2l(c, l) (l = ((unsigned long)(*((c)++))) << 24L, \
84 l |= ((unsigned long)(*((c)++))) << 16L, \
85 l |= ((unsigned long)(*((c)++))) << 8L, \
86 l |= ((unsigned long)(*((c)++))))
87
88 #undef l2n
89 #define l2n(l, c) (*((c)++) = (unsigned char)(((l) >> 24L) & 0xff), \
90 *((c)++) = (unsigned char)(((l) >> 16L) & 0xff), \
91 *((c)++) = (unsigned char)(((l) >> 8L) & 0xff), \
92 *((c)++) = (unsigned char)(((l)) & 0xff))
93
94 #undef s2n
95 #define s2n(l, c) (*((c)++) = (unsigned char)(((l)) & 0xff), \
96 *((c)++) = (unsigned char)(((l) >> 8L) & 0xff))
97
98 #undef n2s
99 #define n2s(c, l) (l = ((IDEA_INT)(*((c)++))) << 8L, \
100 l |= ((IDEA_INT)(*((c)++))))
101
102 #define E_IDEA(num) \
103 x1 &= 0xffff; \
104 idea_mul(x1, x1, *p, ul); \
105 p++; \
106 x2 += *(p++); \
107 x3 += *(p++); \
108 x4 &= 0xffff; \
109 idea_mul(x4, x4, *p, ul); \
110 p++; \
111 t0 = (x1 ^ x3) & 0xffff; \
112 idea_mul(t0, t0, *p, ul); \
113 p++; \
114 t1 = (t0 + (x2 ^ x4)) & 0xffff; \
115 idea_mul(t1, t1, *p, ul); \
116 p++; \
117 t0 += t1; \
118 x1 ^= t1; \
119 x4 ^= t0; \
120 ul = x2 ^ t0; /* do the swap to x3 */ \
121 x2 = x3 ^ t1; \
122 x3 = ul;