summaryrefslogtreecommitdiff
path: root/external/poppler/0001-Revert-Make-the-mul-tables-be-calculated-at-compile-.patch.1
blob: 26fdc10dec50da99ecbc8064aad9f7cc1efbb2f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
Revert "Make the mul tables be calculated at compile time with constexpr"

This reverts commit e0ef346c0f669140076c4cf443f07ea0770996da.
---
 poppler/Decrypt.cc | 134 ++++++++++++---------------------------------
 1 file changed, 35 insertions(+), 99 deletions(-)

diff --git a/poppler/Decrypt.cc b/poppler/Decrypt.cc
index 57945778..f5062929 100644
--- a/poppler/Decrypt.cc
+++ b/poppler/Decrypt.cc
@@ -763,119 +763,55 @@ static inline void invShiftRows(unsigned char *state) {
 }
 
 // {02} \cdot s
-struct Mul02Table
-{
-  constexpr Mul02Table() : values()
-  {
-    for(int s = 0; s < 256; s++) {
-      values[s] = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
-    }
-  }
-
-  constexpr unsigned char operator()(uint8_t i) const { return values[i]; }
-
-  unsigned char values[256];
-};
-
-static constexpr Mul02Table mul02;
+static inline unsigned char mul02(unsigned char s) {
+  return (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
+}
 
 // {03} \cdot s
-struct Mul03Table
-{
-  constexpr Mul03Table() : values()
-  {
-    for(int s=0; s<256; s++) {
-      const unsigned char s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
-      values[s] = s ^ s2;
-    }
-  }
-
-  constexpr unsigned char operator()(uint8_t i) const { return values[i]; }
-
-  unsigned char values[256];
-};
-
-static constexpr Mul03Table mul03;
+static inline unsigned char mul03(unsigned char s) {
+  unsigned char s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
+  return s ^ s2;
+}
 
 // {09} \cdot s
-struct Mul09Table
-{
-  constexpr Mul09Table() : values()
-  {
-    for(int s=0; s<256; s++) {
-      const unsigned char s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
-      const unsigned char s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
-      const unsigned char s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
-      values[s] = s ^ s8;
-    }
-  }
-
-  constexpr unsigned char operator()(uint8_t i) const { return values[i]; }
-
-  unsigned char values[256];
-};
+static inline unsigned char mul09(unsigned char s) {
+  unsigned char s2, s4, s8;
 
-static constexpr Mul09Table mul09;
+  s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
+  s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
+  s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
+  return s ^ s8;
+}
 
 // {0b} \cdot s
-struct Mul0bTable
-{
-  constexpr Mul0bTable() : values()
-  {
-    for(int s=0; s<256; s++) {
-      const unsigned char s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
-      const unsigned char s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
-      const unsigned char s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
-      values[s] = s ^ s2 ^ s8;
-    }
-  }
-
-  constexpr unsigned char operator()(uint8_t i) const { return values[i]; }
+static inline unsigned char mul0b(unsigned char s) {
+  unsigned char s2, s4, s8;
 
-  unsigned char values[256];
-};
-
-static constexpr Mul0bTable mul0b;
+  s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
+  s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
+  s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
+  return s ^ s2 ^ s8;
+}
 
 // {0d} \cdot s
-struct Mul0dTable
-{
-  constexpr Mul0dTable() : values()
-  {
-    for(int s=0; s<256; s++) {
-      const unsigned char s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
-      const unsigned char s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
-      const unsigned char s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
-      values[s] = s ^ s4 ^ s8;
-    }
-  }
+static inline unsigned char mul0d(unsigned char s) {
+  unsigned char s2, s4, s8;
 
-  constexpr unsigned char operator()(uint8_t i) const { return values[i]; }
-
-  unsigned char values[256];
-};
-
-static constexpr Mul0dTable mul0d;
+  s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
+  s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
+  s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
+  return s ^ s4 ^ s8;
+}
 
 // {0e} \cdot s
-struct Mul0eTable
-{
-  constexpr Mul0eTable() : values()
-  {
-    for(int s=0; s<256; s++) {
-      const unsigned char s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
-      const unsigned char s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
-      const unsigned char s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
-      values[s] = s2 ^ s4 ^ s8;
-    }
-  }
-
-  constexpr unsigned char operator()(uint8_t i) const { return values[i]; }
+static inline unsigned char mul0e(unsigned char s) {
+  unsigned char s2, s4, s8;
 
-  unsigned char values[256];
-};
-
-static constexpr Mul0eTable mul0e;
+  s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
+  s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
+  s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
+  return s2 ^ s4 ^ s8;
+}
 
 static inline void mixColumns(unsigned char *state) {
   int c;
-- 
2.21.0