Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/include/internal/constant_time_locl.h |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | static inline unsigned int constant_time_msb(unsigned int a); | - | ||||||
3 | - | |||||||
4 | static inline uint32_t constant_time_msb_32(uint32_t a); | - | ||||||
5 | - | |||||||
6 | static inline uint64_t constant_time_msb_64(uint64_t a); | - | ||||||
7 | - | |||||||
8 | - | |||||||
9 | static inline unsigned int constant_time_lt(unsigned int a, | - | ||||||
10 | unsigned int b); | - | ||||||
11 | - | |||||||
12 | static inline unsigned char constant_time_lt_8(unsigned int a, | - | ||||||
13 | unsigned int b); | - | ||||||
14 | - | |||||||
15 | static inline uint64_t constant_time_lt_64(uint64_t a, uint64_t b); | - | ||||||
16 | - | |||||||
17 | - | |||||||
18 | static inline unsigned int constant_time_ge(unsigned int a, | - | ||||||
19 | unsigned int b); | - | ||||||
20 | - | |||||||
21 | static inline unsigned char constant_time_ge_8(unsigned int a, | - | ||||||
22 | unsigned int b); | - | ||||||
23 | - | |||||||
24 | - | |||||||
25 | static inline unsigned int constant_time_is_zero(unsigned int a); | - | ||||||
26 | - | |||||||
27 | static inline unsigned char constant_time_is_zero_8(unsigned int a); | - | ||||||
28 | - | |||||||
29 | static inline uint32_t constant_time_is_zero_32(uint32_t a); | - | ||||||
30 | - | |||||||
31 | - | |||||||
32 | static inline unsigned int constant_time_eq(unsigned int a, | - | ||||||
33 | unsigned int b); | - | ||||||
34 | - | |||||||
35 | static inline unsigned char constant_time_eq_8(unsigned int a, | - | ||||||
36 | unsigned int b); | - | ||||||
37 | - | |||||||
38 | static inline unsigned int constant_time_eq_int(int a, int b); | - | ||||||
39 | - | |||||||
40 | static inline unsigned char constant_time_eq_int_8(int a, int b); | - | ||||||
41 | static inline unsigned int constant_time_select(unsigned int mask, | - | ||||||
42 | unsigned int a, | - | ||||||
43 | unsigned int b); | - | ||||||
44 | - | |||||||
45 | static inline unsigned char constant_time_select_8(unsigned char mask, | - | ||||||
46 | unsigned char a, | - | ||||||
47 | unsigned char b); | - | ||||||
48 | - | |||||||
49 | - | |||||||
50 | static inline uint32_t constant_time_select_32(uint32_t mask, uint32_t a, | - | ||||||
51 | uint32_t b); | - | ||||||
52 | - | |||||||
53 | - | |||||||
54 | static inline uint64_t constant_time_select_64(uint64_t mask, uint64_t a, | - | ||||||
55 | uint64_t b); | - | ||||||
56 | - | |||||||
57 | static inline int constant_time_select_int(unsigned int mask, int a, | - | ||||||
58 | int b); | - | ||||||
59 | - | |||||||
60 | - | |||||||
61 | static inline unsigned int constant_time_msb(unsigned int a) | - | ||||||
62 | { | - | ||||||
63 | return executed 11388508 times by 3 tests: 0 - (a >> (sizeof(a) * 8 - 1));return 0 - (a >> (sizeof(a) * 8 - 1)); Executed by:
executed 11388508 times by 3 tests: return 0 - (a >> (sizeof(a) * 8 - 1)); Executed by:
| 11388508 | ||||||
64 | } | - | ||||||
65 | - | |||||||
66 | - | |||||||
67 | static inline uint32_t constant_time_msb_32(uint32_t a) | - | ||||||
68 | { | - | ||||||
69 | return executed 4476 times by 3 tests: 0 - (a >> 31);return 0 - (a >> 31); Executed by:
executed 4476 times by 3 tests: return 0 - (a >> 31); Executed by:
| 4476 | ||||||
70 | } | - | ||||||
71 | - | |||||||
72 | static inline uint64_t constant_time_msb_64(uint64_t a) | - | ||||||
73 | { | - | ||||||
74 | return executed 55 times by 1 test: 0 - (a >> 63);return 0 - (a >> 63); Executed by:
executed 55 times by 1 test: return 0 - (a >> 63); Executed by:
| 55 | ||||||
75 | } | - | ||||||
76 | - | |||||||
77 | static inline size_t constant_time_msb_s(size_t a) | - | ||||||
78 | { | - | ||||||
79 | return executed 1280374 times by 4 tests: 0 - (a >> (sizeof(a) * 8 - 1));return 0 - (a >> (sizeof(a) * 8 - 1)); Executed by:
executed 1280374 times by 4 tests: return 0 - (a >> (sizeof(a) * 8 - 1)); Executed by:
| 1280374 | ||||||
80 | } | - | ||||||
81 | - | |||||||
82 | static inline unsigned int constant_time_lt(unsigned int a, | - | ||||||
83 | unsigned int b) | - | ||||||
84 | { | - | ||||||
85 | return executed 786 times by 2 tests: constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b)));return constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b))); Executed by:
executed 786 times by 2 tests: return constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b))); Executed by:
| 786 | ||||||
86 | } | - | ||||||
87 | - | |||||||
88 | static inline size_t constant_time_lt_s(size_t a, size_t b) | - | ||||||
89 | { | - | ||||||
90 | return executed 1065283 times by 2 tests: constant_time_msb_s(a ^ ((a ^ b) | ((a - b) ^ b)));return constant_time_msb_s(a ^ ((a ^ b) | ((a - b) ^ b))); Executed by:
executed 1065283 times by 2 tests: return constant_time_msb_s(a ^ ((a ^ b) | ((a - b) ^ b))); Executed by:
| 1065283 | ||||||
91 | } | - | ||||||
92 | - | |||||||
93 | static inline unsigned char constant_time_lt_8(unsigned int a, | - | ||||||
94 | unsigned int b) | - | ||||||
95 | { | - | ||||||
96 | return executed 162 times by 1 test: (unsigned char)constant_time_lt(a, b);return (unsigned char)constant_time_lt(a, b); Executed by:
executed 162 times by 1 test: return (unsigned char)constant_time_lt(a, b); Executed by:
| 162 | ||||||
97 | } | - | ||||||
98 | - | |||||||
99 | static inline uint64_t constant_time_lt_64(uint64_t a, uint64_t b) | - | ||||||
100 | { | - | ||||||
101 | return executed 55 times by 1 test: constant_time_msb_64(a ^ ((a ^ b) | ((a - b) ^ b)));return constant_time_msb_64(a ^ ((a ^ b) | ((a - b) ^ b))); Executed by:
executed 55 times by 1 test: return constant_time_msb_64(a ^ ((a ^ b) | ((a - b) ^ b))); Executed by:
| 55 | ||||||
102 | } | - | ||||||
103 | - | |||||||
104 | static inline unsigned int constant_time_ge(unsigned int a, | - | ||||||
105 | unsigned int b) | - | ||||||
106 | { | - | ||||||
107 | return executed 424 times by 2 tests: ~constant_time_lt(a, b);return ~constant_time_lt(a, b); Executed by:
executed 424 times by 2 tests: return ~constant_time_lt(a, b); Executed by:
| 424 | ||||||
108 | } | - | ||||||
109 | - | |||||||
110 | static inline size_t constant_time_ge_s(size_t a, size_t b) | - | ||||||
111 | { | - | ||||||
112 | return executed 997931 times by 2 tests: ~constant_time_lt_s(a, b);return ~constant_time_lt_s(a, b); Executed by:
executed 997931 times by 2 tests: return ~constant_time_lt_s(a, b); Executed by:
| 997931 | ||||||
113 | } | - | ||||||
114 | - | |||||||
115 | static inline unsigned char constant_time_ge_8(unsigned int a, | - | ||||||
116 | unsigned int b) | - | ||||||
117 | { | - | ||||||
118 | return executed 162 times by 1 test: (unsigned char)constant_time_ge(a, b);return (unsigned char)constant_time_ge(a, b); Executed by:
executed 162 times by 1 test: return (unsigned char)constant_time_ge(a, b); Executed by:
| 162 | ||||||
119 | } | - | ||||||
120 | - | |||||||
121 | static inline unsigned char constant_time_ge_8_s(size_t a, size_t b) | - | ||||||
122 | { | - | ||||||
123 | return executed 992568 times by 1 test: (unsigned char)constant_time_ge_s(a, b);return (unsigned char)constant_time_ge_s(a, b); Executed by:
executed 992568 times by 1 test: return (unsigned char)constant_time_ge_s(a, b); Executed by:
| 992568 | ||||||
124 | } | - | ||||||
125 | - | |||||||
126 | static inline unsigned int constant_time_is_zero(unsigned int a) | - | ||||||
127 | { | - | ||||||
128 | return executed 11387722 times by 3 tests: constant_time_msb(~a & (a - 1));return constant_time_msb(~a & (a - 1)); Executed by:
executed 11387722 times by 3 tests: return constant_time_msb(~a & (a - 1)); Executed by:
| 11387722 | ||||||
129 | } | - | ||||||
130 | - | |||||||
131 | static inline size_t constant_time_is_zero_s(size_t a) | - | ||||||
132 | { | - | ||||||
133 | return executed 215091 times by 4 tests: constant_time_msb_s(~a & (a - 1));return constant_time_msb_s(~a & (a - 1)); Executed by:
executed 215091 times by 4 tests: return constant_time_msb_s(~a & (a - 1)); Executed by:
| 215091 | ||||||
134 | } | - | ||||||
135 | - | |||||||
136 | static inline unsigned char constant_time_is_zero_8(unsigned int a) | - | ||||||
137 | { | - | ||||||
138 | return executed 29879 times by 2 tests: (unsigned char)constant_time_is_zero(a);return (unsigned char)constant_time_is_zero(a); Executed by:
executed 29879 times by 2 tests: return (unsigned char)constant_time_is_zero(a); Executed by:
| 29879 | ||||||
139 | } | - | ||||||
140 | - | |||||||
141 | static inline uint32_t constant_time_is_zero_32(uint32_t a) | - | ||||||
142 | { | - | ||||||
143 | return executed 4476 times by 3 tests: constant_time_msb_32(~a & (a - 1));return constant_time_msb_32(~a & (a - 1)); Executed by:
executed 4476 times by 3 tests: return constant_time_msb_32(~a & (a - 1)); Executed by:
| 4476 | ||||||
144 | } | - | ||||||
145 | - | |||||||
146 | static inline unsigned int constant_time_eq(unsigned int a, | - | ||||||
147 | unsigned int b) | - | ||||||
148 | { | - | ||||||
149 | return executed 11313822 times by 3 tests: constant_time_is_zero(a ^ b);return constant_time_is_zero(a ^ b); Executed by:
executed 11313822 times by 3 tests: return constant_time_is_zero(a ^ b); Executed by:
| 11313822 | ||||||
150 | } | - | ||||||
151 | - | |||||||
152 | static inline size_t constant_time_eq_s(size_t a, size_t b) | - | ||||||
153 | { | - | ||||||
154 | return executed 39401 times by 2 tests: constant_time_is_zero_s(a ^ b);return constant_time_is_zero_s(a ^ b); Executed by:
executed 39401 times by 2 tests: return constant_time_is_zero_s(a ^ b); Executed by:
| 39401 | ||||||
155 | } | - | ||||||
156 | - | |||||||
157 | static inline unsigned char constant_time_eq_8(unsigned int a, | - | ||||||
158 | unsigned int b) | - | ||||||
159 | { | - | ||||||
160 | return executed 911 times by 2 tests: (unsigned char)constant_time_eq(a, b);return (unsigned char)constant_time_eq(a, b); Executed by:
executed 911 times by 2 tests: return (unsigned char)constant_time_eq(a, b); Executed by:
| 911 | ||||||
161 | } | - | ||||||
162 | - | |||||||
163 | static inline unsigned char constant_time_eq_8_s(size_t a, size_t b) | - | ||||||
164 | { | - | ||||||
165 | return executed 3094 times by 1 test: (unsigned char)constant_time_eq_s(a, b);return (unsigned char)constant_time_eq_s(a, b); Executed by:
executed 3094 times by 1 test: return (unsigned char)constant_time_eq_s(a, b); Executed by:
| 3094 | ||||||
166 | } | - | ||||||
167 | - | |||||||
168 | static inline unsigned int constant_time_eq_int(int a, int b) | - | ||||||
169 | { | - | ||||||
170 | return executed 11279076 times by 3 tests: constant_time_eq((unsigned)(a), (unsigned)(b));return constant_time_eq((unsigned)(a), (unsigned)(b)); Executed by:
executed 11279076 times by 3 tests: return constant_time_eq((unsigned)(a), (unsigned)(b)); Executed by:
| 11279076 | ||||||
171 | } | - | ||||||
172 | - | |||||||
173 | static inline unsigned char constant_time_eq_int_8(int a, int b) | - | ||||||
174 | { | - | ||||||
175 | return executed 459 times by 2 tests: constant_time_eq_8((unsigned)(a), (unsigned)(b));return constant_time_eq_8((unsigned)(a), (unsigned)(b)); Executed by:
executed 459 times by 2 tests: return constant_time_eq_8((unsigned)(a), (unsigned)(b)); Executed by:
| 459 | ||||||
176 | } | - | ||||||
177 | - | |||||||
178 | static inline unsigned int constant_time_select(unsigned int mask, | - | ||||||
179 | unsigned int a, | - | ||||||
180 | unsigned int b) | - | ||||||
181 | { | - | ||||||
182 | return executed 33910362 times by 4 tests: (mask & a) | (~mask & b);return (mask & a) | (~mask & b); Executed by:
executed 33910362 times by 4 tests: return (mask & a) | (~mask & b); Executed by:
| 33910362 | ||||||
183 | } | - | ||||||
184 | - | |||||||
185 | static inline size_t constant_time_select_s(size_t mask, | - | ||||||
186 | size_t a, | - | ||||||
187 | size_t b) | - | ||||||
188 | { | - | ||||||
189 | return executed 200 times by 1 test: (mask & a) | (~mask & b);return (mask & a) | (~mask & b); Executed by:
executed 200 times by 1 test: return (mask & a) | (~mask & b); Executed by:
| 200 | ||||||
190 | } | - | ||||||
191 | - | |||||||
192 | static inline unsigned char constant_time_select_8(unsigned char mask, | - | ||||||
193 | unsigned char a, | - | ||||||
194 | unsigned char b) | - | ||||||
195 | { | - | ||||||
196 | return executed 33856626 times by 4 tests: (unsigned char)constant_time_select(mask, a, b);return (unsigned char)constant_time_select(mask, a, b); Executed by:
executed 33856626 times by 4 tests: return (unsigned char)constant_time_select(mask, a, b); Executed by:
| 33856626 | ||||||
197 | } | - | ||||||
198 | - | |||||||
199 | static inline int constant_time_select_int(unsigned int mask, int a, | - | ||||||
200 | int b) | - | ||||||
201 | { | - | ||||||
202 | return executed 48373 times by 3 tests: (int)constant_time_select(mask, (unsigned)(a), (unsigned)(b));return (int)constant_time_select(mask, (unsigned)(a), (unsigned)(b)); Executed by:
executed 48373 times by 3 tests: return (int)constant_time_select(mask, (unsigned)(a), (unsigned)(b)); Executed by:
| 48373 | ||||||
203 | } | - | ||||||
204 | - | |||||||
205 | static inline int constant_time_select_int_s(size_t mask, int a, int b) | - | ||||||
206 | { | - | ||||||
207 | return executed 5163 times by 1 test: (int)constant_time_select((unsigned)mask, (unsigned)(a),return (int)constant_time_select((unsigned)mask, (unsigned)(a), (unsigned)(b)); Executed by:
executed 5163 times by 1 test: return (int)constant_time_select((unsigned)mask, (unsigned)(a), (unsigned)(b)); Executed by:
| 5163 | ||||||
208 | (unsigned)(b)); executed 5163 times by 1 test: return (int)constant_time_select((unsigned)mask, (unsigned)(a), (unsigned)(b)); Executed by:
| 5163 | ||||||
209 | } | - | ||||||
210 | - | |||||||
211 | static inline uint32_t constant_time_select_32(uint32_t mask, uint32_t a, | - | ||||||
212 | uint32_t b) | - | ||||||
213 | { | - | ||||||
214 | return executed 176130 times by 3 tests: (mask & a) | (~mask & b);return (mask & a) | (~mask & b); Executed by:
executed 176130 times by 3 tests: return (mask & a) | (~mask & b); Executed by:
| 176130 | ||||||
215 | } | - | ||||||
216 | - | |||||||
217 | static inline uint64_t constant_time_select_64(uint64_t mask, uint64_t a, | - | ||||||
218 | uint64_t b) | - | ||||||
219 | { | - | ||||||
220 | return executed 110 times by 1 test: (mask & a) | (~mask & b);return (mask & a) | (~mask & b); Executed by:
executed 110 times by 1 test: return (mask & a) | (~mask & b); Executed by:
| 110 | ||||||
221 | } | - | ||||||
222 | static inline void constant_time_cond_swap_32(uint32_t mask, uint32_t *a, | - | ||||||
223 | uint32_t *b) | - | ||||||
224 | { | - | ||||||
225 | uint32_t xor = *a ^ *b; | - | ||||||
226 | - | |||||||
227 | xor &= mask; | - | ||||||
228 | *a ^= xor; | - | ||||||
229 | *b ^= xor; | - | ||||||
230 | } executed 14744832 times by 2 tests: end of block Executed by:
| 14744832 | ||||||
231 | static inline void constant_time_cond_swap_64(uint64_t mask, uint64_t *a, | - | ||||||
232 | uint64_t *b) | - | ||||||
233 | { | - | ||||||
234 | uint64_t xor = *a ^ *b; | - | ||||||
235 | - | |||||||
236 | xor &= mask; | - | ||||||
237 | *a ^= xor; | - | ||||||
238 | *b ^= xor; | - | ||||||
239 | } never executed: end of block | 0 | ||||||
240 | - | |||||||
241 | - | |||||||
242 | - | |||||||
243 | - | |||||||
244 | - | |||||||
245 | - | |||||||
246 | static inline void constant_time_lookup(void *out, | - | ||||||
247 | const void *table, | - | ||||||
248 | size_t rowsize, | - | ||||||
249 | size_t numrows, | - | ||||||
250 | size_t idx) | - | ||||||
251 | { | - | ||||||
252 | size_t i, j; | - | ||||||
253 | const unsigned char *tablec = (const unsigned char *)table; | - | ||||||
254 | unsigned char *outc = (unsigned char *)out; | - | ||||||
255 | unsigned char mask; | - | ||||||
256 | - | |||||||
257 | memset(out, 0, rowsize); | - | ||||||
258 | - | |||||||
259 | - | |||||||
260 | for (i = 0; i < numrows
| 10980-175680 | ||||||
261 | mask = (unsigned char)constant_time_is_zero_s(idx); | - | ||||||
262 | for (j = 0; j < rowsize
| 175680-33730560 | ||||||
263 | *( executed 33730560 times by 2 tests: outc + j) |= constant_time_select_8(mask, *(tablec++), 0);*(outc + j) |= constant_time_select_8(mask, *(tablec++), 0); Executed by:
executed 33730560 times by 2 tests: *(outc + j) |= constant_time_select_8(mask, *(tablec++), 0); Executed by:
| 33730560 | ||||||
264 | } executed 175680 times by 2 tests: end of block Executed by:
| 175680 | ||||||
265 | } executed 10980 times by 2 tests: end of block Executed by:
| 10980 | ||||||
Switch to Source code | Preprocessed file |