OpenCoverage

constant_time_locl.h

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/include/internal/constant_time_locl.h
Switch to Source codePreprocessed file
LineSourceCount
1-
2static inline unsigned int constant_time_msb(unsigned int a);-
3-
4static inline uint32_t constant_time_msb_32(uint32_t a);-
5-
6static inline uint64_t constant_time_msb_64(uint64_t a);-
7-
8-
9static inline unsigned int constant_time_lt(unsigned int a,-
10 unsigned int b);-
11-
12static inline unsigned char constant_time_lt_8(unsigned int a,-
13 unsigned int b);-
14-
15static inline uint64_t constant_time_lt_64(uint64_t a, uint64_t b);-
16-
17-
18static inline unsigned int constant_time_ge(unsigned int a,-
19 unsigned int b);-
20-
21static inline unsigned char constant_time_ge_8(unsigned int a,-
22 unsigned int b);-
23-
24-
25static inline unsigned int constant_time_is_zero(unsigned int a);-
26-
27static inline unsigned char constant_time_is_zero_8(unsigned int a);-
28-
29static inline uint32_t constant_time_is_zero_32(uint32_t a);-
30-
31-
32static inline unsigned int constant_time_eq(unsigned int a,-
33 unsigned int b);-
34-
35static inline unsigned char constant_time_eq_8(unsigned int a,-
36 unsigned int b);-
37-
38static inline unsigned int constant_time_eq_int(int a, int b);-
39-
40static inline unsigned char constant_time_eq_int_8(int a, int b);-
41static inline unsigned int constant_time_select(unsigned int mask,-
42 unsigned int a,-
43 unsigned int b);-
44-
45static inline unsigned char constant_time_select_8(unsigned char mask,-
46 unsigned char a,-
47 unsigned char b);-
48-
49-
50static inline uint32_t constant_time_select_32(uint32_t mask, uint32_t a,-
51 uint32_t b);-
52-
53-
54static inline uint64_t constant_time_select_64(uint64_t mask, uint64_t a,-
55 uint64_t b);-
56-
57static inline int constant_time_select_int(unsigned int mask, int a,-
58 int b);-
59-
60-
61static inline unsigned int constant_time_msb(unsigned int a)-
62{-
63 return
executed 11388508 times by 3 tests: return 0 - (a >> (sizeof(a) * 8 - 1));
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
  • libssl.so.1.1
0 - (a >> (sizeof(a) * 8 - 1));
executed 11388508 times by 3 tests: return 0 - (a >> (sizeof(a) * 8 - 1));
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
  • libssl.so.1.1
11388508
64}-
65-
66-
67static inline uint32_t constant_time_msb_32(uint32_t a)-
68{-
69 return
executed 4476 times by 3 tests: return 0 - (a >> 31);
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
0 - (a >> 31);
executed 4476 times by 3 tests: return 0 - (a >> 31);
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
4476
70}-
71-
72static inline uint64_t constant_time_msb_64(uint64_t a)-
73{-
74 return
executed 55 times by 1 test: return 0 - (a >> 63);
Executed by:
  • constant_time_test
0 - (a >> 63);
executed 55 times by 1 test: return 0 - (a >> 63);
Executed by:
  • constant_time_test
55
75}-
76-
77static inline size_t constant_time_msb_s(size_t a)-
78{-
79 return
executed 1280374 times by 4 tests: return 0 - (a >> (sizeof(a) * 8 - 1));
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • libssl.so.1.1
0 - (a >> (sizeof(a) * 8 - 1));
executed 1280374 times by 4 tests: return 0 - (a >> (sizeof(a) * 8 - 1));
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • libssl.so.1.1
1280374
80}-
81-
82static inline unsigned int constant_time_lt(unsigned int a,-
83 unsigned int b)-
84{-
85 return
executed 786 times by 2 tests: return constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b)));
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b)));
executed 786 times by 2 tests: return constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b)));
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
786
86}-
87-
88static inline size_t constant_time_lt_s(size_t a, size_t b)-
89{-
90 return
executed 1065283 times by 2 tests: return constant_time_msb_s(a ^ ((a ^ b) | ((a - b) ^ b)));
Executed by:
  • constant_time_test
  • libssl.so.1.1
constant_time_msb_s(a ^ ((a ^ b) | ((a - b) ^ b)));
executed 1065283 times by 2 tests: return constant_time_msb_s(a ^ ((a ^ b) | ((a - b) ^ b)));
Executed by:
  • constant_time_test
  • libssl.so.1.1
1065283
91}-
92-
93static inline unsigned char constant_time_lt_8(unsigned int a,-
94 unsigned int b)-
95{-
96 return
executed 162 times by 1 test: return (unsigned char)constant_time_lt(a, b);
Executed by:
  • constant_time_test
(unsigned char)constant_time_lt(a, b);
executed 162 times by 1 test: return (unsigned char)constant_time_lt(a, b);
Executed by:
  • constant_time_test
162
97}-
98-
99static inline uint64_t constant_time_lt_64(uint64_t a, uint64_t b)-
100{-
101 return
executed 55 times by 1 test: return constant_time_msb_64(a ^ ((a ^ b) | ((a - b) ^ b)));
Executed by:
  • constant_time_test
constant_time_msb_64(a ^ ((a ^ b) | ((a - b) ^ b)));
executed 55 times by 1 test: return constant_time_msb_64(a ^ ((a ^ b) | ((a - b) ^ b)));
Executed by:
  • constant_time_test
55
102}-
103-
104static inline unsigned int constant_time_ge(unsigned int a,-
105 unsigned int b)-
106{-
107 return
executed 424 times by 2 tests: return ~constant_time_lt(a, b);
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
~constant_time_lt(a, b);
executed 424 times by 2 tests: return ~constant_time_lt(a, b);
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
424
108}-
109-
110static inline size_t constant_time_ge_s(size_t a, size_t b)-
111{-
112 return
executed 997931 times by 2 tests: return ~constant_time_lt_s(a, b);
Executed by:
  • constant_time_test
  • libssl.so.1.1
~constant_time_lt_s(a, b);
executed 997931 times by 2 tests: return ~constant_time_lt_s(a, b);
Executed by:
  • constant_time_test
  • libssl.so.1.1
997931
113}-
114-
115static inline unsigned char constant_time_ge_8(unsigned int a,-
116 unsigned int b)-
117{-
118 return
executed 162 times by 1 test: return (unsigned char)constant_time_ge(a, b);
Executed by:
  • constant_time_test
(unsigned char)constant_time_ge(a, b);
executed 162 times by 1 test: return (unsigned char)constant_time_ge(a, b);
Executed by:
  • constant_time_test
162
119}-
120-
121static inline unsigned char constant_time_ge_8_s(size_t a, size_t b)-
122{-
123 return
executed 992568 times by 1 test: return (unsigned char)constant_time_ge_s(a, b);
Executed by:
  • libssl.so.1.1
(unsigned char)constant_time_ge_s(a, b);
executed 992568 times by 1 test: return (unsigned char)constant_time_ge_s(a, b);
Executed by:
  • libssl.so.1.1
992568
124}-
125-
126static inline unsigned int constant_time_is_zero(unsigned int a)-
127{-
128 return
executed 11387722 times by 3 tests: return constant_time_msb(~a & (a - 1));
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
  • libssl.so.1.1
constant_time_msb(~a & (a - 1));
executed 11387722 times by 3 tests: return constant_time_msb(~a & (a - 1));
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
  • libssl.so.1.1
11387722
129}-
130-
131static inline size_t constant_time_is_zero_s(size_t a)-
132{-
133 return
executed 215091 times by 4 tests: return constant_time_msb_s(~a & (a - 1));
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • libssl.so.1.1
constant_time_msb_s(~a & (a - 1));
executed 215091 times by 4 tests: return constant_time_msb_s(~a & (a - 1));
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • libssl.so.1.1
215091
134}-
135-
136static inline unsigned char constant_time_is_zero_8(unsigned int a)-
137{-
138 return
executed 29879 times by 2 tests: return (unsigned char)constant_time_is_zero(a);
Executed by:
  • constant_time_test
  • libssl.so.1.1
(unsigned char)constant_time_is_zero(a);
executed 29879 times by 2 tests: return (unsigned char)constant_time_is_zero(a);
Executed by:
  • constant_time_test
  • libssl.so.1.1
29879
139}-
140-
141static inline uint32_t constant_time_is_zero_32(uint32_t a)-
142{-
143 return
executed 4476 times by 3 tests: return constant_time_msb_32(~a & (a - 1));
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
constant_time_msb_32(~a & (a - 1));
executed 4476 times by 3 tests: return constant_time_msb_32(~a & (a - 1));
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
4476
144}-
145-
146static inline unsigned int constant_time_eq(unsigned int a,-
147 unsigned int b)-
148{-
149 return
executed 11313822 times by 3 tests: return constant_time_is_zero(a ^ b);
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
  • libssl.so.1.1
constant_time_is_zero(a ^ b);
executed 11313822 times by 3 tests: return constant_time_is_zero(a ^ b);
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
  • libssl.so.1.1
11313822
150}-
151-
152static inline size_t constant_time_eq_s(size_t a, size_t b)-
153{-
154 return
executed 39401 times by 2 tests: return constant_time_is_zero_s(a ^ b);
Executed by:
  • constant_time_test
  • libssl.so.1.1
constant_time_is_zero_s(a ^ b);
executed 39401 times by 2 tests: return constant_time_is_zero_s(a ^ b);
Executed by:
  • constant_time_test
  • libssl.so.1.1
39401
155}-
156-
157static inline unsigned char constant_time_eq_8(unsigned int a,-
158 unsigned int b)-
159{-
160 return
executed 911 times by 2 tests: return (unsigned char)constant_time_eq(a, b);
Executed by:
  • constant_time_test
  • libssl.so.1.1
(unsigned char)constant_time_eq(a, b);
executed 911 times by 2 tests: return (unsigned char)constant_time_eq(a, b);
Executed by:
  • constant_time_test
  • libssl.so.1.1
911
161}-
162-
163static inline unsigned char constant_time_eq_8_s(size_t a, size_t b)-
164{-
165 return
executed 3094 times by 1 test: return (unsigned char)constant_time_eq_s(a, b);
Executed by:
  • libssl.so.1.1
(unsigned char)constant_time_eq_s(a, b);
executed 3094 times by 1 test: return (unsigned char)constant_time_eq_s(a, b);
Executed by:
  • libssl.so.1.1
3094
166}-
167-
168static inline unsigned int constant_time_eq_int(int a, int b)-
169{-
170 return
executed 11279076 times by 3 tests: return constant_time_eq((unsigned)(a), (unsigned)(b));
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
  • libssl.so.1.1
constant_time_eq((unsigned)(a), (unsigned)(b));
executed 11279076 times by 3 tests: return constant_time_eq((unsigned)(a), (unsigned)(b));
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
  • libssl.so.1.1
11279076
171}-
172-
173static inline unsigned char constant_time_eq_int_8(int a, int b)-
174{-
175 return
executed 459 times by 2 tests: return constant_time_eq_8((unsigned)(a), (unsigned)(b));
Executed by:
  • constant_time_test
  • libssl.so.1.1
constant_time_eq_8((unsigned)(a), (unsigned)(b));
executed 459 times by 2 tests: return constant_time_eq_8((unsigned)(a), (unsigned)(b));
Executed by:
  • constant_time_test
  • libssl.so.1.1
459
176}-
177-
178static 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: return (mask & a) | (~mask & b);
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • libssl.so.1.1
(mask & a) | (~mask & b);
executed 33910362 times by 4 tests: return (mask & a) | (~mask & b);
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • libssl.so.1.1
33910362
183}-
184-
185static 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: return (mask & a) | (~mask & b);
Executed by:
  • constant_time_test
(mask & a) | (~mask & b);
executed 200 times by 1 test: return (mask & a) | (~mask & b);
Executed by:
  • constant_time_test
200
190}-
191-
192static 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: return (unsigned char)constant_time_select(mask, a, b);
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • libssl.so.1.1
(unsigned char)constant_time_select(mask, a, b);
executed 33856626 times by 4 tests: return (unsigned char)constant_time_select(mask, a, b);
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • libssl.so.1.1
33856626
197}-
198-
199static inline int constant_time_select_int(unsigned int mask, int a,-
200 int b)-
201{-
202 return
executed 48373 times by 3 tests: return (int)constant_time_select(mask, (unsigned)(a), (unsigned)(b));
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
  • libssl.so.1.1
(int)constant_time_select(mask, (unsigned)(a), (unsigned)(b));
executed 48373 times by 3 tests: return (int)constant_time_select(mask, (unsigned)(a), (unsigned)(b));
Executed by:
  • constant_time_test
  • libcrypto.so.1.1
  • libssl.so.1.1
48373
203}-
204-
205static inline int constant_time_select_int_s(size_t mask, int a, int b)-
206{-
207 return
executed 5163 times by 1 test: return (int)constant_time_select((unsigned)mask, (unsigned)(a), (unsigned)(b));
Executed by:
  • libssl.so.1.1
(int)constant_time_select((unsigned)mask, (unsigned)(a),
executed 5163 times by 1 test: return (int)constant_time_select((unsigned)mask, (unsigned)(a), (unsigned)(b));
Executed by:
  • libssl.so.1.1
5163
208 (unsigned)(b));
executed 5163 times by 1 test: return (int)constant_time_select((unsigned)mask, (unsigned)(a), (unsigned)(b));
Executed by:
  • libssl.so.1.1
5163
209}-
210-
211static 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: return (mask & a) | (~mask & b);
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
(mask & a) | (~mask & b);
executed 176130 times by 3 tests: return (mask & a) | (~mask & b);
Executed by:
  • constant_time_test
  • curve448_internal_test
  • libcrypto.so.1.1
176130
215}-
216-
217static 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: return (mask & a) | (~mask & b);
Executed by:
  • constant_time_test
(mask & a) | (~mask & b);
executed 110 times by 1 test: return (mask & a) | (~mask & b);
Executed by:
  • constant_time_test
110
221}-
222static 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:
  • curve448_internal_test
  • libcrypto.so.1.1
14744832
231static 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-
246static 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
i < numrowsDescription
TRUEevaluated 175680 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
FALSEevaluated 10980 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
; i++, idx--) {
10980-175680
261 mask = (unsigned char)constant_time_is_zero_s(idx);-
262 for (j = 0; j < rowsize
j < rowsizeDescription
TRUEevaluated 33730560 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
FALSEevaluated 175680 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
; j++)
175680-33730560
263 *(
executed 33730560 times by 2 tests: *(outc + j) |= constant_time_select_8(mask, *(tablec++), 0);
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
outc + j) |= constant_time_select_8(mask, *(tablec++), 0);
executed 33730560 times by 2 tests: *(outc + j) |= constant_time_select_8(mask, *(tablec++), 0);
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
33730560
264 }
executed 175680 times by 2 tests: end of block
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
175680
265}
executed 10980 times by 2 tests: end of block
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
10980
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2